10 Replies Latest reply on Jan 3, 2019 2:34 PM by Sanford Whiteman

    Re-submit a form on button click with cookied user

    Mark Gill

      Hello,

       

      I am currently integrating Marketo forms to a website. After filling out the form the user is presented with a download button.

       

      The setup:

      JS embeds with custom HTML with a "download" button.

      User fills out the form and is presented with the download button.

      On button click user should receive the asset.

      Assets are hosted on the website, not with Marketo.

      When the user clicks the button the form should submit again in the background and the user receives the asset.

       

       

      Background:

       

      After submitting we are using an additional cookie to perform a lot of frontend swaps and changes

      Once the user fills the form one time they have access to all assets, by clicking the download button on another page it should re-submit the form with the users information, tracking them from page to page (download to download) through form submissions.

       

      The issue I am having is re-submitting the form with the user after the initial form fill.

      The user goes to a new page, they are cookied by Marketo so the form shows the custom HTML download button. When clicking the download button I would like to do a form submission with the cookied users data.

       

      Html:

      MktoForms2.loadForm("//app-----.marketo.com", "910-ISZ----", ----, function(form){
           var thankYouWindow;
           var check = Cookies.get("myCookie");
           var notYou = jQuery('#mktoNotYou');
           var btn = document.getElementById("mktoButton");
           notYou.click(function(){
                Cookies.remove("myCookie");
           });
           if(check === 'unlocked'){
                btn.onclick = function() {
                     thankYouWindow = window.open('');
                     var download = jQuery('.locked').data('download');
                     thankYouWindow.document.location = download;
      
                    // I had hoped
                   //  MktoForms2.whenReady(function (form) {
                  //        form.submit();
                 //    });
                // would work, but doesn't seem to. Even though Marketo has the user cookied in order to show them this button, 
               // I don't think it is pre-filling the form with the users data for re-submission.
      
                }
           } else {
           form.onSuccess(function(values, followUpUrl) {
                jQuery('.marketo').hide();
                jQuery('.locked').text('Download');
                var all = jQuery('.alllock');
                if (all) {
                     jQuery.each(all, function() {
                     jQuery(this).parent().prepend('');
                     this.remove();
                });    
                jQuery(window).scrollTop(0);
                location.reload();
           }
           Cookies.set('myCookie', 'unlocked');
           return false;
           });
           }
      });
      

      Is there a way to re-submit a form outside perhaps saving all the data to a variable and re-populating the form manually and then submitting?