SOLVED

Marketo form : How to pass custom values before submitting the form?

Go to solution
JayNGravel
Level 1

Marketo form : How to pass custom values before submitting the form?

Hi All,

We are using custom fields in Marketo form ( CustomFieldA, CustomFieldB)
CustomFieldA assigned single checkbox and CustomFieldB assigned multiple checkboxes 
Like below imageCheckboxes.png

I would like to submit the form  as CustomFieldB = NULL (empty the field) if user checks only CustomFieldA and not CustomFieldB

Here is my code but it is not working. Please let me know how to make this work.

$(document).ready(function() {
	MktoForms2.whenReady(function(form) {
		form.onSubmit(function(form) {
			var vals = form.vals();
			var giveaway = vals.CustomFieldA;
			var assets = vals.CustomFieldB;
			if(giveaway == "yes" && typeof assets === "undefined"){	
				form.setValues({"CustomFieldB":"NULL"});
			}else if(giveaway == "no" && assets != ""){
				form.setValues({"CustomFieldA":"NULL"});
			}
		});
	});
});



1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form : How to pass custom values before submitting the form?

Two problems here:

 

  1. (severity: fatal) You need to have a hidden NULL option. I wrote an extensive blog post on this a long time ago.
  2. (severity: unknown) You have a possible race condition. $document.ready() firing doesn’t necessarily mean the forms library has been loaded.  Depends on how how you’re loading the library.  If you’re injecting it via GTM, for example, you have a race condition. If it’s just a regular <script> tag in the page you’re fine.

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form : How to pass custom values before submitting the form?

Two problems here:

 

  1. (severity: fatal) You need to have a hidden NULL option. I wrote an extensive blog post on this a long time ago.
  2. (severity: unknown) You have a possible race condition. $document.ready() firing doesn’t necessarily mean the forms library has been loaded.  Depends on how how you’re loading the library.  If you’re injecting it via GTM, for example, you have a race condition. If it’s just a regular <script> tag in the page you’re fine.