Re: checking for null form fields fails

From: Date: Mon, 06 Aug 2001 19:31:38 +0000
Subject: Re: checking for null form fields fails
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61470@lists.php.net to get a copy of this message
On Mon, 6 Aug 2001 13:56:45 -0500, garman (garman@students.uiuc.edu) wrote: >For all of my HTML forms, I put in some JavaScript to check and make >sure no >fields are left blank. When the forms are processed in PHP, I also >perform a >check to make sure the forms fields aren't null (redundant, I know). > >Anyway, on a form I just made, both JavaScript and PHP think the >form has been >completed, even when the fields haven't been touched. > >The code basically looks like this: > ><head> ><script language="JavaScript"> ><!-- >function VerifyInput () { > if (document.myForm.input.value == "") { > alert ("form not complete"); > return false; > } else { > return true; > } >} >// --> ></script> ></head> > ><form name="myForm" action="myscript.php" method="post" >onSubmit="return > VerifyInput()"> i can't tell if it's just a email formatting thing, but if there's a line break in the onsubmit string it might mess things up. ><input type=text name="input" value="" size=30> ><input type=submit value="submit"> ></form> > >Now, the file "myscript.php" will have something like this: > ><?php >if (!isset ($HTTP_POST_VARS['input'])) { > die ("form not complete. cannot continue."); >} well, if it makes it this far, $input will be set, but the value will be "". try empty() instead of !isset() - Mark

« previous php.general (#61470) next »