I realize this is a question that has been asked before ("Cannot use [] for reading"), but I'm having trouble wrapping my head around the answer and how to fix my particular function.
function check_required_checkbox($checkbox_name, $error, $is_multiple_checkboxes)
{
global $error_msgs;
if ($is_multiple_checkboxes == true)
{
if (!isset($_POST[$checkbox_name][]))
{
$error_msgs[] = $error;
}
else if ($is_multiple_checkboxes == false)
{
if (!isset($_POST[$checkbox_name]))
{
$error_msgs[] = $error;
}
}
}
The problem line is 6, !isset($_POST[$checkbox_name][]), and I'm not understanding how the correct way I should write it. I saw instances of using brackets but !isset($_POST[{$checkbox_name}][]) isn't correct either.
When I have multiple checkboxes that use name="radda[]", I want my function to check that all of the checkboxes with a specific name are checked, and if not, add $error to the $error_msgs[] array.
EDIT: I discussed with the department that was requesting a rewrite of the old form. Instead of using checkboxes, I switched it to a list of all of the borrower's rights and responsibilities, and then used a radio button below the list to ask the user to select "yes" or "no" on whether they read the list. Then I made it required to select "yes" or "no" and added validation that if "no" was selected, they wouldn't be able to submit the application. This was far easier than trying to make a bunch of checkboxes required. I do appreciate the help that everyone offered though.
name="radda[]"then you will recieve an array called$_POST['radda']how many occurances depends upon how many of the checkboxes where actually checked. Unchecked checkboxes are not returned in the arrayif (isset($_POST['radda']) < 8)) { $error_msgs[] = $error; }?if (isset($_POST['radda']))check how may have been checked usingif (count($_POST['radda']) < 8) {but remember there will only be an item in the array IF a checkbox is checked. If only 2 checkboxes are checked you will only get 2 items in the array