Possible Duplicate:
Check if multiple strings are empty
today i got this answer here on stackoverflow:
<input type="text" name="required[first_name]" />
<input type="text" name="required[last_name]" />
...
$required = $_POST['required'];
foreach ($required as $req) {
$req = trim($req);
if (empty($req))
echo 'gotcha!';
}
This is ok, but what if someone change
name="required[first_name]"
To
name=""
Then i will have some data missing in further code (i use form to send submited data to email). How to fix this?
Yes, someone can change the html that submits to your code. So you have to check for the existence of everything you want to have in the code that handles the form. Lots of beginners want to automate that away by looping through $_POST or $_GET. And they almost always miss something or end up with code just as complicated, but harder to read, than just checking each input you want.