1. Fabrik 3.7 is now available. This version contains critical security updates, please update as soon as possible. Please remember to backup your site before updating, we also recommend testing your updates on development sites if possible.
  2. We had to restore the site around midday (CST) on Wed 7/26 from a backup approximately 8 hours old. So a few posts in the forums were lost. You may want to check to see if you need to re-post anything.

validation with condition OR

Discussion in 'Standard Support' started by enzo2016, Jul 8, 2017.

  1. enzo2016

    enzo2016 Member

    Level: Standard
    Hi,
    a form includes two elements with validation notempty. I would need that at least one of them is not empty. So if one (or both of them) is full then is ok, but if both of them are empty, then the validation should avoid that.
    I wrote the following code into the condition box for both of them:

    Code (Text):

    return '{table___element}' == 2 || '{table___element}' == 1;
    I tested it, but if I don't fill both of elements, then no validation is shown. How can I solve?

    Thanks,
    Enzo
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I would just do it with a PHP validation on both elements, that does ...

    return !(empty($formModel->formData['table___element1'] && empty($formModel->formData['table___element2']);

    -- hugh
     
    enzo2016 likes this.
  3. enzo2016

    enzo2016 Member

    Level: Standard
    Thanks for the code. If I don't fill both of the two elements, then the following error appears: 0 syntax error, unexpected ';'

    By deleting the ; (semicolon) from the code, it appears: 0 syntax error, unexpected end of file.


    -- Enzo
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Ooops, typo ...

    Code (Text):

    return !(empty($formModel->formData['table___element1']) && empty($formModel->formData['table___element2']));
     
    That's the problem with writing code of the top of one's head with lots of brackets, easy to lose count.

    -- hugh
     
    enzo2016 likes this.
  5. enzo2016

    enzo2016 Member

    Level: Standard
    Thanks. Both of the elements have a php validation. If one of these elements has for example also a isemail validation, how could this further validation be activated only if this element was filled?
    Example: the form includes 'element 1' and 'element 2' with this php validation. If the user fills only element 1, but element 2 has also an isemail validation. How could this validation (of element 2) be activated only if element 2 is filled?

    Thanks,

    Enzo
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Standard
    The email validiation has an option "Allow empty".
     
    enzo2016 likes this.
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Yup, that should have the desired effect.

    Sent from my HTC6545LVW using Tapatalk
     

Share This Page