|
Posted by Adam Hubscher on 01/17/05 10:52
Andrew Maxwell wrote:
> When you submit something, and you want to make sure that the user
> inputs all of the info, is there an easier way to do it than this:
>
> if ((!$_POST[name]) || !$_POST[pass]) || (!$_POST[blah]))
> {
> etc.....
> }
>
> is there an easy way to check if all of the varibles have data in them?
>
> ~Andrew
Well, you could use a simple foreach:
foreach ($_POST as $key => $value){
if($value === '') { print("You must fill in all the values");}
else{continue;}
}
I'm not sure if empty($value); would work, but its worth a try.
You could however use it, within the foreach by doing:
empty($_POST[$key]);
(if $key = name, it would test $_POST[$name] whether it is empty or not).
http://us2.php.net/manual/en/function.empty.php
I would assume that empty() would work in this case eitherway, and is
most likely your best bet.
However, within this function it may also be smart to include a few form
validation rules for the security of your form as well.
Navigation:
[Reply to this message]
|