SOLVED

Re: Possible to Block Form Submissions?

Go to solution
Alexis_D_Alba1
Level 5

Possible to Block Form Submissions?

Hi there,

We have a unique situation ----when a lead selects a specific option on one of our forms,

the submit button will drive to a dedicated landing page. We do not want this to count as a form submission because these leads are not opting into anything and adding them as new leads would not be valuable.  Is it possible to prevent this click from counting as a "fills out form" activity?

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Possible to Block Form Submissions?

Demo/code: MktoForms2 :: Conditionally Bypass Submit

In the example, if you enter "Alexis" as your First Name, then form submission to Marketo is bypassed and you go straight to another URL.

(Note I use onSubmit as opposed to onValidate because it plays better with 3rd-party validation plugins. Lately I have seen some bad problems at clients with competing copy-and-pasted form event listeners, by the way, each one erroneously expecting that it's the only plugin. I have to write some guidelines about this issue when I have a chance.)

View solution in original post

9 REPLIES 9
SanfordWhiteman
Level 10 - Community Moderator

Re: Possible to Block Form Submissions?

Sure, very simple.  Just to be clear: the same form is also used for other form submissions that you do want to count, right?  So the "non-submit submit" only applies when certain values are selected.

Alexis_D_Alba1
Level 5

Re: Possible to Block Form Submissions?

Thank you! and Sanford Whiteman​ that's correct.  We do want the form submission to count if option A and B are selected. But if option C is selected we do not want the submission to count.

SanfordWhiteman
Level 10 - Community Moderator

Re: Possible to Block Form Submissions?

Demo/code: MktoForms2 :: Conditionally Bypass Submit

In the example, if you enter "Alexis" as your First Name, then form submission to Marketo is bypassed and you go straight to another URL.

(Note I use onSubmit as opposed to onValidate because it plays better with 3rd-party validation plugins. Lately I have seen some bad problems at clients with competing copy-and-pasted form event listeners, by the way, each one erroneously expecting that it's the only plugin. I have to write some guidelines about this issue when I have a chance.)

Anonymous
Not applicable

Re: Possible to Block Form Submissions?

Hi Sanford- thanks for the help on this. Would the same apply for a scenario in which you wanted to bypass the submit function if a certain radio button was checked? Ideally we would have the same CTA change to a different text value if the radio button was selected, leading to a URL other than the on form submission redirect.

<script>MktoForms2.loadForm("//app-ab07.marketo.com", "920-LJZ-738", 1914);

MktoForms2.whenReady(function(form) {

  

    form.onSubmit(function(form) {

        if (form.getValues()['mktoRadio_10503_2'] == ':checked') {

            form.submittable(false);

            document.location.href = "http://www.google.com";

        }

    });

});

</script>

SanfordWhiteman
Level 10 - Community Moderator

Re: Possible to Block Form Submissions?

You can do what you describe, but that isn't the way vals works with radio buttons.

You'll get an object like

{

     leadInterest: "How to sell ads in my email.",

     leadgoals: "Simplify my email ad operations.",

     FirstName: "Sanford",

     LastName: "Testor01"

}

so you'd check

if (form.getValues()['leadInterest'] == 'How to sell ads in my email.') {

     ...

}

Anonymous
Not applicable

Re: Possible to Block Form Submissions?

Hi Sanford- Thanks for the help on this! To improve the user flow I would like to change the submit button text from "Submit" to "Get the full story" when the leadInterest is equal to 'Why am I getting ads in my email'.

I've tried to put this in the same function a few different ways but it does not seem to be working. Is this possible?

SanfordWhiteman
Level 10 - Community Moderator

Re: Possible to Block Form Submissions?

It's possible but not in the onSubmit. By definition the onSubmit fires after you've pressed the button, so you can't change the inner text of the button at that point (well, you could, but it would look mighty strange).

In order to change the submit button based on user selections you'd have to listen for underlying HTML element events like change, input, and click (though if you heavily customize your form with other plugins, these will no longer work and you'll have to use the events fired by the plugin/s).

Anonymous
Not applicable

Re: Possible to Block Form Submissions?

You can write javascript using Forms 2.0 to simply 'redirect' to the desired landing page if those 'specific' values are selected. Rest all submissions should go fine as usual. You can use form.onValidate call.

Rajesh

Alexis_D_Alba1
Level 5

Re: Possible to Block Form Submissions?

This is great! thank you for your help.