Defining form value via script | Community
Skip to main content
February 17, 2015
Solved

Defining form value via script

  • February 17, 2015
  • 5 replies
  • 2451 views
We are working on our new website which is on drupal. 

We are using a module on the drupal platform to bring over the data from 
our webforms into Marketo. 

We are using one form for all our content with one difference being that we have a different field value for Marketing Detail which we want to populate. This field will drive the separate programs for each peice of content.


Please see script below. I've checked the field api name and it is 
Marketing_Detail__c . Currently the value for Marketing Detail (in this case:fact sheet nuix collector 
suite) is nt coming over to Marketo. So we cannot differenciate one content download from the other.

We want to avoid creating mutiple forms with hidden values for each peice of content.


<script src="//app-sjf.marketo.com/js/forms2/js/forms2.js"></script> 
<form id="mktoForm_2128"></form> 
<script> 
MktoForms2.loadForm("//app-sjf.marketo.com", "957-JZE-399", 2128, 
function(form){ 
form.vals({ "Marketing_Detail__c":"fact sheet nuix collector 
suite"}); 
form.onSuccess(function(values, followUpUrl){ 
location.href = "/download/fact sheet nuix collector suite"; 
return false; 
}); 
}); 
</script> 

Please let me know if you need any more info. 

Regards 
Chris. 
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
Sanford is right

form.addHiddenFields({ "Marketing_Detail__c":"fact sheet nuix collector suite"});

is a better option

Just make sure to remove he original Marketing_Detail__c field.

The method will append a duplicate field
with a new value but the original field with the old value will still remain.

If this form is used elsewhere you may just want to set values using jquery

<script> 
MktoForms2.loadForm("//app-sjf.marketo.com", "957-JZE-399", 2128, 
function(form){

$('input[name="Marketing_Detail__c"]').val("fact sheet nuix collector suite");
form.onSuccess(function(values, followUpUrl){ 
location.href = "/download/fact sheet nuix collector suite"; 
return false; 
}); 
}); 


 

5 replies

February 17, 2015
Hi Chris,

Can you provide a url of the page?

The method to set values is 

.setValues(vals)

Maybe try 
amending

form.vals({ "Marketing_Detail__c":"fact sheet nuix collector suite"}); 
to

form.setValues({ "Marketing_Detail__c":"fact sheet nuix collector suite"});
February 17, 2015
Thanks Haven,

here you go nuix.com/fact-sheet/nuix-collection-fact-sheet
SanfordWhiteman
Level 10
February 17, 2015
@Chris Y Rather than setValues() (nor its alias vals()), you want addHiddenFields().
Accepted solution
February 17, 2015
Sanford is right

form.addHiddenFields({ "Marketing_Detail__c":"fact sheet nuix collector suite"});

is a better option

Just make sure to remove he original Marketing_Detail__c field.

The method will append a duplicate field
with a new value but the original field with the old value will still remain.

If this form is used elsewhere you may just want to set values using jquery

<script> 
MktoForms2.loadForm("//app-sjf.marketo.com", "957-JZE-399", 2128, 
function(form){

$('input[name="Marketing_Detail__c"]').val("fact sheet nuix collector suite");
form.onSuccess(function(values, followUpUrl){ 
location.href = "/download/fact sheet nuix collector suite"; 
return false; 
}); 
}); 


 
February 19, 2015
Thanks Sanford and Haven!