/    Sign up×
Community /Pin to ProfileBookmark

Form being submitted with blank space

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? ?

Maybe I should ask this in the php section or do you think there is a javascrip that will fix this? I am not really sure which way to go with it.

Thank you for your help!!

to post a comment
HTML

4 Comments(s)

Copy linkTweet thisAlerts:
@dtm32236Sep 19.2007 — when you validate, check to see whether the field is empty ("") OR blank (" ")
Copy linkTweet thisAlerts:
@charliewonkanobauthorSep 19.2007 — When it gets to the validate page the field is empty except I can highlight the two spacebar spaces I put in. So I think that it is the (" ") rather than the ("") option.
Copy linkTweet thisAlerts:
@FangSep 19.2007 — php has to check the form and return the same form with errors 'highlighted'.

Having the same functionality using JavaScript is a bonus.
Copy linkTweet thisAlerts:
@charliewonkanobauthorSep 19.2007 — Any Javascript ideas I could try out? This is what I have so far

<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]




and then it passes onto the validation page which is php.
×

Success!

Help @charliewonkanob 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...