10 Replies Latest reply: Nov 28, 2011 7:08 AM by Michael G. Workman RSS

    Multi-page Form (from another forum)

    EwokStud

      I may have been in the wrong forum, so I copied my issue here.  No arrogance intended.  Please forgive me for not knowing which forum to use.

       

      I have a multi-page form, which is basic.  The form's first page is to post a new person's fist and last name.  The second page is for the person's current address.  Of course, there's more objects/database fields than this, but I need page 1 to go to page 2 smoothly, and without much pause.  Page 2 is the exact same person as page 1.  The ID for the person is created on page 1, somehow.

       

      How do I get the 2nd page form to know it's the same person on page 1?  Do I use call_number =form.ID or ID=ID or what?  Does the form on each page have be the same name?  Does the ACTION have to be the name of the next page in the form (page2), or the name of the page which submits the data?

       

       

      PAGE 1 "The Name"

      <CFQUERY DATASOURCE="people" NAME="nw">

           SELECT *

           FROM people_table;

      </CFQUERY>

      <HTML>

      <HEAD>

      <TITLE>Add an Entry.</TITLE>

      </HEAD>

      <BODY>

      <TABLE>

           <TR>

                <TD>

      <FORM

           ACTION="p_in.cfm"

           METHOD="post"

           NAME="formNewPersonPage1">

      <INPUT

           TYPE="hidden"

           NAME="peopleID">

      <INPUT

           TYPE="hidden"

           NAME="entry_date_time"

           VALUE="now()">

      Your First Name:

      <INPUT

           TYPE="text"

           NAME="people_nm_f"

           SIZE="30"

           id="First name">

      <P>

      Your Last Name:

      <INPUT

           TYPE="text"

           NAME="gb_entry_nm_l"

           SIZE="30"

           id="Last name">

      <BR>

      <P>

      Checkbox if Male:

      <INPUT

           TYPE="checkbox"

         NAME="people_nm_male_x">

                </TD>

           </TR>

      </TABLE>

      </FORM>

      </BODY>

      </HTML>

      ____________________________________________________

      PAGE 2 "The Current Address"

      <CFQUERY DATASOURCE="people" NAME="nw">
            SELECT *
            FROM people_table
            WHERE formNewPersonPage1.peopleID=ID;
      </CFQUERY>
      <HTML>
      <HEAD>
      <TITLE>Add an Entry Page 2</TITLE>
      </HEAD>
      <BODY>
      <TABLE>
            <TR>
                 <TD>
                     <FORM
                          ACTION="p_in.cfm"
                          METHOD="post"
                          NAME="formNewPersonPage2">
      Your Street #:
           <INPUT
                TYPE="text"
                NAME="peopleStreetNbr"
                SIZE="30">

      Your City:
           <INPUT
                TYPE="text"
                NAME="peopleCity"
                SIZE="30">
        <BR>
      Your State:
      <P>
           <INPUT
                TYPE="text"
                NAME="peopleState"
                SIZE="30">
      <P>
                </TD>
           </TR>
      </TABLE>
      </FORM>
      </BODY>
      </HTML>

        • 1. Re: Multi-page Form (from another forum)
          Dan Bracuk Community Member

          You already have a hidden form field for the information.  Give it a value.

          • 2. Re: Multi-page Form (from another forum)
            EwokStud Community Member

            Do you mean, in the 1st page or 2nd page?  Does the form name on each page need to be exactly the same?  Do I need a hidden ID field and value on the 2nd and 3rd pages?

             

            <FORM

                 ACTION="p_in.cfm"

                 METHOD="post"

                 NAME="formNewPersonPage1">

            <INPUT

                 TYPE="hidden"

                 NAME="peopleID"

                 VALUE=#peopleID#>

            <INPUT

                 TYPE="hidden"

                 NAME="entry_date_time"

                 VALUE="now()">

            • 3. Re: Multi-page Form (from another forum)
              Dan Bracuk Community Member

              The form names don't have to be the same.  In fact, the form doesn't even have to have a name.

               

              You need a form field and value for everything you want to submit.  The type of form field and the value depends on your specific requirements.  If you want to quickly see what is being passed, put this at the top of the page to which the form is submitted.

               

              <cfdump var="#form#">

              • 4. Re: Multi-page Form (from another forum)
                BKBK CommunityMVP

                The first page, let's call it id.cfm, enables the user to enter his name. You say the user is new, so there's no point in doing select queries at this point. A useful generator of IDs is createUUID().

                 

                From your description, the action of the first form should be the address page. Let's then call it address.cfm. There you begin by saving the information supplied. It is also good practice to confirm the details the user entered.

                 

                However, this is an oversimplified picture to get you started. It is advisable to always validate user input before saving it in the database.

                 

                id.cfm

                 

                <HTML>

                <HEAD>

                <TITLE>Add an Entry.</TITLE>

                </HEAD>

                <BODY>

                <TABLE>

                     <TR>

                          <TD>

                <FORM

                     ACTION="address.cfm"

                     METHOD="post"

                     NAME="formNewPersonPage1">

                <cfoutput>

                <INPUT

                     TYPE="hidden"

                     NAME="peopleID">

                     VALUE="#createUUID()#"

                </cfoutput>

                Your First Name:

                <INPUT

                     TYPE="text"

                     NAME="people_nm_f"

                     SIZE="30"

                     id="First_name">

                <P>

                Your Last Name:

                <INPUT

                     TYPE="text"

                     NAME="gb_entry_nm_l"

                     SIZE="30"

                     id="Last_name">

                <BR>

                <P>

                Checkbox if Male:

                <INPUT

                     TYPE="checkbox"

                   NAME="people_nm_male_x">

                <P><P>

                <INPUT

                   TYPE="submit"

                   NAME="sbmt"

                   VALUE="Add your address">

                          </TD>

                     </TR>

                </TABLE>

                </FORM>

                </BODY>

                </HTML>

                 

                 

                address.cfm

                 

                <CFQUERY DATASOURCE="people" NAME="nw">

                      INSERT INTO people_table (firstName, lastName, id, entry_date_time)

                      VALUES(<cfqueryparam 

                                value="#form.people_nm_f#" 

                                cfsqltype="CF_SQL_VARCHAR">,

                             <cfqueryparam 

                                value="#form.people_nm_l#" 

                                cfsqltype="CF_SQL_VARCHAR">,

                         <cfqueryparam 

                                value="#form.peopleID#" 

                                cfsqltype="CF_SQL_VARCHAR">,

                             <cfqueryparam 

                                value="#now()#" 

                                cfsqltype="CF_SQL_timestamp">)

                </CFQUERY>

                <HTML>

                <HEAD>

                <TITLE>Add an Entry Page 2</TITLE>

                </HEAD>

                <BODY>

                <TABLE>

                      <TR>

                           <TD>

                               <FORM

                                    ACTION="p_in.cfm"

                                    METHOD="post"

                                    NAME="formNewPersonPage2">

                Your first name:

                <cfoutput>

                     <INPUT

                          TYPE="text"

                          NAME="first_name"

                          VALUE="#form.people_nm_f#">

                <p>

                Your last name:

                     <INPUT

                          TYPE="text"

                          NAME="last_name"

                          VALUE="#form.people_nm_l#">

                </cfoutput>

                  <p>

                Your Street #:

                     <INPUT

                          TYPE="text"

                          NAME="peopleStreetNbr"

                          SIZE="30">

                 

                Your City:

                     <INPUT

                          TYPE="text"

                          NAME="peopleCity"

                          SIZE="30">

                  <BR>

                Your State:

                <P>

                     <INPUT

                          TYPE="text"

                          NAME="peopleState"

                          SIZE="30">

                <P>

                          </TD>

                     </TR>

                </TABLE>

                </FORM>

                </BODY>

                </HTML>

                • 5. Re: Multi-page Form (from another forum)
                  EwokStud Community Member

                  BKBK,

                   

                  Thank you for your response.  I've yet to try your suggestion; my computer was at the shop, and then it was the flu....

                   

                  The people's names etc. which will be added, are not users' names.  They are family names, addresses, phones, education, career, etc.  This is a geneaology program online.  The user are those who enter the family information (a couple folks).

                   

                  Nonetheless, I will try your suggestions - with enthusiasm - in a day or two.  I just wanted you to know I have reviewed yoru response, and am anxious to try it.

                   

                  BTW, I was unsure if using SQL to INSERT, or CFINSERT would be better.  I see that you used a CFPARAM for each field.  I thought, that the WHERE clause and ORDER BY clause were the only areas to do that....  Please elboarate on this conspet for me a little!

                   

                  I also noticed that you used cfsqltype="CF_SQL_VARCHAR" for the peopleID field (which is actually a AutoNumber, Long Integer in MS Access)  Can you use cfsqltype="CF_SQL_VARCHAR" for a number, as well as text?

                   

                  Sincerely,

                  EwokStud

                  • 6. Re: Multi-page Form (from another forum)
                    Dan Bracuk Community Member

                    Use cfqueryparam for all variables, no matter where in the sql command they may be (unless there is some reason you can't).

                     

                    Use the paramater type that matches the datatype in your db.

                    • 7. Re: Multi-page Form (from another forum)
                      EwokStud Community Member

                      Dan,

                       

                      BKBK suggested to me, in his response (Nov 16, 2011 2:34 AM), a CfSqlType of CF_SQL_VARCHAR for my peopleID field (an Autonumber field in MS Access).  Would CF_SQL_VARBIGINT be better?  AND,...are decimals allowed with Big Integer?

                       

                      BTW, I forgot to mention that I'm using CFMX7, with MS Access 2003, just in case there's a need for you to know this in your "much appreciated" responses.

                       

                      Thank you, and looking forward to your response!

                      • 8. Re: Multi-page Form (from another forum)
                        -==cfSearching==- Community Member

                        BKBK suggested to me, in his response (Nov 16, 2011 2:34 AM), a CfSqlType of CF_SQL_VARCHAR

                         

                        for my peopleID field

                         

                         

                        Remember, the cfsqltype should match the data type of your column. He suggested using a uuid (not an autonumber) for the peopleID column. Since they are alphanumeric, they are typically stored in a "varchar" (or "text") column, making the correct cfsqltype cf_sql_varchar.

                         

                        an Autonumber field in MS Access

                         

                        Autonumber columns are numeric. So you should use one of the numeric cfsqltypes. Again, the exact one depends on your column, but the default for Autonumber is "Long Integer", making the correct type "cf_sql_integer".

                         

                        are decimals allowed with Big Integer?

                         

                        While you might not get an error, the decimals would almost certainly be truncated.  An "integer" is a whole number. If you require decimals, integer is the wrong type.

                        • 9. Re: Multi-page Form (from another forum)
                          BKBK CommunityMVP

                          EwokStud wrote:

                           

                          BKBK,

                           

                          Thank you for your response.  I've yet to try your suggestion; my computer was at the shop, and then it was the flu....

                           

                          The people's names etc. which will be added, are not users' names.  They are family names, addresses, phones, education, career, etc.  This is a geneaology program online.  The user are those who enter the family information (a couple folks).

                           

                          Nonetheless, I will try your suggestions - with enthusiasm - in a day or two.  I just wanted you to know I have reviewed yoru response, and am anxious to try it.

                          OK.

                           

                          BTW, I was unsure if using SQL to INSERT, or CFINSERT would be better.  I see that you used a CF[QUERY]PARAM for each field.  I thought, that the WHERE clause and ORDER BY clause were the only areas to do that....  Please elboarate on this conspet for me a little!

                           

                          Choose INSERT or CFINSERT, whichever one you like. Yes, you may use CFQUERYPARAM to insert data. In fact, it is advisable to always use it when you insert form data. It helps secure your code against malicious scripts that may come in through a form.

                           

                           

                          I also noticed that you used cfsqltype="CF_SQL_VARCHAR" for the peopleID field (which is actually a AutoNumber, Long Integer in MS Access)  Can you use cfsqltype="CF_SQL_VARCHAR" for a number, as well as text?

                           

                          -==cfSearching==- has explained this.

                          • 10. Re: Multi-page Form (from another forum)
                            Michael G. Workman Community Member

                            With the web application you are trying to create with ColdFusion. You can have your form action go to the next file, that will work, or you can use a self-posting form that cflocates to the next page in the process. I have included a sample self posting form code in this reply, self posting forms are useful in that you dont let the user go to the next page if there is a mistake in thier form data.

                             

                            <!--- first you want to have default values for your form parameters, important --->

                            <cfparam name="FORM.FirstName" default="">

                            <cfparam name="FORM.LastName" default="">

                            <cfparam name="FORM.Submit"      default="">

                             

                            <!--- a flag value to track if there is an error in the form data --->

                            <cfset ValidationError = false>

                             

                            <!--- process the form submital, do server side validation as well --->

                            <cfif FORM.Submit eq "Continue">

                              

                               <!--- server side validate the form elements --->

                                <cfif (FORM.FirstName neq "") and (FORM.LastName neq "")>

                                 

                                 <!--- insert new person into database --->

                                  <CFQUERY DATASOURCE="people" NAME="nw">

                                     INSERT INTO people_table (firstname, lastname)

                                     VALUES ( '#FORM.FirstName#','#FORM.LastName#')

                                 </CFQUERY>

                             

                                 <!--- go to the next page of the process --->

                                <cflocation url="p_in.cfm" addtoken="no">

                             

                                <cfelse>

                                   <cfset ValidationError = true>

                                </cfif>

                             

                            </cfif>

                             

                            <!--- alert user if there is an error --->

                            <cfif ValidationError>

                                There was an error with the form data in the form<br>

                            </cfif>

                             

                            <!--- form goes here, when you do not specifiy a form action, the form becomes self-posting --->

                            <cfoutput>

                            <form method="post">

                            First Name: <input type="text" name="FirstName" maxlength="50" value="#FORM.FirstName#"><br>

                            Last Name: <input type="text" name="LastName" maxlength="50" value="#FORM.LastName#"><br>

                            <input type="submit" name="Submit" value="Continue"> <!-- give submit button a name, so we can reference it in the CF FORM scope --->

                            </form>

                            </cfoutput>

                             

                            Michael G. Workman

                            mworkman@usbid.com

                            http://www.usbid.com

                            http://ic.locate-ic.com