SOLVED

Change Consent Language on Form Based on Country Selection

Go to solution
Liz_Nguyen1
Level 3

We are testing marketo form embed on non-marketo pages. We have our consent language as a rich text field on the form.

How would we dynamically change the text of the consent language based on the Country field selection someone selects on the form? I looked at visibility rules for the rich text box, but could not figure out how to make it so if County = XXX, show new text. Default text will be visible and only change based on country selection..

 

2 ACCEPTED SOLUTIONS
SanfordWhiteman
Level 10 - Community Moderator

You can’t switch content in the same Rich Text area, but you can create multiple Rich Text areas and then apply Visibility Rules to each so only one is shown at a time.

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Except this code does not work. onChange is not a function property of a Marketo form object, among other errors.

 

I assume the snippet was generated by a machine that doesn’t understand Marketo forms. Such content is not allowed here on the community.

 

While you can use JavaScript to manage HTML content in a Rich Text (provided the JS code is correct) there’s really no reason to go down that road here as it breaks your ability to use the Rich Text editor. It’s not the “better way” for that reason. Only if you had a very large number of language variants would this become easier to manage.

View solution in original post

3 REPLIES 3
NiharikaGoyal
Level 4

⚠️  This post has been edited by a moderator for accuracy.
It’s our responsibility as a community to not provide AI-hallucinated and/or untested answers.

 

Hi @Liz_Nguyen1 Either you can use the visibility rule by creating separate rich text editor or better way if there are multiple countries then you can use the JS to show separate text of consent on basis of countries instead of creating separate multiple rich text fields. You have to add consent-text class in consent language rich text field. Here is the example of JS just for reference:

<script>
MktoForms2.whenReady(function(form) {
form.onChange(function(values) {
var country = values.values['Country']; // Replace 'Country' with your actual Marketo field API name
var consentText = document.querySelector('.consent-text');

if (consentText) {
if (country === "Germany") {
consentText.innerHTML = "<p>This is the GDPR consent text for Germany.</p>";
} else if (country === "USA") {
consentText.innerHTML = "<p>This is the consent text for USA.</p>";
} else {
consentText.innerHTML = "<p>This is the default consent text.</p>";
}
}
});

});
</script>

Hope that would helpful!!

Thanks!!

SanfordWhiteman
Level 10 - Community Moderator

Except this code does not work. onChange is not a function property of a Marketo form object, among other errors.

 

I assume the snippet was generated by a machine that doesn’t understand Marketo forms. Such content is not allowed here on the community.

 

While you can use JavaScript to manage HTML content in a Rich Text (provided the JS code is correct) there’s really no reason to go down that road here as it breaks your ability to use the Rich Text editor. It’s not the “better way” for that reason. Only if you had a very large number of language variants would this become easier to manage.

SanfordWhiteman
Level 10 - Community Moderator

You can’t switch content in the same Rich Text area, but you can create multiple Rich Text areas and then apply Visibility Rules to each so only one is shown at a time.