9 Replies Latest reply on May 9, 2007 9:45 AM by Newsgroup_User

    Passing form variables

    semi star gazer Level 1
      HI~

      I have a cfform on my index.cfm page, and the action is set to go to a confirm.cfm page. On that page, I want the user to be able to look at the information they entered into the form, and then hit "Submit" if it is correct. Right now, I am able to display the form information on the confirm.cfm page, but I'm having a hard time with my insert statement. Right now, when I hit the final Submit button, an entry is made in the database, but none of the variables are passed. I'm guessing this is because of the cfparam default="" setting, but I don't know what else to set it as-- if I try to set it as semester or form.semester, it says it is not defined. Please help! Thanks!
        • 1. Passing form variables
          amers Level 1
          On the second form, you should add a hidden form field to pass the previous Form variable along.

          <cfinput type="hidden" name="semester" value="Form.semester">

          So, when you submit the second Form - it will have the value from the first Form. Otherwise, the variable Form.semester does not exist.
          • 2. Re: Passing form variables
            LL@Work Level 1
            Exactly.
            It makes it clear if you simply display the form data for review:
            <cfoutput>
            #form.semester#
            </cfoutput>
            <cfinput type="hidden" name="semester" value="Form.semester">
            Then direct the user back to edit or forward to confirm
            • 3. Re: Passing form variables
              semi star gazer Level 1
              OK... so, do I just need the hidden field, or do I still need the <cfparam> tag?
              • 4. Re: Passing form variables
                Level 7
                semi star gazer wrote:
                > OK... so, do I just need the hidden field, or do I still need the <cfparam> tag?

                you must have a form field (hidden or not) that stores selected/entered
                semester from the first form (index page) in your second form (confirm
                page), otherwise when that (second) form (is submitted, it does not hold
                any reference to the semester inside its scope...

                --
                Azadi Saryev
                Sabai-dee.com
                Vientiane, Laos
                http://www.sabai-dee.com
                • 5. Re: Passing form variables
                  semi star gazer Level 1
                  OK, I think I'm still missing something here. This is what I have right now. With this code, I get a blank entry in the database when the user hits the Submit button.
                  • 6. Re: Passing form variables
                    Level 7
                    semi star gazer wrote:
                    > OK, I think I'm still missing something here. This is what I have right now.
                    > With this code, I get a blank entry in the database when the user hits the
                    > Submit button.
                    >
                    > <cfparam name="form.semester" default="">
                    >
                    > <cfif isDefined("form.submitEval")>
                    >
                    > <!--- insert form data into database --->
                    > <cfquery name="insertEval" datasource="intern">
                    > INSERT INTO mentorEvals (
                    > semester
                    > ) VALUES (
                    > '#Trim(form.semester)#'
                    > )
                    > </cfquery>
                    >
                    > <cfform action="#CGI.SCRIPT_NAME#" name="submitEval" METHOD="post">
                    > <cfinput type="hidden" name="semester" value="form.semester">
                    > <!--- Submit Button that reads "Submit Evaluation" --->
                    > <cfinput type="submit" value="Submit Evaluation" name="submitEval"
                    > id="submitEval">
                    > </cfform>
                    >

                    try using <input type="hidden" ...> instead of <cfinput ...> - i seem to
                    recall there being issues with hidden cfinput fields...

                    also - where's your closing </cfif>??? it should be after </cfquery> - i
                    hope it is actually there...

                    just to make sure semester is passed from first form, you can put
                    <cfoutput>#form.semester#</cfoutput> right after your <cfparam>

                    NOTE: you do not really need that <cfparam> there... it does not do
                    anything... unless you are planning to use it later for validation
                    routines... i wonder if it may be tampering with the semester value...
                    it shouldn't, but who knows...

                    --
                    Azadi Saryev
                    Sabai-dee.com
                    Vientiane, Laos
                    http://www.sabai-dee.com
                    • 7. Re: Passing form variables
                      paross1 Level 2
                      You need to make sure that the form.semester variable is treated as a variable... use #'s and <cfoutput> tags....

                      <cfform action="#CGI.SCRIPT_NAME#" name="submitEval" METHOD="post">
                      <!--- Submit Button that reads "Submit Evaluation" --->
                      <cfinput type="submit" value="Submit Evaluation" name="submitEval" id="submitEval">
                      <cfoutput>
                      <cfinput type="hidden" name="semester" value="#form.semester#">
                      </cfoutput>
                      </cfform>

                      Phil
                      • 8. Re: Passing form variables
                        Level 7

                        right on! just no need for <cfoutput> tags around it, #'s are enough...
                        how did i miss that??? should go to bed now...

                        anyway, that still does not explain why his form.semester is an empty
                        string, since, without the #'s, the value of the hidden field will be
                        literal 'form.semester', and that is what should be inserted into the
                        db, not an empty string.....

                        --
                        Azadi Saryev
                        Sabai-dee.com
                        Vientiane, Laos
                        http://www.sabai-dee.com
                        • 9. Re: Passing form variables
                          semi star gazer Level 1
                          Thanks everyone!