• Resolved Serge

    (@gholem)


    Hi guys,

    Apologies if this was already asked and has received answers, I couldn’t find it on a quick look.

    I want to prevent users from sending the form if certain conditions are met. For example:

    1. User needs to make a selection between Yes and No.
    2. If No is selected, they can simply send the form
    3. If Yes is selected, they can’t sent the form.

    And this is how the sortcodes look:

    [select* enquiry-condition first_as_label "-- Please select --" "Yes" "No"]
    
    [group condition-yes inline]
    Please go to this page instead: /somepage/
    [/group]

    The problem is that once the user makes a selection (either Yes or No) they submit the form; I only want them to be able to send it if No is selected.

    I hope I haven’t missed this in the documentation.

    Appreciate your help greatly.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jules Colle

    (@jules-colle)

    I think there are a couple of approaches you could take.

    1. (requires some PHP knowledge), you could write a custom validation function that invalidates the select field if you select “Yes” https://contactform7.com/2015/03/28/custom-validation/

    2. (most simple) change your code to [select* enquiry-condition first_as_label "Yes" "No"]

    3. Create an additional group with the submit button inside, and only show this group when “No” is selected

    Thread Starter Serge

    (@gholem)

    Hi Jules,

    Thanks very much for taking the time to answer my question.

    I’m not sure whether I understood correctly your #2 suggestion; is it not what I already use more or less?

    My snippet:

    [select* enquiry-condition first_as_label "-- Please select --" "Yes" "No"]

    Your suggestion:

    [select* enquiry-condition first_as_label "Yes" "No"]

    Unfortunately #3 did not work, as CF7 keeps showing the Submit button no matter what.

    I’ll do some reading for your suggestion #1.

    Thanks again,
    Serge

    Plugin Author Jules Colle

    (@jules-colle)

    Yes, #1 is definitely the way to go.

    This plugin is primarily designed to make a form more compact and only show the relevant fields in smaller chunks instead of overwhelming the user with a gigantic form.

    What you are looking for is indeed custom validation = a field must have a valid input before you can submit the form. In this case the valid input is any value apart from “Yes”. So custom validation is definitely the way to go here.

    Thread Starter Serge

    (@gholem)

    Thanks Jules,

    I really appreciate your answers.

    Off to documentation reading for me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to prevent the form from being sent if a condition is met’ is closed to new replies.