With that code and the hidden fields deleted from the form, it does not work.
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.
<?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>
OK, but I need a URL to see if the code is throwing console errors.
So MktoForms2 is being called before it is loaded?
What to do?
forms2.min.js creates the MktoForms2 object.
So any refs to MktoForms2 need to be after that <script> loads.
Thanks. I moved it down below the form into the footer and it works!
Great! If you could mark one of my answers (maybe the last one w/code) as Correct...