note 44211 deleted from reserved.variables by aidan
| From: | aidan@php.net | Date: | Mon, 13 Sep 2004 07:37:25 +0000 |
| Subject: | note 44211 deleted from reserved.variables by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76585@lists.php.net to get a copy of this message | ||
Note Submitter: info at gjbdesign dot com
----
if you want a good, short way to check to see if all a form's fields have been filled in, then
you can check it this way.
<?php
function GJB_Form_Check($GJB_form_vars){
/*test that each variable has a value*/
foreach ($GJB_form_vars as $key => $value){
if (!isset($key) || empty($value)){
return false;
}
}
return true;
}
if(isset($cmdPost){/*prevents code below from running unless form is submitted*/
if(!GJB_Form_Check($_POST)){
echo"Not all fields are filled out.";/*Not filled out*/
}else{
echo"All ok";/*All filled out*/
}
}
?>
An example form for this function is as follows:
<form method="post" action="">
<input type="text" name="user"
value="<?=$_POST['user']?>" /><br />
<input type="text" name="pass"
value="<?=$_POST['pass']?>" /><br />
<input type="submit" value="Submit" name="cmdPost" />
</form>