Checkbox required

Home Forums Quform WordPress Checkbox required

This topic is: resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #23314
    moe
    Participant

    Hi

    We have did a solution earlier to make checkbox required if the fields are empty.
    We just want to add small thing on it:
    if the one or all of the fields are filled then user can’t click on checkbox

    is that possible ?

    function my_checkbox_required($form)
    {
        $checkbox = $form->getElement('iphorm_11_64');
    
        if ($checkbox && $checkbox->isEmpty()) {
            $checkIfEmpty = array('iphorm_11_10', 'iphorm_11_11', 'iphorm_11_12', 'iphorm_11_13', 'iphorm_11_14', 'iphorm_11_15', 'iphorm_11_30', 'iphorm_11_16', 'iphorm_11_17', 'iphorm_11_18', 'iphorm_11_19', 'iphorm_11_20', 'iphorm_11_21', 'iphorm_11_22', 'iphorm_11_23', 'iphorm_11_44', 'iphorm_11_46', 'iphorm_11_40', 'iphorm_11_52', 'iphorm_11_50', 'iphorm_11_46', 'iphorm_11_56', 'iphorm_11_62', 'iphorm_11_63');
            $hasValue = false;
    
            foreach ($checkIfEmpty as $elementId) {
                $element = $form->getElement($elementId);
    
                if ($element && ! $element->isEmpty()) {
                    $hasValue = true;
                    break;
                }
            }
    
            if (!$hasValue) {
                $checkbox->setRequired(true);
            }
        }
    }
    • This topic was modified 6 years, 4 months ago by Ally. Reason: Code formatting
    #23395
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #23399
    moe
    Participant

    Thanks Ally

    But it didn’t works
    you can see the page her http://www.revas.dk/toemnings-bestilling/

    Am still able to click on checkbox even i filled the fields

    #23448
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #23475
    moe
    Participant

    Thanks but still didn’t work :/
    am still able to click on check box even the fields are filled

    #23497
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #23498
    moe
    Participant

    Hi Ally

    It’s worked perfect

    thanks a lot

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy