SOLVED

changing value of marketo form before submit

Go to solution
dondmcg
Level 2

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.
Tags (1)
1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

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.

View solution in original post

24 REPLIES 24
dondmcg
Level 2

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
Level 10 - Community Moderator

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).

dondmcg
Level 2

"although note that will not overwrite an existing value (should there already be one in Marketo for some reason)"

Do you mean if the user already exists and has entered a value for that field in the db it will not be over written by the blank string?

SanfordWhiteman
Level 10 - Community Moderator

Do you mean if the user already exists and has entered a value for that field in the db it will not be over written by the blank string?

Correct.