Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @j0111

    I checked the last code shared in the previous thread and it seems there was either a slight mistake or misunderstanding on our end which lead to code glitch. So let me make sure: the error defined in this code should show up in any of following cases:

    – if both email and phone fields are not provided
    – if one of them (either email or phone) is not provided

    In other words, it should act as if both fields are required, right?

    If so, please edit the code and make small change in it. In this line (I’m assuming you used email-1 and phone-1 fields in it):

    if ( empty( $submitted_data['email-1'] ) && empty( $submitted_data['phone-1'] ) ) {

    replace the

    &&

    with

    ||

    so the line would be

    if ( empty( $submitted_data['email-1'] ) || empty( $submitted_data['phone-1'] ) ) {

    The difference here is the logical operator. In the code originally there was AND operator used, meaning that both these fields would have to be empty to trigger the error and if just one of them would have something entered – error would not show up.

    The change makes it an OR operator, so if both or one of these fields (any of them) will be empty, error will show up.

    Additionally, in this case I’d also suggest setting both these fields to “required” directly in the form (this doesn’t affect he code but will let you display additional validation message right below the field; will mark the field as required and will provide additional submission prevention).

    Also just in case, double-check if form ID is correct in both

    if ( $form_id != 2871 ) {

    these lines (there are two of them in code, both have to be set to the same form ID!).

    With above changes applied to the code (note: I also changed error message in the code on my end) and form, I tested the it on my test setup and it seems to be working just fine.

    Both fields empty:

    https://app.screencast.com/ZKDnB4WdX5EHy

    Phone field empty only:

    https://app.screencast.com/xPIZrwdl9Xx0k

    Email field empty only:

    https://app.screencast.com/Re4J976azT2c5

    Best regards,
    Adam

    Thread Starter j0111

    (@j0111)

    I’m trying to get at least one of the two fields filled in (phone and email). So the initial assumption was correct, if both fields are empty show an error. The form-id matches the one in the form ($form_id != 663). I’m still seeing the form submitting unfortunately, have also tried changing field validation and required or not as well.

    Thread Starter j0111

    (@j0111)

    Attaching the code that I have at the moment

    https://justpaste.it/4swai

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @j0111,

    I’m trying to get at least one of the two fields filled in (phone and email). So the initial assumption was correct, if both fields are empty show an error. T

    Then the code that you have provided is correct. I tested the code in my test site with your form export and I can confirm it works out of the box. Thats the form will only get submitted if either phone or email field is filled.

    Sounds like there is a conflict on your website. To start with do you have a staging site?

    If yes, would recommend you to disable all the plugins except Forminator and switch to a default WP theme and then check whether the submission works fine or not?

    The above test should help in ruling out what might be causing a conflict. Please do check and let us know how that goes.

    Best Regards,

    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @j0111 ,

    We haven’t heard from you for some time now, so it looks like you don’t require our further assistance.

    Feel free to re-open this topic if needed.

    Kind regards
    Kasia

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Issue prevent form submission with mu plugin’ is closed to new replies.