SOLVED

changing value of marketo form before submit

Go to solution
Highlighted
Level 1

changing value of marketo form before submit

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

Accepted Solutions
Highlighted
Level 10 - Community Moderator

Re: changing value of marketo form before submit

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

11 REPLIES 11
Highlighted
Level 10 - Community Moderator

Re: changing value of marketo form before submit

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

Highlighted
Level 1

Re: changing value of marketo form before submit

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.

Highlighted
Level 10 - Community Moderator

Re: changing value of marketo form before submit

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

Highlighted
Level 1

Re: changing value of marketo form before submit

"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?

Highlighted
Level 10 - Community Moderator

Re: changing value of marketo form before submit


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.

Highlighted
Level 1

Re: changing value of marketo form before submit

Actually if I just send an ajax call with the custom object instead of using the API to submit that might work easier no? Or would I run into the same problem from server side validation?

Highlighted
Level 1

Re: changing value of marketo form before submit

Is there a way to strip off any masking and other validation from any field coming through the loop to be able to edit its value to be the desired string?

Highlighted
Level 1

Re: changing value of marketo form before submit

So if your solution is to remove the mask can that be done programmatically?

My question is how do I strip personal information from the values onSubmit (preferably replacing with a string)?

I just found your blog https://blog.teknkl.com/clearing-lead-fields-when-no-value-submitted/ this is not the same case I have but similar.

Highlighted
Level 10 - Community Moderator

Re: changing value of marketo form before submit

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