Home › Forums › Quform WordPress › Minimum and maximum selected checkboxes › Reply To: Minimum and maximum selected checkboxes
I simulated the code you put in to check the total goals and wrote the following code to check if between 4 and 6 options are selected:
add_filter(‘quform_post_validate_141’, function (array $result, Quform_Form $form) {
$checkboxIds = array(‘141_10’, ‘141_23’, ‘141_34’, ‘141_46’, ‘141_57’, ‘141_68’, ‘141_79’, ‘141_90’, ‘141_101’, ‘141_114’);
$selectedCount = 0;
foreach ($checkboxIds as $id) {
$element = $form->getElement(“quform_$id”);
if ($element instanceof Quform_Element_Checkbox && $element->isChecked()) {
$selectedCount++;
}
}
if ($selectedCount < 4 || $selectedCount > 6) {
$result = array(
‘type’ => ‘error’,
‘error’ => array(
‘enabled’ => true,
‘title’ => ‘Error’,
‘content’ => ‘You must select between 4 and 6 options.’
)
);
}
return $result;
}, 10, 2);
but it appears to error:
There was a problem
Ajax Error
Any advice?