dndco
asked on
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>#sessio n.buynow_n fo.State#< /cfoutput> </OPTION>
<option value="Alabama">Alabama</o ption>
<option value="Alaska">Alaska</opt ion>
<option value="Arizona">Arizona</o ption>
<option value="Arkansas">Arkansas< /option>
<option value="California">Califor nia</optio n>
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.NAMEOF FIELD# 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.NAMEOF FIELD#
How can I fix this?
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
<option value="Alabama">Alabama</o
<option value="Alaska">Alaska</opt
<option value="Arizona">Arizona</o
<option value="Arkansas">Arkansas<
<option value="California">Califor
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.NAMEOF
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.NAMEOF
How can I fix this?
ASKER
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_n fo.State#< /OPTION>
</cfoutput>
<option value="Alabama">Alabama</o ption>
<option value="Alaska">Alaska</opt ion>
<option value="Arizona">Arizona</o ption>
<option value="Arkansas">Arkansas< /option>
<option value="California">Califor nia</optio n>
etc....
</cfselect>
And it works perfectly now.
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
</cfoutput>
<option value="Alabama">Alabama</o
<option value="Alaska">Alaska</opt
<option value="Arizona">Arizona</o
<option value="Arkansas">Arkansas<
<option value="California">Califor
etc....
</cfselect>
And it works perfectly now.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am happy with the results, thanks.
I'll be posting a new question tomorrow. Another problem with the same form.
I'll be posting a new question tomorrow. Another problem with the same form.
<cfoutput>
<select name="State">
<cfloop list="#statelist#" index="ii">
<option value="#ii#" <cfif ii is session.buynow_nfo.State>s
</cfloop>
</select>
</cfoutput>