checking for null form fields fails

From: Date: Mon, 06 Aug 2001 18:56:45 +0000
Subject: checking for null form fields fails
Groups: php.general 
Request: Send a blank email to php-general+get-61465@lists.php.net to get a copy of this message
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()"> <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."); } In all the previous forms I've made, this will catch all uncompleted form fields. However, I made another form in the exact same way, and now both the JavaScript and the PHP checks are failing, i.e. they think something has been entered, when the field has been left blank. In the example above, if the page loaded, then I just pressed the submit button (without even touching the text box), the neither the javascript nor PHP would catch the blank field. Any ideas? Thanks, Matt

« previous php.general (#61465) next »