Re-submit a form on button click with cookied user | Community
Skip to main content
January 3, 2019
Question

Re-submit a form on button click with cookied user

  • January 3, 2019
  • 1 reply
  • 6154 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
Level 10
January 3, 2019

Please edit the post and use the Advanced Editor's syntax highlighter to make the code readable:

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

It also sounds like you need to read these blog posts:

Auto-submitting a form for Known Visitors

Marketo Forms Patterns: The “Not You?” session regen link

January 3, 2019

I can't seem to find any documentation on that particular known visitor editor

Is there a way to add an ID to {{form.Button:default=Auto-submit}}?

SanfordWhiteman
Level 10
January 3, 2019

Doesn't look like you've read my response yet, so post back when you have, thanks.