Forums
This topic is locked
Form Submission & Validation
Posted 04 May 2004 18:38:30
1
has voted
04 May 2004 18:38:30 Georgio Sfakiotakis posted:
Hi there,I'm using the popular DW MX Extension - Check Form by Yaromat.com. I've applied it to my Insert form and although it validates correctly the damn thing still goes ahead and posts all the dud data/empty fields to the DB.
I've looked at it (and looked at it...and looked at it... etc etc) and I can't see why - I was hoping an eagle eyed visitor could tell me where I was going wrong - I figured it had something to do with the first line of the <form> tag but I wasn't 100% sure.
Thanks in advance
Georgio
Here's the code for my page:
<html>
<head>
<title>Staffdeals.co.uk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles/style.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="1">
<table width="800" border="0" align="center" class="MainBorder">
<tr>
<td colspan="2"> <div align="left">
<!--#include file="includes/header_inc.asp" -->
</div></td>
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert") = "form1" Then
MM_editConnection = MM_connStaffDeals_STRING
MM_editTable = "CompanyDetails"
MM_editRedirectUrl = "signup_thankyou.asp"
MM_fieldsStr = "CompanyName|value|CompanyUsername|value|Firstname|value|Surname|value|CompanyPassword|value|CompanyAddress1|value|CompanyAddress2|value|CompanyAddress3|value|SecretQuestion|value|CompanyAddress4|value|SecretAnswer|value|CompanyPostcode|value|CompanyTelCode|value|CompanyTel|value|CompanyWebsite|value|CompanyFaxCode|value|CompanyFax|value|CompanyAbta|value|CompanyEmail|value|CompanyIata|value|CompanyAtol|value"
MM_columnsStr = "CompanyName|',none,''|Username|',none,''|ContactFirstName|',none,''|ContactSurName|',none,''|Password|',none,''|CompanyAddress1|',none,''|CompanyAddress2|',none,''|CompanyAddress3|',none,''|SecretQuestion|',none,''|CompanyAddress4|',none,''|SecretAnswer|',none,''|CompanyPostcode|',none,''|CompanyTelCode|',none,''|CompanyTel|none,none,NULL|CompanyWebsite|',none,''|CompanyFaxAreaCode|',none,''|CompanyFax|none,none,NULL|CompanyAbta|',none,''|CompanyEmail|',none,''|CompanyIata|',none,''|CompanyAtol|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert") <> "" Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),","
MM_delim = MM_typeArray(0)
If (MM_delim = "none" Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none" Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none" Then MM_emptyVal = ""
If (MM_formVal = "" Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "" Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'" Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''" & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim rsSignUp
Dim rsSignUp_numRows
Set rsSignUp = Server.CreateObject("ADODB.Recordset"
rsSignUp.ActiveConnection = MM_connStaffDeals_STRING
rsSignUp.Source = "SELECT * FROM CompanyDetails"
rsSignUp.CursorType = 0
rsSignUp.CursorLocation = 2
rsSignUp.LockType = 1
rsSignUp.Open()
rsSignUp_numRows = 0
%>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function YY_checkform() { //v4.71
//copyright ©1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,"");
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,"");
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidden'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\w\.=-]+@[\w\.-]+\.[a-zA-Z]{2,4}$"if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#"at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#"at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,""];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]];
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</tr>
<tr>
<td width="17" rowspan="2" valign="top">
<!--#include file="includes/left_inc.asp" -->
</td>
<td height="36" valign="middle"> <img src="images/site/signup.gif" width="74" height="34"></td>
</tr>
<tr>
<td width="757" valign="top"> <table width="99%" border="0" cellpadding="1" cellspacing="0" >
<tr>
<td height="382" valign="top" class="SmallText">
<table width="99%" border="0" cellpadding="1" cellspacing="0">
<tr>
<td height="324" valign="top" class="SmallText">
<form action="<%=MM_editAction%>" method="POST" name="form1" id="form1" onSubmit="YY_checkform('form1','termsandconditionsconf','#q','1','You must confirm you\'ve read our terms & conditions','CompanyName','#q','0','Your company name is required!','CompanyUsername','#q','0','A username is required!','Firstname','#q','0','A contact firstname is required','Surname','#q','0','A contact surname is required','CompanyPassword','#q','0','A password is required!','CompanyAddress1','#q','0','You must provide a house number or office name','CompanyAddress2','#q','0','You must provide a street name','CompanyAddress3','#q','0','You must provide a town or city','SecretQuestion','#q','0','Please advise what your secret question is','CompanyAddress4','#q','0','You must provide a county','SecretAnswer','#q','0','Please advise what your secret answer is','CompanyPostcode','#q','0','Please advise what your postcode is','CompanyTelCode','#0_999999','1','Please provide your telephone area code','CompanyTel','#0_999999','1','Please provide your telephone number','CompanyEmail','S','2','Please provide your email address','CompanyVerifyEmail','#CompanyEmail','6','The email address you provided does not match!','CompanyVerifyPassword','#CompanyPassword','6','The password you provided does not match!');return document.MM_returnValue">
<table align="center">
<tr valign="baseline" class="OffersHeaderText">
<td colspan="4" align="right" nowrap><div align="center">CONTACT
DETAILS </div></td>
<td colspan="2"><div align="center">LOGIN DETAILS </div></td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td width="105" align="right" nowrap>Company Name:</td>
<td colspan="3"> <input name="CompanyName" type="text" class="SmallText" value="" size="32">
* </td>
<td width="110"><div align="right">Username:</div></td>
<td width="253"><input name="CompanyUsername" type="text" class="SmallText" id="CompanyUsername" value="" size="15">
* </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap> Firstname:</td>
<td width="80"><input name="Firstname" type="text" class="SmallText" id="Firstname" value="" size="15"> </td>
<td width="47">Surname: </td>
<td width="111"><input name="Surname" type="text" class="SmallText" id="Surname" value="" size="15">
*</td>
<td><div align="right">Password:</div></td>
<td><input name="CompanyPassword" type="text" class="SmallText" id="CompanyPassword" value="" size="15">
*</td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Number/Office Name</td>
<td colspan="3"><input name="CompanyAddress1" ID="CompanyAddress1" type="text" class="SmallText" value="" size="32">
*</td>
<td><div align="right">Confirm Password:</div></td>
<td><input name="CompanyVerifyPassword" type="password" class="SmallText" id="CompanyVerifyPassword" value="" size="15">
* </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Street:</td>
<td colspan="3"><input name="CompanyAddress2" type="text" ID="CompanyAddress2" class="SmallText" value="" size="32">
*</td>
<td><div align="right"></div></td>
<td> </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Town/City</td>
<td colspan="3"><input name="CompanyAddress3" type="text" ID="CompanyAddress3" class="SmallText" value="" size="32">
*</td>
<td> <div align="right">Secret Question:</div></td>
<td><input name="SecretQuestion" type="text" class="SmallText" id="SecretQuestion" value="" size="32">
<br>
eg Mothers maiden name * </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>County:</td>
<td colspan="3"><input name="CompanyAddress4" type="text" ID="CompanyAddress4" class="SmallText" value="" size="32">
*</td>
<td><div align="right">Secret Answer:</div></td>
<td><input name="SecretAnswer" type="text" class="SmallText" id="SecretAnswer" value="" size="32">
* </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Postcode:</td>
<td colspan="3"><input name="CompanyPostcode" ID="CompanyPostcode" type="text" class="SmallText" value="" size="15">
*</td>
<td> <div align="right"></div></td>
<td> </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap> </td>
<td colspan="3"> </td>
<td colspan="2"><div align="center" class="OffersHeaderText">OTHER DETAILS</div></td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Tel:</td>
<td colspan="3"><input name="CompanyTelCode" type="text" class="SmallText" id="CompanyTelCode" value="" size="6">
<input name="CompanyTel" type="text" ID="CompanyTel" class="SmallText" value="" size="15">
*</td>
<td><div align="center">Company Website:</div></td>
<td><input name="CompanyWebsite" type="text" ID="CompanyWebsite" class="SmallText" value="" size="32"></td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Fax:</td>
<td colspan="3"><input name="CompanyFaxCode" type="text" class="SmallText" id="CompanyFaxCode" value="" size="6">
<input name="CompanyFax" type="text" ID="CompanyFax" class="SmallText" value="" size="15"></td>
<td><div align="right"></div></td>
<td> </td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap> </td>
<td colspan="3"> </td>
<td><div align="right">ABTA Number:</div></td>
<td><input name="CompanyAbta" type="text" ID="CompanyAbta" class="SmallText" value="" size="10">
Leave blank if not a member</td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Email:</td>
<td colspan="3"><input name="CompanyEmail" type="text" ID="CompanyEmail" class="SmallText" value="" size="32">
*</td>
<td><div align="right">IATA Number:</div></td>
<td><input name="CompanyIata" type="text" ID="CompanyIata" class="SmallText" value="" size="10">
Leave blank if not a member</td>
</tr>
<tr valign="baseline" bgcolor="#FDFAFE" class="SmallText">
<td align="right" nowrap>Confirm Email:</td>
<td colspan="3"><input name="CompanyVerifyEmail" type="text" class="SmallText" id="CompanyVerifyEmail" value="" size="32">
* </td>
<td><div align="right">ATOL Number:</div></td>
<td><input name="CompanyAtol" type="text" ID="CompanyAtol" class="SmallText" value="" size="10">
Leave blank if not a member</td>
</tr>
<tr valign="baseline" class="SmallText">
<td align="right" nowrap> </td>
<td colspan="3"> </td>
<td><div align="right"></div></td>
<td> </td>
</tr>
<tr valign="baseline" class="SmallText">
<td colspan="6" align="right" nowrap><div align="center">
* Indicates a mandatory field<a href="index.asp"><br>
</a></div></td>
</tr>
<tr valign="baseline" class="SmallText">
<td colspan="6" align="right" nowrap><div align="center">You
have read and accepted our <a href="termsandconditions.asp" target="_blank">terms
and conditions</a>
<input type="checkbox" name="checkbox" ID="termsandconditionsconf" value="checkbox">
</div></td>
</tr>
<tr valign="baseline" class="SmallText">
<td colspan="6" align="right" nowrap> <div align="center">
<input type="submit" class="LinkButton" value="Submit">
</div></td>
</tr>
</table>
<div align="center"> </div>
<div align="center">
<input type="hidden" name="MM_insert" value="form1">
</div>
</form></td>
</tr>
</table>
</td>
</tr>
</table>
<a href="index.asp"><br>
</a><br> </td>
</tr>
</table>
<div align="center">
<!--#include file="includes/footer_inc.asp" -->
</div>
<div align="center"> </div>
</body>
</html>
<%
rsSignUp.Close()
Set rsSignUp = Nothing
%>
Replies
Replied 04 May 2004 19:27:55
04 May 2004 19:27:55 Georgio Sfakiotakis replied:
Argghhh...
I know what the problem is - I already have an instance of yy_checkform running in an Include so the two sections of Javascript are clashing.
It works fine now as I've removed the other one.
Georgio
I know what the problem is - I already have an instance of yy_checkform running in an Include so the two sections of Javascript are clashing.
It works fine now as I've removed the other one.
Georgio