• Hi, I need to redirect to thank you page as answer choose on form.
    Example:
    If answer is B redirect to thank you page Sucess!
    I answer is A redirect to other thank you page.

    This conditional logic for show conversion tag google ads how lead is better (answer b) than others (answer a).
    *but I have 4 kind of answer options that I consider to redirect for a thank you page Sucess or other.

    Is there way to use conditional logic on cf7 form?

    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello @smorici,

    Let’s say you have a form with the ID 123 and a form tag like this:

    [select your-options id:your-options "Option 1" "Option 2" "Option 3"]

    Note the form tag above has the ID your-options. We’ll use this field ID and the Form ID as selectors in the following JavaScript code snippet to redirect the user according to the option selected (you can paste this code at the end of your Form tab content):

    <script type="text/javascript">
      document.addEventListener('wpcf7mailsent', function (event) {
        if ('123' == event.detail.contactFormId) {
          var your_options = document.getElementById("your-options").value;
          if (your_options == "Option 1") {
            location = 'http://contactform7.com/';
          }
          if (your_options == "Option 2") {
            location = 'https://google.com/';
          }
          if (your_options == "Option 3") {
            location = 'https://example.com/';
          }
        }
      }, false)
    </script>

    In the line 3 of the code above you’ll find the form ID 123 that you need to replace with your form ID. The next line has the selector your-options, you need to replace this ID for the one from your select form tag. Finally, you need to create as many IF statements as you have options.

    Best regards,
    Yordan.

    Thread Starter Smorici

    (@smorici)

    Hi, thanks your help!

    I tried your code, but didn´t work.

    On this patch

    var your_options = document.getElementById(“your-options”).value;
    if (your_options == “Option 1”)

    (“your-options”)= a tag of field, ok?
    if (your_options == “option 1”) and “option 1” is a option select of field to redirect page.

    but didn´t work

    • This reply was modified 5 years ago by Smorici.
    Yordan Soares

    (@yordansoares)

    Hello @smorici,

    This code was tested and works.

    Could you please share your Form tab content?

    Please note you need to replace the form ID from 123 to your current form ID.

    Best regards,
    Yordan.

    Thread Starter Smorici

    (@smorici)

    Yes, of course!

    <label>Nome</label>
    [text* text-223 placeholder “qual é seu primeiro nome?”]
    <label>Whatsapp</label>
    [text* whatsapp placeholder “whatsapp (11)99999-9999”]
    <label>Pergunta A?</label>
    [select* p1 include_blank
    “SIM!”
    “NÂO!”
    “Outros”]

    [submit “ENVIAR”]

    *script that you sent me
    document.addEventListener(‘wpcf7mailsent’, function (event) {
    if (‘2802’ == event.detail.contactFormId) {
    var your_options = document.getElementById(“p1”).value;
    if (your_options == “NÂO!”) {
    location = ‘https://mydomain.com/thankyou-no&#8217;;
    }

    • This reply was modified 5 years ago by Smorici.
    • This reply was modified 5 years ago by Smorici.
    • This reply was modified 5 years ago by Smorici.
    • This reply was modified 5 years ago by Smorici.
    • This reply was modified 5 years ago by Smorici.
    • This reply was modified 5 years ago by Smorici.
    • This reply was modified 5 years ago by Smorici.
    Thread Starter Smorici

    (@smorici)

    Hi, can you see my model form?

    Thread Starter Smorici

    (@smorici)

    May can be where I add code? When I tested i added on end tab form after send button.

    But I tought if would be on head or body?

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

The topic ‘Conditional logic to show thank you page’ is closed to new replies.