Question
<cfif form.secret_word EQ #session.secretWord#> thank you <cfelse>sorry </cfif>
If users enter the secret_word which coincides with the
session.secretWord then the form can continue and do its
validating. If not the form stops and the cfelse message is shown.
The cfif code is here:
<cfif form.secret_word EQ #session.secretWord#>
Thank you for your message.
<cfelse>
Sorry, the secret word you entered in the field does not match the word in the image
Please hit your back button</cfif>
My actionpage is here and I would be very greatful if someone could show me where the cfif should go. Thanks:
<cfinclude template="topnav.cfm">
<!--- Must create this default structure or we pull an error --->
<cfparam name="session.contact_nfo" default="">
<cfif NOT IsStruct(session.contact_nfo)>
<cfset session.contact_nfo = StructNew()>
</cfif>
<!-- Now we create default variable using cfparam -->
<cfparam name="Form.terms" default="NO">
<cfparam name="session.contact_nfo.Name" default="">
<cfparam name="Form.Country" default="">
<cfparam name="Form.City" default="">
<cfparam name="Form.Telephone" default="">
<cfparam name="session.contact_nfo.email" default="">
<cfparam name="session.contact_nfo.comments" default="">
<!-- Now we clear the Session of any Values to allow us to place our new form Values passed from our form page -->
<cfset StructClear(session.contact_nfo)>
<!-- Now we are placing our Form Values into the Session -->
<cfset session.contact_nfo.terms= form.terms>
<cfset session.contact_nfo.Name= form.Name>
<cfset session.contact_nfo.email= form.email>
<cfset session.contact_nfo.comments= form.comments>
<!-- Now we are going to do our Error Checking first off by creating a value of nothing for the variable we are calling Errors -->
<cfparam name="errors" type="string" default="">
<!-- As we check for Errors if we find one we place it in our List to display to our user making it easy for the end-user to correct as they can see the error -->
<!-- Notice we are not validating the checkbox as it is not a required form field -->
<cfif form.Name EQ "">
<cfset errors = errors & "<li>You Forgot to enter your name!</li>">
</cfif>
<!-- Checking the email is a little more complicated so we use a regular expression to check and see if there is a email address and also is it formed properly -->
<cfif NOT REFindnocase("^[-_!a-z0-9\.]+@([-_a-z0-9]+\.)+[a-z]{2,6}$", email)>
<cfset errors = errors & "<li class=""errors"">Your Email Address seems incorrect?</li>">
</cfif>
<cfif form.comments EQ "">
<cfset errors = errors & "<li class=""errors"">You Forgot to enter a comment!</li>">
</cfif>
<cfif errors NEQ "">
<!-- Here we are collecting the Error Message generated by our code and placing them into a list for the user to see -->
<TABLE class="label1" WIDTH="300" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="Center">
<TR><P> <TD ALIGN="Left" VALIGN="Top">You have some errors in your form submission, please try again<br>
<cfoutput>#errors#</cfoutput></td></P>
</tr>
</table>
<!-- Also take note that the form action is now different in that it is carrying the applications session with it which we need to make our Application.cfm file work with the action. -->
<cfoutput>
<form method="post" action="action_form.cfm?#session.UrlToken#">
<P><TABLE class="label1" WIDTH="300" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="Center">
<TR> <TD ALIGN="Left" VALIGN="Top">
<!-- This is how we place our session values into the form field also important to note the because we used cfparam in the start of this page to assign a default value of "" if there was no value originally entered in the form than it will show no value here. If we did not use the cfparam tag we would now show an error as the session would go looking for a non-existant value -->
<P>Name:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Name" SIZE="40" value="#session.contact_nfo.Name#"></P>
<P>Country:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Country" SIZE="40" value="#Form.Country#"></P>
<P>City:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="City" SIZE="40" value="#Form.City#"></P>
<P>Telephone:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Telephone" SIZE="40" value="#Form.Telephone#"></P>
<P>E-mail: <br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Email" SIZE="40" value="#session.contact_nfo.email#"></P>
</P>
<P>Comments: <BR>
<textarea cols="40" size="40" class="ftforminputsmall" rows="2" name="comments">#session.contact_nfo.comments#</textarea></P>
<P>Booking dates:<br>
<P>From:
<select name="day" class="ftforminputsmall">
<cfloop from="1" to="31" index="i">
<option value="#i#" selected="selected">#form.day#</option>
</cfloop>
</select>
<cfset monthList = "January,February,March,April,May,June,July,August,September,October,November,December" />
<select name="month" class="ftforminputsmall">
<cfloop list="#monthList#" index="m"> <option value="#m#" selected="selected">#form.month#</option></cfloop> </select>
<select name="year" class="ftforminputsmall">
<cfloop from="2006" to="2020" index="i">
<option value="#i#">#form.year#</option>
</cfloop>
</select>
</P>
<P>To:
<select name="dayto" class="ftforminputsmall">
<cfloop from="1" to="31" index="i">
<option value="#i#" selected="selected">#form.dayto#</option>
</cfloop>
</select>
<cfset monthList = "January,February,March,April,May,June,July,August,September,October,November,December" />
<select name="monthto" class="ftforminputsmall">
<cfloop list="#monthList#" index="m"> <option value="#m#" selected="selected">#form.monthto#</option></cfloop> </select>
<select name="yearto" class="ftforminputsmall">
<cfloop from="2006" to="2020" index="i">
<option value="#i#" selected="selected">#form.yearto#</option>
</cfloop>
</select>
<P>
<input name="Submit" type="submit" CLASS="ftforminputsmall" value="Submit">
</P>
</table>
</form>
</cfoutput>
<!-- If no errors were detected we abort the previous code and show the next code section -->
<cfabort>
</cfif></td></tr>
<cfif form.secret_word EQ #session.secretWord#>
Thank you for your message.
<cfelse>
Sorry, the secret word you entered in the field does not match the word in the image
Please hit your back button</cfif>
My actionpage is here and I would be very greatful if someone could show me where the cfif should go. Thanks:
<cfinclude template="topnav.cfm">
<!--- Must create this default structure or we pull an error --->
<cfparam name="session.contact_nfo" default="">
<cfif NOT IsStruct(session.contact_nfo)>
<cfset session.contact_nfo = StructNew()>
</cfif>
<!-- Now we create default variable using cfparam -->
<cfparam name="Form.terms" default="NO">
<cfparam name="session.contact_nfo.Name" default="">
<cfparam name="Form.Country" default="">
<cfparam name="Form.City" default="">
<cfparam name="Form.Telephone" default="">
<cfparam name="session.contact_nfo.email" default="">
<cfparam name="session.contact_nfo.comments" default="">
<!-- Now we clear the Session of any Values to allow us to place our new form Values passed from our form page -->
<cfset StructClear(session.contact_nfo)>
<!-- Now we are placing our Form Values into the Session -->
<cfset session.contact_nfo.terms= form.terms>
<cfset session.contact_nfo.Name= form.Name>
<cfset session.contact_nfo.email= form.email>
<cfset session.contact_nfo.comments= form.comments>
<!-- Now we are going to do our Error Checking first off by creating a value of nothing for the variable we are calling Errors -->
<cfparam name="errors" type="string" default="">
<!-- As we check for Errors if we find one we place it in our List to display to our user making it easy for the end-user to correct as they can see the error -->
<!-- Notice we are not validating the checkbox as it is not a required form field -->
<cfif form.Name EQ "">
<cfset errors = errors & "<li>You Forgot to enter your name!</li>">
</cfif>
<!-- Checking the email is a little more complicated so we use a regular expression to check and see if there is a email address and also is it formed properly -->
<cfif NOT REFindnocase("^[-_!a-z0-9\.]+@([-_a-z0-9]+\.)+[a-z]{2,6}$", email)>
<cfset errors = errors & "<li class=""errors"">Your Email Address seems incorrect?</li>">
</cfif>
<cfif form.comments EQ "">
<cfset errors = errors & "<li class=""errors"">You Forgot to enter a comment!</li>">
</cfif>
<cfif errors NEQ "">
<!-- Here we are collecting the Error Message generated by our code and placing them into a list for the user to see -->
<TABLE class="label1" WIDTH="300" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="Center">
<TR><P> <TD ALIGN="Left" VALIGN="Top">You have some errors in your form submission, please try again<br>
<cfoutput>#errors#</cfoutput></td></P>
</tr>
</table>
<!-- Also take note that the form action is now different in that it is carrying the applications session with it which we need to make our Application.cfm file work with the action. -->
<cfoutput>
<form method="post" action="action_form.cfm?#session.UrlToken#">
<P><TABLE class="label1" WIDTH="300" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="Center">
<TR> <TD ALIGN="Left" VALIGN="Top">
<!-- This is how we place our session values into the form field also important to note the because we used cfparam in the start of this page to assign a default value of "" if there was no value originally entered in the form than it will show no value here. If we did not use the cfparam tag we would now show an error as the session would go looking for a non-existant value -->
<P>Name:
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Name" SIZE="40" value="#session.contact_nfo.Name#"></P>
<P>Country:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Country" SIZE="40" value="#Form.Country#"></P>
<P>City:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="City" SIZE="40" value="#Form.City#"></P>
<P>Telephone:<br>
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Telephone" SIZE="40" value="#Form.Telephone#"></P>
<P>E-mail:
<INPUT TYPE="Text" class="ftforminputsmall" NAME="Email" SIZE="40" value="#session.contact_nfo.email#"></P>
</P>
<P>Comments:
<textarea cols="40" size="40" class="ftforminputsmall" rows="2" name="comments">#session.contact_nfo.comments#</textarea></P>
<P>Booking dates:<br>
<P>From:
<select name="day" class="ftforminputsmall">
<cfloop from="1" to="31" index="i">
<option value="#i#" selected="selected">#form.day#</option>
</cfloop>
</select>
<cfset monthList = "January,February,March,April,May,June,July,August,September,October,November,December" />
<select name="month" class="ftforminputsmall">
<cfloop list="#monthList#" index="m"> <option value="#m#" selected="selected">#form.month#</option></cfloop> </select>
<select name="year" class="ftforminputsmall">
<cfloop from="2006" to="2020" index="i">
<option value="#i#">#form.year#</option>
</cfloop>
</select>
</P>
<P>To:
<select name="dayto" class="ftforminputsmall">
<cfloop from="1" to="31" index="i">
<option value="#i#" selected="selected">#form.dayto#</option>
</cfloop>
</select>
<cfset monthList = "January,February,March,April,May,June,July,August,September,October,November,December" />
<select name="monthto" class="ftforminputsmall">
<cfloop list="#monthList#" index="m"> <option value="#m#" selected="selected">#form.monthto#</option></cfloop> </select>
<select name="yearto" class="ftforminputsmall">
<cfloop from="2006" to="2020" index="i">
<option value="#i#" selected="selected">#form.yearto#</option>
</cfloop>
</select>
<P>
<input name="Submit" type="submit" CLASS="ftforminputsmall" value="Submit">
</P>
</table>
</form>
</cfoutput>
<!-- If no errors were detected we abort the previous code and show the next code section -->
<cfabort>
</cfif></td></tr>