SOLVED

Defining form value via script

Go to solution
Anonymous
Not applicable

Defining form value via script

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. 
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Defining form value via script

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; 
}); 
}); 


 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Re: Defining form value via script

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"});
Anonymous
Not applicable

Re: Defining form value via script

SanfordWhiteman
Level 10 - Community Moderator

Re: Defining form value via script

@Chris Y Rather than setValues() (nor its alias vals()), you want addHiddenFields().
Anonymous
Not applicable

Re: Defining form value via script

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; 
}); 
}); 


 
Anonymous
Not applicable

Re: Defining form value via script

Thanks Sanford and Haven!