/    Sign up×
Community /Pin to ProfileBookmark

form using php – validation problem

Hello all,

I’ve been working on developing a form for a customer that uses php throughout. I’m still pretty new to javascript and i’m using Dreamweaver to plugin the validation scripting for me automatically. So far i haven’t been able to get it working. ideally, i’d like to prompt an alert box if the fields aren’t filled in and another one if the terms and conditions check box isn’t checked.

The function DoTheCheck() that checks the terms and conditions checkbox is working, but the other validatoin (that dreamweaver created for me) isn’t working. I can leave all the fields blank and the form will still process…. what am i missing?

[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″ />
<title>Untitled Document</title>
<script type=”text/JavaScript”>
<!–

function DoTheCheck() {
if (document.form2.accept.checked == false) {
alert(‘You must agree to the terms and conditions’);
return false;
} else
return true;
}

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 MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors=”,args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!=””) {
if (test.indexOf(‘isEmail’)!=-1) { p=val.indexOf(‘@’);
if (p<1 || p==(val.length-1)) errors+=’- ‘+nm+’ must contain an e-mail address.n’;
} else if (test!=’R’) { num = parseFloat(val);
if (isNaN(val)) errors+=’- ‘+nm+’ must contain a number.n’;
if (test.indexOf(‘inRange’) != -1) { p=test.indexOf(‘:’);
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+=’- ‘+nm+’ must contain a number between ‘+min+’ and ‘+max+’.n’;
} } } else if (test.charAt(0) == ‘R’) errors += ‘- ‘+nm+’ is required.n’; }
} if (errors) alert(‘The following error(s) occurred:n’+errors);
document.MM_returnValue = (errors == ”);
}

//–>
</script>
</head>

<body>

<form name=”form2″ method=”POST” action=”<?php echo $_SERVER[‘PHP_SELF’] ?>”>
<table border=”0″ cellspacing=”0″ cellpadding=”2″>
<tr>
<td colspan=”3″><strong>Company Information</strong></td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td>Company Name:</td>
<td><input type=”text” name=”cName” />
</td>
<td><input type=”hidden” name=”ediUser” value=”<?php echo $_COOKIE[‘mainstreetComp’];?>” /></td>
</tr>
<tr>
<td>Phone Number:</td>
<td>(<input type=”text” name=”cPhone1″ size=”3″ maxlength=”3″ />) <input type=”text” name=”cPhone2″ size=”3″ maxlength=”3″ />&nbsp;-&nbsp;<input type=”text” name=”cPhone3″ size=”4″ maxlength=”4″ />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Fax Number:</td>
<td>(<input type=”text” name=”faxNumber1″ size=”3″ maxlength=”3″ />)<input type=”text” name=”faxNumber2″ size=”3″ maxlength=”3″ />&nbsp;-&nbsp;<input type=”text” name=”faxNumber3″ size=”4″ maxlength=”4″ />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Company Address:</td>
<td><input type=”text” name=”companyAddress” />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>City:</td>
<td><input type=”text” name=”city” />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>State:</td>
<td><input type=”text” name=”state” size=”3″ maxlength=”2″ />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Zip Code:</td>
<td><input type=”text” name=”zipCode” size=”6″ maxlength=”5″ />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Website Address (optional):</td>
<td><input type=”text” name=”website” />
</td>
<td><input type=”hidden” name=”otherUrl” /></td>
</tr>
</tr>
<tr>
<td>Fed Tax ID:</td>
<td><input type=”text” name=”fedTaxId1″ size=”3″ maxlength=”2″ />’. ‘ – ‘. ‘<input type=”text” name=”fedTaxId2″ size=”8″ maxlength=”7″ />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Owner’s Name:</td>
<td><input type=”text” name=”ownersName” />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Person in charge of EDI/Glaxis&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
(optional):</td>
<td><input type=”text” name=”eCommerceManager” />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Email Address:</td>
<td><input type=”text” name=”emailAddress” />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td>What service form do you need to submit?<br />(Froms will appear below)</td>
<td><select name=”serviceForm” onChange=”document.form2.submit();”>
<option>Select One</option>
<option>EDI</option>
<option>Glaxis</option>
<option>EDI and Glaxis</option>
</select>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″><strong>EDI Service Request</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>EDI Volume Plan:</td>
<td><input name=”volumePlan” type=”radio” value=”standard volume” checked=”checked” /> Standard Volume<br />
<input name=”volumePlan” type=”radio” value=”low volume” /> Low Volume<br />
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=”#”>What is this?</a></td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td>How would you like to pay your monthly<br />fees?&nbsp;&nbsp;&nbsp;</td>
<td><input type=”radio” value=”E.F.T.” name=”paymentOptions” checked=”checked” />E.F.T. (Direct Debit)<br />
<input type=”radio” value=”Send a Check” name=”paymentOptions” />Send a Check</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=”#”>Why choose E.F.T.?</a></td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″><strong>Glaxis Service Request</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Previous Lynx Dispatch Number:</td>
<td><input type=”text” name=”lynxDispatch” size=”10″ maxlength=”9″/></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=”#”>What is this?</a></td>
</tr>
<tr>
<td>Requested Start Date (mm/dd/yyyy):</td>
<td><input type=”text” name=”liveDateMonth” size=”2″ maxlength=”2″/>/<input type=”text” name=”liveDateDay” size=”2″ maxlength=”2″/>/<input type=”text” name=”liveDateYear” size=”4″ maxlength=”4″/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Would you like to setup PPG online ordering?</td>
<td><input name=”ppgOnlineOrdering” value=”Yes” type=”radio” checked=”checked” />Yes &nbsp;&nbsp;&nbsp;
<input name=”ppgOnlineOrdering” value=”No” type=”radio” />No
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=”#”>What is this?</a></td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td colspan=”3″><strong>Additional Comments</strong></td>
</tr>
<tr>
<td colspan=”2″><textarea name=”comments” cols=”55″ rows=”5″></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td colspan=”3″><input type=”checkbox” name=”accept” value=”I agree” />I agree to the <a href=”#”>Terms of Service</a></td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td colspan=”3″ valign=”top”><input type=”submit” name=”submit2″ value=”Send Form” onclick=”return(DoTheCheck()); addon.value=’go’;MM_validateForm(‘cName’,”,’R’,’cPhone1′,”,’RisNum’,’cPhone2′,”,’RisNum’,’cPhone3′,”,’RisNum’,’faxNumber1′,”,’RisNum’,’faxNumber2′,”,’RisNum’,’faxNumber3′,”,’RisNum’,’companyAddress’,”,’R’,’city’,”,’R’,’state’,”,’R’,’zipCode’,”,’RisNum’,’fedTaxId1′,”,’RisNum’,’fedTaxId2′,”,’RisNum’,’ownersName’,”,’R’,’emailAddress’,”,’RisEmail’,’lynxDispatch’,”,’RisNum’);return document.MM_returnValue” /></td>
</tr>
</table>
</form>

</body>
</html>
[/code]

any replies are greatly appreciated! Thanks for helping out a newbie!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyJan 30.2009 — This is pretty bogus:

onclick="return(DoTheCheck()); addon.value='go';MM_validateForm('cName','','R','cPhone1','','RisNum','cPhone2','','RisNum','cPhone3','','RisNum','faxNumber1','','RisNum','faxNumber2','','RisNum','faxNumber3','','RisNum','companyAddress','','R','city','','R','state','','R','zipCode','','RisNum','fedTaxId1','','RisNum','fedTaxId2','','RisNum','ownersName','','R','emailAddress','','RisEmail','lynxDispatch','','RisNum');return document.MM_returnValue"

In the first place, your initial [B]return[/B] is preventing the rest of that code (the DreamWeaver part) from executing at all. Try this:

onclick="if(!DoTheCheck()) return false; addon.value='go';MM_validateForm('cName','','R','cPhone1','','RisNum','cPhone2','','RisNum','cPhone3','','RisNum','faxNumber1','','RisNum','faxNumber2','','RisNum','faxNumber3','','RisNum','companyAddress','','R','city','','R','state','','R','zipCode','','RisNum','fedTaxId1','','RisNum','fedTaxId2','','RisNum','ownersName','','R','emailAddress','','RisEmail','lynxDispatch','','RisNum'); return document.MM_returnValue;"
×

Success!

Help @mainstwebguy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...