• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Form Validaton, Select Menus Losing Session Info

I have a two page processing set up, form and action page with error checking for required fields.  All fields are stored in a session but I am having sort of two problems with select menus.

First off, if a user missed a required field on the form page when they submitted to the action/processing page, select menu values that were stored in the session did not update themselves. So if a user had chosen the state of California on the form page, on the action/processing page it was back to the default 'Choose A State'. This was the case for all select menus on the page. To altered the select menus on the action page as such;

<cfselect
          name="State"          
          required="yes"
          message="Please select your State">
              <OPTION value="#session.buynow_nfo.State#" selected><cfoutput>#session.buynow_nfo.State#</cfoutput></OPTION>
              <option value="Alabama">Alabama</option>
              <option value="Alaska">Alaska</option>
              <option value="Arizona">Arizona</option>
              <option value="Arkansas">Arkansas</option>
              <option value="California">California</option>
               etc....
</cfselect>

Which worked, or so I thought.  If the user makes an error in a text field or select menu, select menus that have been selected did update with the session info passed to the action page.  However, if a user makes TWO mistakes and therefore submits the form twice all select boxes lose the session info and display the #session.buynow_nfo.NAMEOFFIELD# fix, I thought I had created.

This is not seen as an error, so when and if all the required text fields are correct the form submits and the select values all come through with #session.buynow_nfo.NAMEOFFIELD#

How can I fix this?
0
dndco
Asked:
dndco
  • 2
  • 2
1 Solution
 
dgrafxCommented:
I believe you need to do something like:

<cfoutput>
<select name="State">
<cfloop list="#statelist#" index="ii">
<option value="#ii#" <cfif ii is session.buynow_nfo.State>selected</cfif>>#ii#
</cfloop>
</select>
</cfoutput>
0
 
dndcoAuthor Commented:
Thanks anyway, but it looks like you are pulling the #statelist# from a DB and looping through to the next item with "ii".  I don't have a database for this.   I just have the 50 states coded in the form.  

However, your code did give me an idea.  I wrapped the selected option value with cfoutput like this;

<cfselect
          name="State"          
          required="yes"
          message="Please select your State">
              <cfoutput>
              <OPTION value="#session.buynow_nfo.State#" selected>#session.buynow_nfo.State#</OPTION>
             </cfoutput>
              <option value="Alabama">Alabama</option>
              <option value="Alaska">Alaska</option>
              <option value="Arizona">Arizona</option>
              <option value="Arkansas">Arkansas</option>
              <option value="California">California</option>
               etc....
</cfselect>

And it works perfectly now.  

0
 
dgrafxCommented:
I did notice that you didn't have output around the value but I thought that was just a mistake when typing in this forum.
#statelist# just meant your list of states instead of tying them in.

Good luck ...
0
 
dndcoAuthor Commented:
I am happy with the results, thanks.

I'll be posting a new question tomorrow.  Another problem with the same form.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now