SOLVED

Re: Insert php variable into marketo form hidden field

Go to solution
Anonymous
Not applicable

Re: Insert php variable into marketo form hidden field

With that code and the hidden fields deleted from the form, it does not work.

SanfordWhiteman
Level 10 - Community Moderator

Re: Insert php variable into marketo form hidden field

Need a lot more than "does not work." Post a link to a URL. Also note I have no idea what your actual PHP var names are.

Anonymous
Not applicable

Re: Insert php variable into marketo form hidden field

<?php

$mkto_camp_name = (get_field_object("marketo_campaign_name")['value']);

$mkto_camp_content = (get_field_object("marketo_campaign_content")['value']);

?>

<script> 

var marketoVars = { 

   campaign:  "<?php echo $mkto_camp_name ?>",

   content:  "<?php echo $mkto_camp_content ?>"

MktoForms2.whenReady(function(form){ 

form.addHiddenFields({ 

   Campaign_Name__c : marketoVars.campaign,

   Campaign_Content__c : marketoVars.content

}); 

});

</script>

SanfordWhiteman
Level 10 - Community Moderator

Re: Insert php variable into marketo form hidden field

OK, but I need a URL to see if the code is throwing console errors.

Anonymous
Not applicable

Re: Insert php variable into marketo form hidden field

Screen Shot 2016-11-23 at 2.31.04 PM.png

So MktoForms2 is being called before it is loaded?

What to do?

SanfordWhiteman
Level 10 - Community Moderator

Re: Insert php variable into marketo form hidden field

forms2.min.js creates the MktoForms2 object.

So any refs to MktoForms2 need to be after that <script> loads.

Anonymous
Not applicable

Re: Insert php variable into marketo form hidden field

Thanks. I moved it down below the form into the footer and it works!

SanfordWhiteman
Level 10 - Community Moderator

Re: Insert php variable into marketo form hidden field

Great! If you could mark one of my answers (maybe the last one w/code) as Correct...