1. The 3.8 code for Fabrik is now available on github, in the 'master' branch. If you are familiar with updating Fabrik from github, we would appreciate it if you could test this code on J! 3.8 for us. Once we have some feedback, we'll build a 3.8 release.

validation with two elements, one non-empty

Discussion in 'Community' started by MILORD65, Sep 11, 2017.

  1. MILORD65

    MILORD65 Member

    Level: Community
    Hello,

    I have two éléments on the same form and I want them to be validated only if at least one of them or both is not empty.
    I think it is necessary to use the php validation plugin but I don't find the code to put in condition and in php code.
    Thank for your help

    JP
     
  2. MILORD65

    MILORD65 Member

    Level: Community
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Well, are you talking about using this as the "condition" (which determines if the validation itself should be run), or as the validation itself?

    If it's the validation itself, then don't put it in the Condition, put it in the PHP code box.

    -- hugh
     
  4. MILORD65

    MILORD65 Member

    Level: Community
    Thank you for your reply.
    The problem is that if I put this code in the php code box, the validation fails for both items. If I put it in the condition box nothing happens. What I am trying to do is a validation if at least one of the two elements is filled or both.
    Validation must fail if both elements (A and B) are empty.
    I think this is the same as in the post: http://www.fabrikar.com/forums/index.php?threads/validation-with-condition-or.47055/#post-244942
    I had thought of using the notempty plugin but the post that I found on the forum advises rather the plugin PHP validation.

    JP
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    When you say "the validation fails for both items", what exactly do you mean?

    -- hugh
     
  6. MILORD65

    MILORD65 Member

    Level: Community
    Thank for your reply.
    By "the validation fails for both items", I mean that the text "validation failed" appears in red under the two elements and the text "Some parts of your form have not been filled correctly" on top of the form.
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Right, but does it actually "work" in the sense that if you have one filled in, it doesn't fail?

    -- hugh
     
  8. MILORD65

    MILORD65 Member

    Level: Community
    No, if I have one filled in or both, it doesn't work.

    JPB
     
  9. MILORD65

    MILORD65 Member

    Level: Community
    To try to better explain my problem:
    If in the php validation plugin I put only in PHP code for my two elements A and B:
    PHP:
    return $data != '';
    the validation is done systematically but separately and the message "Some parts of your form have not been properly filled in" is displayed if one of the elements is empty.
    If in addition I put in "condition" of the php validation pluginfor both elements:
    PHP:
    return !(empty($formModel->formData['mytable ___ elementA']) && empty($formModel->formData['mytable ___ elementB']));
    registration does not fail and no message "Some parts of your form have not been properly filled in" if both elements are empty.

    JP
     

Share This Page