The form (form.htm) posts a value from a text box (id='first_name') into a script (test.php) that checks the data entered. The script takes an array of required fields from a config file (config.php) and uses these to validate the data that comes from form.htm.
If the required fields ($required) are not filled in then an error message is displayed. If they are then a 'Thank You' message is displayed.
My problem is with the following script:
<?php
require_once("config.php");
if ($required)
{
$require = explode(",",$required);
for($n=0; $n<count($require); $n++);
{
$field = $require[$n];
if(!$_POST[$field])
{
print $msg['required'];
}
else
{
print 'Thank You';
}
}
}
?>
Regardless of what is entered on the form, the error message is displayed. However if i replace if(!$_POST[[B]$field[/B]]) with if(!$_POST[[B]'first_name'[/B]])...which is the name of the required form field...the script works perfectly.
Is there a problem with the way I am trying to access the $field variable with $_POST?
Sorry if its unclear :o
Thanks for your help,
JameZ ;)