A shortcut for submit twice?

Discussion in 'Programming' started by Hercf, Aug 4, 2008.

  1. #1
    Hi guys!
    I need your help!
    The next script is a normal “insert page” which get back the “GENERATED_KEY”: “myid” and put it hidden form:”myid”.
    If the value of “myid” is numeric then the action attribute of “form1” get a page address as value.
    The issue is, it shows 2 times the insert page. You have to push 2 times the “submit” button to receive the desired page.
    Is it a way to shortcut these repetitive submit?

    <cfparam name="email" default="">
    <cfparam name="lname" default="">
    <cfparam name="fname" default="">
    <cfparam name="myAdress" default="">
    <cfparam name="myid" default="">

    <cfif isNumeric("#myid#")>
    <cfset myAdress ="workform.cfm">

    <cfelse>
    <cfif isDefined("form.email")>
    <cfquery datasource="myData" result="myid">
    INSERT INTO myTable
    (email, lname, fname)
    VALUES
    ('#form.email#', '#form.lnume#', '#form.fname#')
    </cfquery>
    <cfset #form.myid#="#myid.GENERATED_KEY#">
    <cfdump label="Result Structrure" var="#form#"/>
    </cfif>
    </cfif>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
    <title>Register</title>
    </head>


    <body>
    <cfform name="form1" id="form1" method="post" preservedata="yes" action="#myAdress#">


    </p>
    <p>
    <label for="email">Email:</label>
    <cfinput type="text" name="email" id="email">
    </p>
    <p>
    <label for="lname">Last name:</label>
    <cfinput type="text" name="lname" id="lname">
    </p>
    <p>
    <label for="fname">First name</label>
    <cfinput type="text" name="fname" id="fname">
    </p>
    <p>
    <cfinput type="hidden" name="myid">
    <cfinput type="submit" name="submit" id="submit" value="OK!">
    </p>
    </cfform>
    <p>&nbsp;</p>

    </body>
    </html>
     
    Hercf, Aug 4, 2008 IP
  2. phydiux

    phydiux Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Who wrote this? It looks like a homework assignment.

    You need to scope these variables, which is part of the issue you're having.

    You should set the generated key when the page first loads if it's not defined/numeric so you don't have to reload the page in order to get to the next page. You're passing around blank hidden form fields for no reason, which is why you have to submit the page multiple times.

    Also, myid.GENERATED_KEY is never defined here, so it's going to throw an error unless it's defined elsewhere.

    I assume you're trying to do this to prevent automated form submissions?
     
    phydiux, Aug 4, 2008 IP
  3. Hercf

    Hercf Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your opinions!
    I tried what you sad, the same result: double submit to get the new page. But using “cflocation” instead trying to change “action”, is OK!
    Maybe I did some mistake, would you please be more specific?
    Thank you!
     
    Hercf, Aug 10, 2008 IP