Re: $_POST

From: Date: Mon, 17 Jan 2005 08:52:07 +0000
Subject: Re: $_POST
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-206521@lists.php.net to get a copy of this message
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.

« previous php.general (#206521) next »