Submit validation and preview
I am trying to create a form that validates to make sure both fields have values entered.
If they have both values entered then go to preview page. If not then stay in the form page (main.cfm).
My below attempt is not working because sometimes it works with the validation and sometimes it doesnt work where it will send to preview page even if there are blank values or a blank value.
Please advise.
--------
main.cfm
<cfoutput>
<cfset myAction = "">
<cfif isDefined("form.submit")>
<cfif trim(form.city) eq "" or trim(form.state) eq "">
<cfset myAction = "main.cfm">
<cfelse>
<cfset myAction = "preview.cfm">
</cfif>
</cfif>
Both City and State are required.<br>
<form action="#myAction#" method="post">
City: <input type="text" name="city" value="<cfif isDefined("form.city")>#form.city#</cfif>"><br>
State: <input type="text" name="state" value="<cfif isDefined("form.state")>#form.state#</cfif>"><br>
<input type="submit" name="submit" value="Preview">
</form>
</cfoutput>
-----------
Preview.cfm
<cfoutput>
Preview of what you entered:<br>
City = #form.city#<br>
State = #form.state#
<form action="process.cfm" method="post">
<input type="hidden" name="city">
<input type="hidden" name="state">
<input type="submit" name="submit" value="Submit Information"> 
<input type="button" value="Go Back and Edit Form" onclick="history.go(-1)">
</form>
</cfoutput>
