clivecrawdevil
asked on
Compare ColdFusion form fields with validation
Hi Experts
Coldfusion newbie and I have come unstuck with form validation.
I need to specify that if one field has a certain value then this limits the valid entry’s for three other fields like so.
Field A is 01
Field B can be only 01 or 02
Field C has to be 99
Field D can be 01, 02 or 03
Any combination of valid entry’s and I would like the form data to be submitted.
I cannot seem to get this to work.
I have tried server side validation using cfif statements and cfcase statements.
I am running Coldfusion MX 7 and using a flash form.
500 points for a comprehensive answer to this one. As I cannot work it out and the web has not pointed me in the right direction.
Thanks
Clive
Coldfusion newbie and I have come unstuck with form validation.
I need to specify that if one field has a certain value then this limits the valid entry’s for three other fields like so.
Field A is 01
Field B can be only 01 or 02
Field C has to be 99
Field D can be 01, 02 or 03
Any combination of valid entry’s and I would like the form data to be submitted.
I cannot seem to get this to work.
I have tried server side validation using cfif statements and cfcase statements.
I am running Coldfusion MX 7 and using a flash form.
500 points for a comprehensive answer to this one. As I cannot work it out and the web has not pointed me in the right direction.
Thanks
Clive
Okay then you need to show us exactly what the restrictions are.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi I tried this gonna post the entire site in order for you to be able to see the entire code.
<CFSET error = 0>
<CFIF form.E12 eq "01">
<CFIF NOT LISTFIND("01,02",form.E13) >
<CFSET error = 1>
</CFIF>
<CFIF form.E14 neq "99">
<CFSET error = 1>
</CFIF>
<CFIF NOT LISTFIND("01,02,03",form.E 15)>
<CFSET error = 1>
</CFIF>
</CFIF>
<CFIF error eq 0>
<CFSET error = 1>
<CFIF form.E12 eq "03">
<CFIF NOT LISTFIND("01,02",form.E13) >
<CFSET error = 2>
</CFIF>
<CFIF form.E14 neq "99">
<CFSET error = 2>
</CFIF>
<CFIF NOT LISTFIND("02",form.E15)>
<CFSET error = 2>
</CFIF>
</CFIF>
<CFIF error eq 1>
<CFSET error = 2>
<CFIF form.E12 eq "02,05">
<CFIF from.E13 neq "98">
<CFSET error = 3>
</CFIF>
<CFIF form.E14 neq "99">
<CFSET error = 3>
</CFIF>
<CFIF from.E15 neq "99">
<CFSET error = 3>
</CFIF>
</CFIF>
<CFIF error eq 2>
<CFSET error = 3>
<CFIF form.E12 eq "04">
<CFIF NOT LISTFIND("01,02,03,04,05", form.E14)>
<CFSET error = 4>
</CFIF>
<CFIF form.E13 neq "03">
<CFSET error = 4>
</CFIF>
<CFIF form.E15 neq "99">
<CFSET error = 4>
</CFIF>
</CFIF>
<CFIF error eq 3>
<!--- Insert the new record --->
<cfinsert datasource="ILRData" tablename="tblILR" formfields="L03,L09,L10,L1 8,L19,L20, L21,L17,L2 3,L11,L13, L14,L12,L2 7A,L27B,L2 5,L01,A47B 2,A23,E22, E23,A09,E1 2,A48A,A48 B,A47A,E13 A,E13B,E14 ,E15,A47B1 ,E20,E21,L 35,A24,E17 ,E16,A10,E 08,E09,E18 ,E19,A46,A 49,L42,A34 ,A35,L39,E 10">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>BFPan Learners</title>
<style type="text/css">
<!--
body {
background-color: #26468F;
background-image: url(Images/PpBg.png);
margin-left: 100px;
margin-right: 100px;
margin-top: 30px;
margin-bottom: 100px;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #FFFFFF;
}
.style1 {color: #5EB05E}
a {
font-size: 14px;
color: #FFFFFF;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #CCCCCC;
}
a:hover {
text-decoration: underline;
color: #5EB05E;
}
a:active {
text-decoration: none;
}
.style2 {font-size: 18px}
-->
</style></head>
<body>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="Images/BlueBGTopLeft. png" width="20" height="20"></td>
<td bgcolor="#26468F"> </ td>
<td><img src="Images/BlueBGTopRight .png" width="20" height="20"></td>
</tr>
<tr>
<td height="640" bgcolor="#26468F"> </ td>
<td>
<table width="818" border="0" cellpadding="5" cellspacing="5" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<tr align="right" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<td height="191" align="left" valign="top" bordercolor="#FFFFFF"><tab le width="796" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><img src="Images/BlueTopLeft.gi f" width="20" height="20"></td>
<td width="756" bgcolor="#26468F"> </ td>
<td width="20"><img src="Images/BlueTopRight.g if" width="20" height="20"></td>
</tr>
<tr>
<td rowspan="3" bgcolor="#26468F"> </ td>
<td bgcolor="#26468F"><h1 align="center" class="style1">Building Foundations Pan London </h1></td>
<td rowspan="3" bgcolor="#26468F"> </ td>
</tr>
<tr>
<td><object classid="clsid:D27CDB6E-AE 6D-11cf-96 B8-4445535 40000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="756" height="52">
<param name="movie" value="SWF/menu.swf">
<param name="quality" value="high">
<param name="BGCOLOR" value="#26468F">
<embed src="SWF/menu.swf" width="756" height="52" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockw ave-flash" bgcolor="#26468F"></embed>
</object></td>
</tr>
<tr>
<td><object classid="clsid:D27CDB6E-AE 6D-11cf-96 B8-4445535 40000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="756" height="52">
<param name="movie" value="SWF/6_larger_button s.swf">
<param name="quality" value="high">
<param name="BGCOLOR" value="#26468F">
<embed src="SWF/6_larger_buttons. swf" width="756" height="52" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockw ave-flash" bgcolor="#26468F"></embed>
</object></td>
</tr>
<tr>
<td><img src="Images/BlueBottomLeft .png" width="20" height="20"></td>
<td bgcolor="#26468F"> </ td>
<td><img src="Images/BlueBottomRigh t.gif" width="20" height="20"></td>
</tr>
</table></td>
</tr>
<tr align="right" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<td width="798" height="434" align="center" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20" height="20"><img src="Images/GreenTopLeft.p ng" width="20" height="20"></td>
<td width="360" bgcolor="#75BC75"> </ td>
<td width="385" bgcolor="#75BC75"> </ td>
<td width="20"><img src="Images/GreenTopRight. png" width="20" height="20"></td>
</tr>
<tr>
<td height="32" bgcolor="#26468F"> </ td>
<td colspan="2" align="center" valign="top" bgcolor="#26468F"><span class="style2">
<cfoutput> #L10# #L09# has been sucessfully added to the ILRDatabase </cfoutput> </span></td>
<td bgcolor="#26468F"> </ td>
</tr>
<tr>
<td height="352" bgcolor="#26468F"> </ td>
<td colspan="2" align="center" valign="top" bgcolor="#26468F">
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="ILRForm.cfm" target="_self"><strong>Add Learner </strong></a></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><span class="style3">Click the link above to add a learner </span></div></td>
</tr>
<tr>
<td><div align="center"><a href="ILRSearchForm.cfm" target="_self"><strong>Edi t Learner</strong></a></div> </td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><span class="style3">Click the link above to edit learners you have already added </span></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><a href="Section3SearchForm.c fm" target="_self"><strong>Com plete learner</strong></a></div> </td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><span class="style3">Click the above link to fill in section 3 of the ILR Form and complete a learner </span></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><a href="ILRSearchForm.cfm" target="_self"><strong>Pri nt ILR</strong></a></div></td >
</tr>
<tr>
<td align="left" valign="top"><div align="center"><span class="style3">Click the above link to print a ILR form directly from the ILRDatabase </span></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><strong>Add Exam </strong></div></td>
</tr>
<tr>
<td align="center" valign="top"><span class="style3">Click the above link to enter candidates exam details </span></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><strong>Lea rner survey </strong></div></td>
</tr>
<tr>
<td align="center" valign="top"><span class="style3">Click the above link to complete the learner survey</span></td>
</tr>
<tr>
<td height="16"> </td>
</tr>
</table>
</td>
<td bgcolor="#26468F"> </ td>
</tr>
<tr>
<td height="20"><img src="Images/BlueBottomLeft .png" width="20" height="20"></td>
<td colspan="2" bgcolor="#26468F"> </ td>
<td><img src="Images/BlueBottomRigh t.png" width="20" height="20"></td>
</tr>
</table></td>
</tr>
</table>
</td>
<td bgcolor="#26468F"> </ td>
</tr>
<tr>
<td height="20"><img src="Images/BlueBGBottomLe ft.png" width="20" height="20"></td>
<td bgcolor="#26468F"> </ td>
<td><img src="Images/BlueBGBottomRi ght.png" width="20" height="20"></td>
</tr>
</table>
</body>
</html>
<CFELSE>
E12 = 02 or 05 E13 needs to be 98 E14 needs to be 99 E15 needs to be 99.
</CFIF>
<CFELSE>
E12 = 04 E13 needs to be 03 E14 needs to be 01,02,03,04,05 E15 needs to be 99.
</CFIF>
<CFELSE>
E12 = 03 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 02.
</CFIF>
<CFELSE>
E12 = 01 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 01,02,03.
</CFIF>
When i submit i get a String index out of range: -2 error message no idea where to start.
I Thought i would be able to nest the cfif statements in order to achive all the required validation.
The fields involved are E12, E13, E14 and E15.
the logic needs to be
E12 = 02 or 05 E13 needs to be 98 E14 needs to be 99 E15 needs to be 99.
E12 = 04 E13 needs to be 03 E14 needs to be 01,02,03,04,05 E15 needs to be 99.
E12 = 03 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 02.
E12 = 01 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 01,02,03.
Any 1 of the above is valid and the form should be submitted anything else should be thrown back with an error message.
Any help would be greatly appriciated.
Thanks
Clive
<CFSET error = 0>
<CFIF form.E12 eq "01">
<CFIF NOT LISTFIND("01,02",form.E13)
<CFSET error = 1>
</CFIF>
<CFIF form.E14 neq "99">
<CFSET error = 1>
</CFIF>
<CFIF NOT LISTFIND("01,02,03",form.E
<CFSET error = 1>
</CFIF>
</CFIF>
<CFIF error eq 0>
<CFSET error = 1>
<CFIF form.E12 eq "03">
<CFIF NOT LISTFIND("01,02",form.E13)
<CFSET error = 2>
</CFIF>
<CFIF form.E14 neq "99">
<CFSET error = 2>
</CFIF>
<CFIF NOT LISTFIND("02",form.E15)>
<CFSET error = 2>
</CFIF>
</CFIF>
<CFIF error eq 1>
<CFSET error = 2>
<CFIF form.E12 eq "02,05">
<CFIF from.E13 neq "98">
<CFSET error = 3>
</CFIF>
<CFIF form.E14 neq "99">
<CFSET error = 3>
</CFIF>
<CFIF from.E15 neq "99">
<CFSET error = 3>
</CFIF>
</CFIF>
<CFIF error eq 2>
<CFSET error = 3>
<CFIF form.E12 eq "04">
<CFIF NOT LISTFIND("01,02,03,04,05",
<CFSET error = 4>
</CFIF>
<CFIF form.E13 neq "03">
<CFSET error = 4>
</CFIF>
<CFIF form.E15 neq "99">
<CFSET error = 4>
</CFIF>
</CFIF>
<CFIF error eq 3>
<!--- Insert the new record --->
<cfinsert datasource="ILRData" tablename="tblILR" formfields="L03,L09,L10,L1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>BFPan Learners</title>
<style type="text/css">
<!--
body {
background-color: #26468F;
background-image: url(Images/PpBg.png);
margin-left: 100px;
margin-right: 100px;
margin-top: 30px;
margin-bottom: 100px;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #FFFFFF;
}
.style1 {color: #5EB05E}
a {
font-size: 14px;
color: #FFFFFF;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #CCCCCC;
}
a:hover {
text-decoration: underline;
color: #5EB05E;
}
a:active {
text-decoration: none;
}
.style2 {font-size: 18px}
-->
</style></head>
<body>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="Images/BlueBGTopLeft.
<td bgcolor="#26468F"> </
<td><img src="Images/BlueBGTopRight
</tr>
<tr>
<td height="640" bgcolor="#26468F"> </
<td>
<table width="818" border="0" cellpadding="5" cellspacing="5" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<tr align="right" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<td height="191" align="left" valign="top" bordercolor="#FFFFFF"><tab
<tr>
<td width="20"><img src="Images/BlueTopLeft.gi
<td width="756" bgcolor="#26468F"> </
<td width="20"><img src="Images/BlueTopRight.g
</tr>
<tr>
<td rowspan="3" bgcolor="#26468F"> </
<td bgcolor="#26468F"><h1 align="center" class="style1">Building Foundations Pan London </h1></td>
<td rowspan="3" bgcolor="#26468F"> </
</tr>
<tr>
<td><object classid="clsid:D27CDB6E-AE
<param name="movie" value="SWF/menu.swf">
<param name="quality" value="high">
<param name="BGCOLOR" value="#26468F">
<embed src="SWF/menu.swf" width="756" height="52" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockw
</object></td>
</tr>
<tr>
<td><object classid="clsid:D27CDB6E-AE
<param name="movie" value="SWF/6_larger_button
<param name="quality" value="high">
<param name="BGCOLOR" value="#26468F">
<embed src="SWF/6_larger_buttons.
</object></td>
</tr>
<tr>
<td><img src="Images/BlueBottomLeft
<td bgcolor="#26468F"> </
<td><img src="Images/BlueBottomRigh
</tr>
</table></td>
</tr>
<tr align="right" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<td width="798" height="434" align="center" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20" height="20"><img src="Images/GreenTopLeft.p
<td width="360" bgcolor="#75BC75"> </
<td width="385" bgcolor="#75BC75"> </
<td width="20"><img src="Images/GreenTopRight.
</tr>
<tr>
<td height="32" bgcolor="#26468F"> </
<td colspan="2" align="center" valign="top" bgcolor="#26468F"><span class="style2">
<cfoutput> #L10# #L09# has been sucessfully added to the ILRDatabase </cfoutput> </span></td>
<td bgcolor="#26468F"> </
</tr>
<tr>
<td height="352" bgcolor="#26468F"> </
<td colspan="2" align="center" valign="top" bgcolor="#26468F">
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="ILRForm.cfm" target="_self"><strong>Add
</tr>
<tr>
<td align="center" valign="top"><div align="center"><span class="style3">Click the link above to add a learner </span></div></td>
</tr>
<tr>
<td><div align="center"><a href="ILRSearchForm.cfm" target="_self"><strong>Edi
</tr>
<tr>
<td align="center" valign="top"><div align="center"><span class="style3">Click the link above to edit learners you have already added </span></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><a href="Section3SearchForm.c
</tr>
<tr>
<td align="center" valign="top"><div align="center"><span class="style3">Click the above link to fill in section 3 of the ILR Form and complete a learner </span></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><a href="ILRSearchForm.cfm" target="_self"><strong>Pri
</tr>
<tr>
<td align="left" valign="top"><div align="center"><span class="style3">Click the above link to print a ILR form directly from the ILRDatabase </span></div></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><strong>Add
</tr>
<tr>
<td align="center" valign="top"><span class="style3">Click the above link to enter candidates exam details </span></td>
</tr>
<tr>
<td align="center" valign="top"><div align="center"><strong>Lea
</tr>
<tr>
<td align="center" valign="top"><span class="style3">Click the above link to complete the learner survey</span></td>
</tr>
<tr>
<td height="16"> </td>
</tr>
</table>
</td>
<td bgcolor="#26468F"> </
</tr>
<tr>
<td height="20"><img src="Images/BlueBottomLeft
<td colspan="2" bgcolor="#26468F"> </
<td><img src="Images/BlueBottomRigh
</tr>
</table></td>
</tr>
</table>
</td>
<td bgcolor="#26468F"> </
</tr>
<tr>
<td height="20"><img src="Images/BlueBGBottomLe
<td bgcolor="#26468F"> </
<td><img src="Images/BlueBGBottomRi
</tr>
</table>
</body>
</html>
<CFELSE>
E12 = 02 or 05 E13 needs to be 98 E14 needs to be 99 E15 needs to be 99.
</CFIF>
<CFELSE>
E12 = 04 E13 needs to be 03 E14 needs to be 01,02,03,04,05 E15 needs to be 99.
</CFIF>
<CFELSE>
E12 = 03 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 02.
</CFIF>
<CFELSE>
E12 = 01 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 01,02,03.
</CFIF>
When i submit i get a String index out of range: -2 error message no idea where to start.
I Thought i would be able to nest the cfif statements in order to achive all the required validation.
The fields involved are E12, E13, E14 and E15.
the logic needs to be
E12 = 02 or 05 E13 needs to be 98 E14 needs to be 99 E15 needs to be 99.
E12 = 04 E13 needs to be 03 E14 needs to be 01,02,03,04,05 E15 needs to be 99.
E12 = 03 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 02.
E12 = 01 E13 needs to be 01 or 02 E14 needs to be 99 E15 needs to be 01,02,03.
Any 1 of the above is valid and the form should be submitted anything else should be thrown back with an error message.
Any help would be greatly appriciated.
Thanks
Clive