LearnersPermit
Technical User
My problem is that I have a form with required fields. I want to submit the form to the user the first time and allow them to submit. Once they submit the application confirms whether they have missing fields and reshows the form with a list of the missing fields. If not the information gathered is sent by e-mail to the recipient and an acknowledge is diplayed on the screen to the user that their order has occcured.
The problem with my code is that the first time that the form is submitted to the user it comes up with the list of missing fields also. I want them to have the blank form be displayed the first time through without the error messages.
<cfif not isdefined("form.submit")>
<cfparam name="form.firstname" default="">
<cfparam name="form.lastname" default="">
<!--- There are several others --->
</cfif>
<!-- 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 -->
<cfif form.firstname EQ "">
<cfset errors = errors & "<li>Please enter your first name!</li>">
</cfif>
<cfif form.lastname EQ "">
<cfset errors = errors & "<li> Please enter your last name!</li">
</cfif>
<!---Removed several others to shorten this message--->
<!-- If any errors were detected in the previous section we now show the form again placing our error messages in a list to show the users the errors they need to correct Now this is where we use the session we created, we don't want our user to have to re-enter good data again so we show him the form with the original data he entered in it saving him typing time. This will make perfect sense on a long form where quite possibly you could lose a potential customer if they get annoyed at having to re-fill in information again -->
<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 width="100%" border="0" align="center" cellpadding="0">
<tr valign="middle">
<td colspan="2"><center><h1>InterLibrary Loan </h1></center></td>
</tr>
<tr valign="middle">
<td colspan="2"><center><h3>Book Request</h3></center></td>
</tr>
<tr>
<td>You have some errors in your form submission! Please try again!<br>
<ol><cfoutput>#errors#</cfoutput>
</ol>
</td>
</tr>
</table>
<cfoutput>
<form name="bookreq" method="post" action="new_bookreq.cfm">
<table width="80%" border="0" align="center" cellpadding="0">
<tr><td colspan="2"><h3>User Information </h3></td></tr>
<tr><td><font color="red">*</font>First Name:</td><td><input type="text" name="firstname" size="30" value="#form.firstname#"></td>
<td><font color="red">*</font>Last Name:</td><td><input type="text" name="lastname" size="30" value="#form.lastname#"></td>
</tr>
<tr valign="middle"><td colspan="2" align="center"><br><input name="Submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
</cfoutput>
<cfif form.submit is not "">
<cfmail to="someone.com"
from="recipient.com"
subject="Ill Book Request from #form.firstname# #form.lastname#" >
A new Book request has been received.
___________________________________________________________________
Name: #Form.firstname# #form.lastname#
Establishment: #Form.establishment#
</cfmail>
</table>
<!--- Acknowledgement is sent to the person requesting the journal. --->
<table width="442" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="442" valign="top">
<table width="100%" cellspacing="0" cellpadding="0">
<tr align="center">
<td align="center" class="headline">
<b>ILL - Book Request</b> </td>
</tr>
<tr align="center">
<td align="center">
<p><hr align="center" width="40%"><br>
<tr><td align="center">Thank you! Your request for the following Book:</td></tr>
<tr><td align="center"><cfoutput>#Form.book#, #Form.bookauthor#</cfoutput></td></tr>
<tr><td align="center"><cfoutput> #Form.chapter#, #Form.author#</cfoutput></td></tr>
<tr><td align="center"><p>Has been received by recipient for action!</p></td></tr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</cfif>
</cfif>
Thank you
The problem with my code is that the first time that the form is submitted to the user it comes up with the list of missing fields also. I want them to have the blank form be displayed the first time through without the error messages.
<cfif not isdefined("form.submit")>
<cfparam name="form.firstname" default="">
<cfparam name="form.lastname" default="">
<!--- There are several others --->
</cfif>
<!-- 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 -->
<cfif form.firstname EQ "">
<cfset errors = errors & "<li>Please enter your first name!</li>">
</cfif>
<cfif form.lastname EQ "">
<cfset errors = errors & "<li> Please enter your last name!</li">
</cfif>
<!---Removed several others to shorten this message--->
<!-- If any errors were detected in the previous section we now show the form again placing our error messages in a list to show the users the errors they need to correct Now this is where we use the session we created, we don't want our user to have to re-enter good data again so we show him the form with the original data he entered in it saving him typing time. This will make perfect sense on a long form where quite possibly you could lose a potential customer if they get annoyed at having to re-fill in information again -->
<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 width="100%" border="0" align="center" cellpadding="0">
<tr valign="middle">
<td colspan="2"><center><h1>InterLibrary Loan </h1></center></td>
</tr>
<tr valign="middle">
<td colspan="2"><center><h3>Book Request</h3></center></td>
</tr>
<tr>
<td>You have some errors in your form submission! Please try again!<br>
<ol><cfoutput>#errors#</cfoutput>
</ol>
</td>
</tr>
</table>
<cfoutput>
<form name="bookreq" method="post" action="new_bookreq.cfm">
<table width="80%" border="0" align="center" cellpadding="0">
<tr><td colspan="2"><h3>User Information </h3></td></tr>
<tr><td><font color="red">*</font>First Name:</td><td><input type="text" name="firstname" size="30" value="#form.firstname#"></td>
<td><font color="red">*</font>Last Name:</td><td><input type="text" name="lastname" size="30" value="#form.lastname#"></td>
</tr>
<tr valign="middle"><td colspan="2" align="center"><br><input name="Submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
</cfoutput>
<cfif form.submit is not "">
<cfmail to="someone.com"
from="recipient.com"
subject="Ill Book Request from #form.firstname# #form.lastname#" >
A new Book request has been received.
___________________________________________________________________
Name: #Form.firstname# #form.lastname#
Establishment: #Form.establishment#
</cfmail>
</table>
<!--- Acknowledgement is sent to the person requesting the journal. --->
<table width="442" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="442" valign="top">
<table width="100%" cellspacing="0" cellpadding="0">
<tr align="center">
<td align="center" class="headline">
<b>ILL - Book Request</b> </td>
</tr>
<tr align="center">
<td align="center">
<p><hr align="center" width="40%"><br>
<tr><td align="center">Thank you! Your request for the following Book:</td></tr>
<tr><td align="center"><cfoutput>#Form.book#, #Form.bookauthor#</cfoutput></td></tr>
<tr><td align="center"><cfoutput> #Form.chapter#, #Form.author#</cfoutput></td></tr>
<tr><td align="center"><p>Has been received by recipient for action!</p></td></tr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</cfif>
</cfif>
Thank you