Conditional Return: false on Marketo Forms | Community
Skip to main content
Lucho_Soto
New Participant
August 23, 2018
Solved

Conditional Return: false on Marketo Forms

  • August 23, 2018
  • 1 reply
  • 3549 views

I have the following custom form code that displays a thank you message on submit without reloading the page. I'd like to take this a step further and make this conditional. If the field C_Service_Reason is submitted with the value Training, then I don't want the thank you message to display, and instead want them to be redirected to an external URL on success.

Any help with this would be much appreciated, thank you!

<script ></script>

                    <form id="mktoForm_2338"></form>

                    <script>MktoForms2.loadForm("//app-sj04.marketo.com", "980-GBD-747", 2338);</script>

                    <script>

                        MktoForms2.whenReady(function (form){

                            //Add an onSuccess handler

                            form.onSuccess(function(values, followUpUrl){

                                dataLayer.push({

                                    'event': 'contacttest',

                                    'eventCallback' : function () {        

                                        form.getFormElem().hide();

                                        document.getElementById('contacttest').style.visibility = 'visible';

                                    }

                                });

                                return false;

                            });

                        })

                    </script>

                    <div id="contacttest" style="visibility:hidden; text-align: center;">Thank you for your interest! A Hatch expert will be in touch soon.</div>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

if ( <condition> ) {

  <condition is true action>

} else {

  <condition is false action>

}

i.e.

if ( values.C_Service_Reason == "Training" ) {

  // do dataLayer stuff

  return false;

} else {

  // do something else, or do nothing and the regular Thank You URL will load

}

1 reply

SanfordWhiteman
New Participant
August 23, 2018

What have you tried?  It's a basic JS conditional.

Check the value of values.C_Service_Reason and proceed accordingly.

Lucho_Soto
New Participant
August 23, 2018

I very limited JS knowledge, so coming up with the structure of a JS conditional would be beyond me. However, if you could help me with what that would look like for this scenario, I'm familiar enough with JS to adapt the code to other URLs/fields/field values.

Thanks again.

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
August 23, 2018

if ( <condition> ) {

  <condition is true action>

} else {

  <condition is false action>

}

i.e.

if ( values.C_Service_Reason == "Training" ) {

  // do dataLayer stuff

  return false;

} else {

  // do something else, or do nothing and the regular Thank You URL will load

}