Re: how to check the form filled all
| From: | Chris W | Date: | Mon, 19 Jan 2004 18:28:04 +0000 |
| Subject: | Re: how to check the form filled all | ||
| References: | 1 | Groups: | php.general php.general |
| Request: | Send a blank email to php-general+get-175065@lists.php.net to get a copy of this message | ||
Sungpill Han wrote:
HI, i want to check if the user filled the all inputs in the form. So, I checked NULL and "" with this function in the post receiving script. ------------------------------- function is_filled_out() { // test that each variabl has a value foreach($_POST as $key => $value) { if(is_null($value) || $value="") return false; } return true; } --------------------- but when I submit the form without putting any value, it returns 'true'. what's wrong with my code?It is my understanding (not sure if it is correct though) that if your form has a field named x and the user does not enter any value in that field, there will be no entry for field x in the $_POST array. so your loop should never return false. To see if they entered a value in field X you need to code something like this if(! $_POST['x']){ do what ever you do when they don't fill out a required field; } Chris W