I am having a problem particularly with trying to validate an array of quantities from a form. This (bad) code is on the validation page and is validated against a seperate functions page.
$quant = $_POST['quan'];
require_once ('Function.php');
$valid = TRUE;
if (isset ($_POST['submit'])) {
foreach($_POST as $key=>$value) {
$$key = $value;
}
$valid = $fn = checkLength($fname, 1, 40);
$valid = $bus = checkLength($UserBusinessname, 1, 40);
$valid = $tel = checkLength($Telephone, 1, 40);
$em = checkEmail($email);
$valid = $valid && $em;
$cntquan = count($_POST['SessItemID']);
for ($g = 0; $g<$cntquan; $g++){
$valid = $qn = checkLength($quant[$g], 1, 5);
}
if ($valid) {//do things like update database etc
else
if (!$valid) //show the form again with highlighted text etc.
I know that all the functions work. I know that the quantities are correct, as I have echoed the variables to check. When the quantity count is in this position, it validates only one of the fields, I think! but not the name, e-mail, etc. However, if it is in any other location within the script, it does not do anything. However the name, e-mail, etc. do validate. I am obviously messing this up, but cannot see the reason. Then my eyes glaze over ! I am using a checklength function here, but could easily be isDigits to check for numbers. I would prefer not to start all over. By the way, the variable is being passed from the form field as an array created by naming the quantity field name='quan[]'. I need to keep this way of passing the data. So, if we can just focus on this code that would be brilliant. Any help would be appreciated.