Picklist value to store in Marketo Form | Community
Skip to main content
Level 5
October 14, 2020
Solved

Picklist value to store in Marketo Form

  • October 14, 2020
  • 2 replies
  • 4896 views

Business need to store Display Value as well as Stored Value in Marketo Field-1 and 2. Is it possible in Marketo? what will be the logic in such case. In the form, Field Type is Select. and allowing only one field to enable for display in Marketo Form.

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

Easily done with a little JS.

 

submitOptionText specifies those picklists (selects) whose option text (in addition to option value) is interesting to you.

 

valueField is the name of the visible field, textField is the hidden field that'll contain the option text.

 

 

MktoForms2.whenReady(function (mktoForm) { const submitOptionText = [ { valueField: "Country", textField: "CountryFriendlyNameField" } ]; /* NO NEED TO TOUCH BELOW THIS LINE! */ const formEl = mktoForm.getFormElem()[0]; mktoForm.onSubmit(function (mktoForm) { const currentValues = mktoForm.getValues(), newValues = {}; submitOptionText.forEach(function (fieldDesc) { const selectEl = formEl.querySelector( "select[name='" + fieldDesc.valueField + "']" ), indexEl = selectEl[selectEl.selectedIndex]; newValues[fieldDesc.textField] = indexEl.textContent; }); mktoForm.addHiddenFields(newValues); }); });

 

 

 

 

2 replies

Michael_Florin-2
Level 10
October 14, 2020

Let me try to understand. You have a select field on your form - let's say "Country" - and you have value pairs that look like this in your advanced editor:

 

Deutschland|DE
Österreich|AT
Schweiz|CH

 

And now you want to save "Deutschland" to field A, and "DE" to field B? 

No, don't think that's possible. You can created a "Change Data Value" Flow Step though on a Smart Campaign that listens to form submits that write "Deutschland" into field A, should the value in your select field be "DE". Like that:

Katja_Keesom
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
October 14, 2020

That would indeed be a good alternative solution.

However, I do think it can be done with the second field hidden on the form and some JS to update the value based on what is selected in the visible field. Someone with sufficient JS skills should be able to help you there. I am sure @sanfordwhiteman can advise here.

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
October 14, 2020

Easily done with a little JS.

 

submitOptionText specifies those picklists (selects) whose option text (in addition to option value) is interesting to you.

 

valueField is the name of the visible field, textField is the hidden field that'll contain the option text.

 

 

MktoForms2.whenReady(function (mktoForm) { const submitOptionText = [ { valueField: "Country", textField: "CountryFriendlyNameField" } ]; /* NO NEED TO TOUCH BELOW THIS LINE! */ const formEl = mktoForm.getFormElem()[0]; mktoForm.onSubmit(function (mktoForm) { const currentValues = mktoForm.getValues(), newValues = {}; submitOptionText.forEach(function (fieldDesc) { const selectEl = formEl.querySelector( "select[name='" + fieldDesc.valueField + "']" ), indexEl = selectEl[selectEl.selectedIndex]; newValues[fieldDesc.textField] = indexEl.textContent; }); mktoForm.addHiddenFields(newValues); }); });

 

 

 

 

Level 5
October 15, 2020

Hi @sanfordwhiteman 

I have implemented the given JS but it is not working. Can you please help me to replace correct value in the suggested JS script for the given two Field.

 

Field-1 = Country (REST API- country)

Field-2 = Country Code (REST API- countrycode)

Field-2 is hidden in the form. And I am using REST API name in the JS script. and Autofill as Use Default Value. And Form Prefill disable.

Display Value Stored Value
United States US
Canada CA

 

In this example, what will be the submitOptionText, valueField and textField.

 

Jay
SanfordWhiteman
Level 10
October 15, 2020

Form fields use SOAP field names, not REST.