4 Replies Latest reply on Nov 12, 2015 1:19 PM by Tricia Francis

    Check hidden field value before assigning a value.

    Tricia Francis

      We want to use a master form for landing pages hosted on our own site.  We're able to do this and assign campaign ID, assets and the redirect url as needed with the following code:

       

      <script src="//app-sj05.marketo.com/js/forms2/js/forms2.min.js"></script>

      <form id="mktoForm_ourFormID"></form>

      <script>

        MktoForms2.loadForm("//app-sj05.marketo.com", "ourID", ourFormID, function(form) {

        // Set values in hidden fields to determine campaign and asset to serve

        form.vals({

        "Campaign_Id__c":"assignedCampaignID",

        "Campaign_Asset__c":"assignedCampaignAsset"

        });

        // Override master redirect URL set in Marketo

        form.onSuccess(function(values, followUpUrl) {

        location.href = "newRedirectURL";

        // Return false to prevent the submission handler continuing with its own processing

        return false;

        });

        });

      </script>

       

      The next step is to assign the campaign iD only if it's not already included in the referring url.  So I need some sort of if/then statement that looks at the hidden campaign ID to see if there's a value - and assign a value only if there is not.  I'm not a javascript master by any stretch, and I'm not sure what is the best method for the Marketo API.  Can someone help me with this last bit of if/else?