SOLVED

Using multiple form conditions to determine thank you page - GDPR

Go to solution
Tyria_Saul
Level 2

Hi all,

I'm building our first ever subscription center for GDPR and I'm trying to get my form to send users to different thank you pages based on their choices. For example, they can opt out of email and/or opt out of cookie tracking. If they opt-in to email and opt-out of tracking we need to send them to a certain landing page with the no tracking url on it. If they opt-out of email but opt-into tracking we need to send them to a different thank you page, etc. There are four different thank you pages in total. I can't figure out how to do this in Advanced Thank you. I can set a single condition, like send them to page A if they choose email opt out, but I can't figure out how to send them to page A if they choose email and date opt-out. Any suggestions would be greatly appreciated!

How are others doing this in their subscription centers? By the way I'm using both Marketo landing pages and forms.

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

MktoForms2.whenReady(function(form){
  form.onSubmit(function(form){

    var currentValues = form.getValues(),

    fieldsToConsolidate = ["fieldA","fieldB","fieldC"],

    consolidated__c =

      fieldsToConsolidate

        .map(function(field){

          return currentValues[field];

        })

        .join(";");

   form.addHiddenFields({ consolidated__c : consolidated__c });

});

});

Where consolidated__c is the name of your new custom field and fieldA, fieldB, and fieldC are the names you want to put together.

The resulting consolidated__c field will be a semicolon-delimited string (apples;oranges;pumpkins) so needless to say, the values themselves can't contain a semicolon.

View solution in original post

28 REPLIES 28
SanfordWhiteman
Level 10 - Community Moderator

You have to either

  1. use JavaScript to consolidate their choices into a single field in the onSubmit, and use that value in your Advanced Thank You; or
  2. use JavaScript in the onSuccess to choose the Thank You page based on crunching multiple values (do not use the Form Editor to choose the TY in this case)
Tyria_Saul
Level 2

Thanks Sanford! How would I do option 1? I'm just learning the coding piece so I'm not as familiar.

SanfordWhiteman
Level 10 - Community Moderator

MktoForms2.whenReady(function(form){
  form.onSubmit(function(form){

    var currentValues = form.getValues(),

    fieldsToConsolidate = ["fieldA","fieldB","fieldC"],

    consolidated__c =

      fieldsToConsolidate

        .map(function(field){

          return currentValues[field];

        })

        .join(";");

   form.addHiddenFields({ consolidated__c : consolidated__c });

});

});

Where consolidated__c is the name of your new custom field and fieldA, fieldB, and fieldC are the names you want to put together.

The resulting consolidated__c field will be a semicolon-delimited string (apples;oranges;pumpkins) so needless to say, the values themselves can't contain a semicolon.

Michael_McGowan
Level 1

Hi Sanford,

I am trying to use this script but find that it is not consolidating the values and inserting them into the hidden field. The hidden field (mkto_AscentTest_4) is in the form and has string as its data value. Here is the code that I am using.

MktoForms2.whenReady(function(form){

form.onSubmit(function(form){

var currentValues = form.getValues(),

fieldsToConsolidate = ["mkto_AscentTest_1","mkto_AscentTest_2","mkto_AscentTest_3"],

mkto_AscentTest_4 =

fieldsToConsolidate

.map(function(field){

return currentValues[field];

})

.join(";");

form.addHiddenFields({ mkto_AscentTest_4 : mkto_AscentTest_4 });

});

});

Any thoughts?

SanfordWhiteman
Level 10 - Community Moderator

Please provide your URL. The code on its own is fine.

Michael_McGowa1
Level 3

Here is the link to the page​.

SanfordWhiteman
Level 10 - Community Moderator

You're using the wrong field names. The prefix "mkto_" doesn't exist on those fields, and they don't have underscores.

pastedImage_0.png

Michael_McGowa1
Level 3

Thank you Sanford, that worked. However, I am confused on about this. In my instance the field names do have mkto_ in them. Below is a screenshot of the fields in the database.

pastedImage_0.png

And when I go to edit the form, the field names are consistent.

pastedImage_1.png

Is it because I am embedding the code on my site that the names change? Maybe beyond the scope of this thread but curious. As always, thanks for the help.

SanfordWhiteman
Level 10 - Community Moderator

The form fields will be the SOAP field names (as opposed to the friendly names). So export all your fields from Field Management, check the SOAP column, and you'll always be accurate.

Anonymous
Not applicable

Is there a way to do this without using Marketo forms 2.0? I don't believe I have the right bundle to use the 2.0 editor.

for example, can this be done by embedding this code in <script> </script> tags directly on the landing page?

SanfordWhiteman
Level 10 - Community Moderator

What do you mean by "bundle" exactly?

All Marketo forms are either 1.0 or 2.0. 2.0 is the default for anything after -- well, a long time ago.

Anonymous
Not applicable

Sorry, I meant form editor 2.0. Unlike this picture shown here ​I do not have the option to open the 2.0 editor.

pastedImage_1.png so I can't do much code editing other than CSS

SanfordWhiteman
Level 10 - Community Moderator

That's the way the New Form dialog is expected to look.  Are you saying you can't edit the form after this?

While custom JS behaviors go outside the Form Editor anyway (preferably in an external .js file) it's not practical for you to build this form entirely in JS.

Anonymous
Not applicable

what I want to know is where are you putting this code? Are you embedding between script tags on a landing page, or somewhere on the form editor? If on the form editor, can you show where.

thanks again for your help

SanfordWhiteman
Level 10 - Community Moderator

Custom form JS depends on the forms2.min.js file being loaded first.

Hence, on a 3rd-party site, you'd load custom JS right after the standard form embed code. On a Marketo LP with a named mktoForm element, you'd put your custom JS right before the closing </body> tag (because Marketo LPs will insert the forms2.min.js wherever in the body the form appears).

Anonymous
Not applicable

ah okay, thank you for clarifying, and my apologies if it was obvious. There is one final thing I'm not quite getting.

I am using a Marketo landing page and have included the script to match and consolidate the fields I want. Once that is set up however, where can I actually set up the conditional redirect?

pastedImage_0.png

I can't do it on the form itself because that field isn't created until the form is submitted. (I don't have the option to type in a field that isn't already on the form)

SanfordWhiteman
Level 10 - Community Moderator

You add the field to the form as a Hidden field in Form Editor.

Anonymous
Not applicable

Bringing this back because I have another question about embedding these forms on a non-marketo landing page (our wordpress site). I would like to be able to preserve the hidden-field auto-fill based on fields. How would one include the  MktoForms2.whenReady(function(form) function along with the embed code?

SanfordWhiteman
Level 10 - Community Moderator

You place the custom forms JS in a <script> block directly after the standard embed code.

Anonymous
Not applicable

That's what I did initially but my simple test did not work.

I find that after filling out the embedded form the formredirect field remains NULL (although it updates correctly when on a marketo landing page). Am I missing something? Here's what I've embedded

<script src="//app-sj20.marketo.com/js/forms2/js/forms2.min.js">

</script>

<form id="mktoForm_1232"></form>

<script>MktoForms2.loadForm("//app-sj20.marketo.com", "530-RLQ-870", 1232);</script>

<script>

MktoForms2.whenReady(function(form){

form.onSubmit(function(form){

   form.addHiddenFields({ formredirect : a_different_value)});

});

});

</script>