• Resolved lucari

    (@lucari)


    Hello and thanks for your plugin.
    I have a simple form with name, surname, email and interest groups, already created in Mailchimp:
    [ redundant link removed ]
    I’d like to redirect to a Thank you page only if the user picks “Group 1”, how can I do something like that?

    Here is the code of my form:

    <label>First Name*</label>
    <input type="text" name="FNAME" placeholder="first name"
        required="">
    <br><br>
    <label>Last Name*</label>
    <input type="text" name="LNAME" placeholder="last name" required="">
    <br><br>
    <label>E-mail address* 
    		<input type="email" name="EMAIL" placeholder="E-mail address" required />
    </label>
    <br><br>
    Groups of interest (pick at least one)*<br>
    <label>
    <input name="INTERESTS[e81db3f978][]" type="checkbox" value="9f456824c8"> <span>Group 1</span>
    </label>
    <label>
    <input name="INTERESTS[e81db3f978][]" type="checkbox" value="bce4fef6f2"> <span>Group 2</span>
    </label>
    <br><br>
    <input type="submit" value="Subscribe" />
    
    <script>
    /* Makes checkboxes required - at least one per group */
        jQuery('.mc4wp-form').on('change', function(evt) {
            let checkboxFields = jQuery(this).find('[name^="INTERESTS"]');
            let checkedCount = checkboxFields.filter(':checked').length;
            checkboxFields.prop('required', checkedCount == 0);
        });
    </script>

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @lucari Do not use short links in these forums, that has been abused in the past and is expanded when found. I have expanded yours.

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey @lucari,

    Thanks for reaching out to us.

    Our plugin does not have such a feature. The page will refresh to submit the data first and then based on the settings for “Redirect to URL” it will either redirect to a specific page or simply refresh and stay on the existing page.

    Thread Starter lucari

    (@lucari)

    @hchouhan thank you,
    actually I saw that the main settings allow only one redirect rule for any form and any condition, but I was wondering if it is possible to use JavaScript form events like

    mc4wp.forms.on('success', function() {
    var checkBox = document.querySelectorAll("[value=9f456824c8]");
      if (checkBox.checked == true){
    window.location.replace("https://www.pinkarman.com/thank-you/");
    }
    });

    which is not working

    Plugin Contributor Lap

    (@lapzor)

    I think that code should probably work, but you should NOT setup redirect in the settings at the same time, else the settings redirect will overwrite it.

    Other than that, I would start by debugging/trying just this:

    mc4wp.forms.on('success', function() {
    window.location.href("https://www.pinkarman.com/thank-you/");
    });

    and add the conditions later, if this is confirmed to work.

    Hope that helps. If you have any questions, please let me know!

    Thread Starter lucari

    (@lucari)

    @lapzor thanks a lot!
    The basic Javascript redirect works great,
    without the plugin settings redirection, and with just a little tweak in the code:

    window.location.href = "https://www.pinkarman.com/thank-you/";
    (I had to change the brackets to an equals sign)

    But the conditions are not working: I fear that, as soon as the “success” event is triggered, the form is cleared, so the checkbox is not checked anymore.
    Have you got any ideas?

    Plugin Contributor Lap

    (@lapzor)

    Ah, you may very well be right about that!

    The form data is available to the success function.

    Here an example that dumps the form data to console, just for the form with the ID 15.

    <script>
    mc4wp.forms.on('15.success', function(form, data) {
       console.log(form);
       console.log(data);
    });
    </script>

    Hope that helps. If you have any questions, please let me know!

    Thread Starter lucari

    (@lucari)

    Thank you so much @lapzor , I got it working!
    in the end I used this code

    mc4wp.forms.on('success', function(form, data) {
      if (JSON.stringify(data).includes('bce4fef6f2')){ /*'bce4fef6f2' is the value of the checkbox that allows redirect */
        	window.location.href = "https://www.pinkarman.com/thank-you/";
      }
    Plugin Contributor Lap

    (@lapzor)

    Nice! Thanks for sharing the code.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘redirect depending on interest group’ is closed to new replies.