Menu
I have a form that is built in html and then sent to a validation form in php. Everything works great with a pop up box if a field is left empty on the form. But some people have been putting in space bar spaces into the fields and the form still submits. How can I get the form to submit only if there are actual characters in it rather than allowing space bar spaces?
Is this a php issue or something I work into the html page?
Thank you for your help!!
[code=php]
if (strlen($_POST['dd']) > 0 ) {
...
}
[/code]
[code=php]
if (strlen(trim($_POST['dd'])) > 0 ) {
...
}
[/code]
[code=php]
if (ereg('^s*$', $formVariable)) {
//what to do if only spaces
} else {
//what to do if not only spaces
}[/code]
<input name='firstname' type='text' size='50' maxlength='50' value='<?PHP echo ($firstname) ?>' />
<?PHP if (!$firstname)
echo " First Name is Required.";
?>[/QUOTE]
if (ereg('^s*$', $formVariable)) {
//what to do if only spaces
} else {
//what to do if not only spaces
} [/QUOTE]
[code=php]
<input name='firstname' type='text' size='50' maxlength='50' value='<?PHP echo ($firstname) ?>' />
<?PHP if (ereg('^s*$', $firstname)) {
echo " First Name is Required.";
}
?> [/code]
<script 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 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>[/QUOTE]
<form name="RMAForm" id="RMAform" action="RMAValidation.php" method="post" onsubmit="MM_validateForm('firstname','','R','lastname','','R','street','','R','city','','R','zip','','R','ZIP','','NisNum','phone','','RisNum','email','','RisEmail','prodName','','R','prodCode','','R','ZIP','','RisNum','orderDate','','R','returnReason','','R');return document.MM_returnValue">[/QUOTE]
<table>
<tr>
<td ALIGN="left" VALIGN="top" WIDTH="750"><?PHP
@extract($_POST);
?>
<table cellpadding='0' cellspacing='0' border='0' class='formTable'>
<tr>
<td colspan='3' class='header'><h2>RMA - Return Mechandise Authorization Form</h2></td>
</tr>
<tr>
<td colspan="2"><br>
Please verify that the below information is complete and accurate.<br></td>
</tr>
<td width="116"><form name='RMAForm' id='RMAform' action='RMAprocess.php' method='post' >
<tr>
<td colspan='2' class='formsectionHeading'>Request Type</td>
</tr>
<tr>
<?PHP
if ($requestType == 'exchange'){
?>
<td class='formLeftColumn'>Exchange:</td>
<td width='418' class='formRightColumn'><input name='requestType' type='radio' value='exchange' checked />
</td>
</tr>
<tr>
<td class='formLeftColumn'> Refund:</td>
<td class='formRightColumn'><input name='requestType' type='radio' value='refund' />
</td>
</tr>
<?PHP } elseif ($requestType == 'refund'){ ?>
<td class='formLeftColumn'>Exchange:</td>
<td width='418' class='formRightColumn'><input name='requestType' type='radio' value='exchange' />
</td>
</tr>
<tr>
<td class='formLeftColumn'> Refund:</td>
<td class='formRightColumn'><input name='requestType' type='radio' value='refund' checked />
</td>
</tr>
<?PHP } ?>
<tr>
<td colspan='2' class='formsectionHeading' > Contact Information</td>
</tr>
<tr>
<td class='formLeftColumn'> First Name:</td>
<td class='formRightColumn' ><input name='firstname' type='text' size='50' maxlength='50' value='<?PHP echo ($firstname) ?>' />
<?PHP if (ereg('^s*$', $firstname)) {
echo " First Name is Required.";
}
?>
</td>
</tr>...etc.[/QUOTE]
[CODE]<script language="JavaScript" type="text/javascript">
<!--
function openNewWindow(URLtoOpen, windowName, windowFeatures) { newWindow=window.open(URLtoOpen, windowName, windowFeatures); }
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
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_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
[/CODE]
[CODE]<table>
<tr>
<td ALIGN="left" VALIGN="top" WIDTH="750"><?PHP
@extract($_POST);
?>
<table cellpadding='0' cellspacing='0' border='0' class='formTable'>
<tr>
<td colspan='3' class='header'><h2>RMA - Return Mechandise Authorization Form</h2></td>
</tr>
<tr>
<td colspan="2"><br>
Please verify that the below information is complete and accurate.<br></td>
</tr>
<td width="116"><form name='RMAForm' id='RMAform' action='RMAprocess.php' method='post' >
<tr>
<td colspan='2' class='formsectionHeading'>Request Type</td>
</tr>
<tr>
<?PHP
if ($requestType == 'exchange'){
?>
<td class='formLeftColumn'>Exchange:</td>
<td width='418' class='formRightColumn'><input name='requestType' type='radio' value='exchange' checked />
</td>
</tr>
<tr>
<td class='formLeftColumn'> Refund:</td>
<td class='formRightColumn'><input name='requestType' type='radio' value='refund' />
</td>
</tr>
<?PHP } elseif ($requestType == 'refund'){ ?>
<td class='formLeftColumn'>Exchange:</td>
<td width='418' class='formRightColumn'><input name='requestType' type='radio' value='exchange' />
</td>
</tr>
<tr>
<td class='formLeftColumn'> Refund:</td>
<td class='formRightColumn'><input name='requestType' type='radio' value='refund' checked />
</td>
</tr>
<?PHP } ?>
<tr>
<td colspan='2' class='formsectionHeading' > Contact Information</td>
</tr>
<tr>
<td class='formLeftColumn'> First Name:</td>
<td class='formRightColumn' ><input name='firstname' type='text' size='50' maxlength='50' value='<?PHP echo ($firstname) ?>' />
<?PHP if (ereg('^s*$', $firstname)) {
echo " First Name is Required.";
}
?>
</td>
</tr>
<tr>
<td class='formLeftColumn'> Last Name:</td>
<td class='formRightColumn' ><input name='lastname' type='text' size='50' maxlength='50' value='<?PHP echo ($lastname)?>'>
<?PHP if (!$lastname)
echo " Last Name is Required.";
$error=1;
?>
</td>
</tr>
<tr>
<td class='formLeftColumn'> Organization:</td>
<td class='formRightColumn' ><input name='organization' type='text' size='50' maxlength='50' value='<?PHP echo($organization)?>'>
</td>
<tr>
<td class='formLeftColumn'> Street Address:</td>
<td class='formRightColumn' ><input name='street' type='text' size='50' maxlength='50' value='<?PHP echo($street)?>'>
<?PHP if (!$street)
echo " Street Address is Required.";
$error=1;
?>
</td>
<tr>
<td class='formLeftColumn'> City:</td>
<td class='formRightColumn' ><input name='city' type='text' size='25' maxlength='25' value='<?PHP echo($city)?>'>
<?PHP if (!$city)
echo " City is Required.";?>
</td>
</tr>....and more of the form code.[/CODE]
[code=php]
$error=1;[/code]
[code=php]
Every place this occurs:
<?PHP if (!$lastname)
echo " Last Name is Required.";
$error=1;
?>
Replace it with this (change the variables to match):
<?PHP if (ereg('^s*$', $lastname) || !$lastname) {
echo " Last Name is Required.";
$error = 1;
}
?>[/code]
[code=php]
<?PHP if ((strpos('^s*$', $lastname)!==false) || (!$lastname)) {
echo " Last Name is Required.";
$error = 1;
}
?>[/code]
0.1.9 — BETA 5.28