changing value of marketo form before submit | Community
Skip to main content
New Participant
November 18, 2020
Solved

changing value of marketo form before submit

  • November 18, 2020
  • 1 reply
  • 7007 views

I have to strip out the personal data from marketo forms submitted.  Inside the form.onSubmit I look for names of forms that meet criteria of personal data. If any exist I call the API method form.submittable(false) I make an ajax call to a 3rd party passing the personal data to them and then use a callback to attempt to update the form.vals(newObj) object with "REDACTED" string in place of the personal info and continue submitting the marketo form.

But the form does not submit and though the object newObj has the correct entry for the personal name value pair when I console out the form.vals() the pair has "null" as the value instead of "REDACTED". I also use form.setValues(newObj) and still see the same.

 

Everything works until the code reaches this block.

// submit the marketo form const submitMarketo = function () { console.log('submit this to marketo!!!'); console.log(newObj); // returns the new values with redacted info ie: "personal_phone": "REDACTED" form.setValues(newObj); // attempts to set the new values with redacted info console.log(form.vals()); // returns the values with personal info as null ie: "personal_phone": null console.log(form); // returns the correct form form.submittable(true).submit(); // appears to do nothing, network panel does not show call to marketo, // if I comment out the form.setValues(newObj); the submit goes through }
 
It seems the null value for the adjusted personal data being set as null is causing the marketo form submission to fail before the package is sent.  What is the correct way to alter data like this?
 
I have a loop that runs through all the values, when one is personal data I do this:
form.setValues({[key]: "REDACTED"}); console.log(form.getValues());
And every time the key is assigned the value of null NOT the string I am passing to it.
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

You can remove the literal mask on a String, yes — but with a Select there's no "mask." It's just the implicit restriction to the options.

 

The only way to have a <select> dropdown presented to the user and be able to write additional values to that same field, i.e. values that don't appear in the options, is to have a String selected in Form Editor, but then turn it into a <select> on the client side using JS.

1 reply

SanfordWhiteman
New Participant
November 18, 2020

If you're using an input mask on this field (as the Phone field does by default), you can't set it to a string that doesn't fit the mask! Same for other types of validation.

 

You need to remove the mask before setting it to "REDACTED."

dondmcgAuthor
New Participant
November 18, 2020

It is actually a select so the element does not have a value or masking.  But a selectedIndex.  But I am substituting the value in just the object so I did not think that would factor in.  But maybe because "redacted" is not an option that is why this is happening but the field accepts an empty string. So to do what I want to do I could create a new hidden input for all the personal info values (such as "personal_phone_alt": "REDACTED") and pass an empty string for the value of personal_phone.

SanfordWhiteman
New Participant
November 18, 2020

Then it does have validation. A Select is explicitly restrictive, as the value has to be one of the options! "REDACTED" would have to be an option.

 

Yes, you can pass an empty string for the value of the field, if the empty string is in the list, although note that will not overwrite an existing value (should there already be one in Marketo for some reason).