I currently have this for the forms :
[html]
<form action="?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Title: <input type="text" name="title" value="NewPage"/><br />
Pagename: <input type="text" name="page" value="NewPage"/><br />
Members : <input type="radio" name="memb" value="0">Yes
<input type="radio" checked="checked" name="memb" value="1">No<br />
Admin : <input type="radio" name="admin" value="0">Yes
<input type="radio" checked="checked" name="admin" value="1">No<br />
<input type="submit" />
</form>
[/html]
And I want to use a php script to use the input only how can I effieciently loop trough all the forms and check if their not empty or containing just a space.
(later on I might add much more forms so I dont want to use like 6-8 ifs xD
You can loop through $_POST but it's probably best to check each before you use it.
You could set the name of each input to (for example):
[html]name="blah[]"[/html]which when submitted would be automatically place all values into an array.
Then just use
[php]foreach($_POST['blah'] as $bleh){
if ($bleh == NULL){
//blah
}else{
//bleh
}
}[/php]
Blah.
[QUOTE=RobZ1337;16888866]You could set the name of each input to (for example):
[html]name="blah[]"[/html]which when submitted would be automatically place all values into an array.
Then just use
[php]foreach($_POST['blah'] as $bleh){
if ($bleh == NULL){
//blah
}else{
//bleh
}
}[/php]
Blah.[/QUOTE]
If you must do it that way you could at least name them so you know which input you're using.
[html]name="blah[name]"[/html]
Also, use empty() instead of comparing to null.
Also keep in mind when using empty() variables containing '0' will return true.
Something I always forget :<
Isn't using blah[] pretty much just foreaching $_POST?
[QUOTE='-[ Fizzadar ]-;16901206']Isn't using blah[] pretty much just foreaching $_POST?[/QUOTE]
Basically yes, but then again no. Because you could still be able to name some forms "name" "password" "other_crap_that_i_dont_need_to_go_through" etc.
It would still ONLY run through the ones with blah[whatever] as name.
Another way to do such, maybe not the best way but Maybe easier to understand could be this...
[php]
if(isset($_POST['form']))
{
if(!empty($_POST['field1']) || !empty($_POST['field2']))
{
echo "Nice";
}
else
{
echo "Left shit empty";
}
}
[/php]
[QUOTE=h2ooooooo;16902387]Basically yes, but then again no. Because you could still be able to name some forms "name" "password" "other_crap_that_i_dont_need_to_go_through" etc.
It would still ONLY run through the ones with blah[whatever] as name.[/QUOTE]
Yeah, I thought he was checking all of them anyway... confused myself. Anyway just foreach and die/break/exit depending on what ya want.
Sorry, you need to Log In to post a reply to this thread.