Hi everyone,
I have an errors function that I need to dynamically apply the name from a series of checkboxes and I am a little but stuck, nesting/escaping the code inside a foreach loop.
Here is my foreach loop before I nest it.
if(isset($_POST['Rating']))
{
foreach($_POST['Rating'] as $key => $value)
{
$_SESSION['Rating'][$key] = $value;
}
}
And a sample of the errors function looks like this....
$rate = errors('Rating', 'This is a required field.');
But since these are an array of dynamic checkboxes (and are required) they will be named as such.
Rating[0]
Rating[1]
Rating[2]
and so on.
So I tried to enclose the to code snippets like so...
if(isset($_POST['Rating']))
{
foreach($_POST['Rating'] as $key => $value)
{
$_SESSION['Rating'][$key] = $value;
$rate[$key] = errors('Rating[' . $key . ']', 'This is a required field.');
}
}
But when I print_r the results set is an empty array.
So I am not coding it correctly within the loop.
Where did I go wrong?
As always, I appreciate the guidance,
Regards,
Don