Forum Replies Created
- AuthorPosts
Abbas
ParticipantHi Ally
I modified it as you mentioned, and the code is now working properly
I am grateful to you, and very happy with this support
Thank you very much
AbbasAbbas
ParticipantI 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 ErrorAny advice?
Abbas
ParticipantUpdate:
Thee code snippet for the second requirement works properly.
I made a small change to the code and it works for me.
I changed:
if ($total > 100)
to
if ($total != 100)And it works properly
Very grateful to you
Hope you help me restrict the number of options selected
Abbas
ParticipantI also modified the code by changing the IDs, but unfortunately when I press the submit button the condition does not work and the total is not checked if it is equal to 100 or not
This is the code I modified the IDs and added to Code Snippets:
add_filter(‘quform_post_validate_141’, function (array $result, Quform_Form $form) {
$ids = array(‘141_11’, ‘141_19’, ‘141_29’, ‘141_40’, ‘141_50′,’141_60′,’141_70′,’141_150’);
$total = 0;foreach ($ids as $id) {
$element = $form->getElement(“quform_$id”);if ($element instanceof Quform_Element_Field && !$element->isEmpty()) {
$total += (int) $element->getValue();
}
}if ($total > 100) {
$result = array(
‘type’ => ‘error’,
‘error’ => array(
‘enabled’ => true,
‘title’ => ”,
‘content’ => ‘Total goal importance ratio cannot exceed 100’
)
);
}return $result;
}, 10, 2);Any advice?
Abbas
ParticipantFirst of all, I would like to thank you very much for your help, and I apologize for my poor English.
It seems that the idea did not get across correctly.
The code that you put works if the verification is works on one option box that contains several items, but in my form, each option box contains only one item, meaning that each option box has a different ID, which means that there is a need to create an array for verification according to my simple understanding.
- This reply was modified 2 months, 2 weeks ago by
Abbas.
Abbas
ParticipantThanks a lot, the code works great.
- This reply was modified 2 months, 2 weeks ago by
- AuthorPosts