Post-map-repost Marketo Referral Form | Community
Skip to main content
New Participant
December 8, 2022
Question

Post-map-repost Marketo Referral Form

  • December 8, 2022
  • 2 replies
  • 3091 views

I'm trying to submit a form twice via Marketo. The first submit should post all of the original data. The second submit should remap some of the form values. For some reason the form just gets stuck at "Please wait" when submitting. No errors - nothing. Can someone help me?

 

 

 

 

<script src="/js/forms2/js/forms2.min.js"></script> <form id="mktoForm_id" style="max-width:100%;"></form> <script> MktoForms2.loadForm("/", "munchkinId", formId); MktoForms2.whenReady(function(form) { var originalValues; form.onSubmit(function(form) { originalValues = form.getValues(); // stores original values in variable }) form.onSuccess(function(vals, thankYouURL) { this.onSuccess(); // clear onSuccess for 2nd run this.setValues({ 'FirstName': originalValues['referralFirstName'], 'LastName': originalValues['referralLastName'], 'Email': originalValues['referralEmail'], 'Company': originalValues['referralCompanyName'], 'referralFirstName': '', 'referralLastName': '', 'referralEmail': '', 'referralCompanyName': '', 'referralPhoneNumber': '' }); // remaps values for second submit this.submit(); // submits it again }.bind(form)); }); </script>

 

 

 

 

 

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

2 replies

SanfordWhiteman
New Participant
December 8, 2022

Like Darshil says, please don’t use this code. Anything on jsFiddle is way outdated and all the latest snippets are on my CodePen.

 

In any case, the problem here is that you’re trying to submit the form (the second submit, on behalf of the referral) with required fields empty. That won’t work, so it fails silently.

 

 

Darshil_Shah1
Community Manager
December 8, 2022

Well, you're missing setting the '_mkt_trk' to null during the 2nd form post in the onSuccess method (and a separate form for the person being referred won't be submitted).

 

See my comments in the script below!

 

<script src="/js/forms2/js/forms2.min.js"></script> 
<form id="mktoForm_1347" style="max-width:100%;"></form>

<script>
  MktoForms2.loadForm("/", "720-FTJ-659", 1347);

  MktoForms2.whenReady(function(form) {
    var originalValues;

    form.onSubmit(function(form) {
      originalValues = form.getValues(); // stores original values in variable
    })

    form.onSuccess(function(vals, thankYouURL) {
      this.onSuccess(); // clear onSuccess for 2nd run

      this.setValues({
        'FirstName': originalValues['referralFirstName'],
        'LastName': originalValues['referralLastName'],
        'Email': originalValues['referralEmail'],
        'Company': originalValues['referralCompanyName'],
        'referralFirstName': '', // These fields are required on the form but have no values assigned
        'referralLastName': '',
        'referralEmail': '',
        'referralCompanyName': '',
        'referralPhoneNumber': '',
        '_mkt_trk': '' //Clearing cookies before form-submit is critical for the referrer form setup
      }); // remaps values for second submit

      this.submit(); // submits it again
    }.bind(form));

  });
</script>

 

Also, I'd recommend using Sandy's newer and improved MktoForms2 :: Referral v2.0.2 script instead of this older version.

 

DavidMa39Author
New Participant
December 9, 2022

Thank you very much for providing some insight here.

 

Unfortunately the form still does not post even when values are assigned to required fields & the "_mkt_trk" is set to null on the second post. Any other ideas? Is there any way to post errors to the console so I'm not just blindly guessing at what's wrong?

 

Also, is something so inherently wrong with the code that I should be using Sandy's newer version? I'll end up implementing the new code regardless, but just curious?

Darshil_Shah1
Community Manager
December 9, 2022

The newer version has a relatively smoother UX, i.e., unlike the previous version, the end user doesn't see on the web page that the form is being submitted twice. To give you more idea, with the older version, after the 1st submission, the data gets populated on the form for the 2nd form as per the script, and then it gets submitted again. All of this happens in front of the end-user (giving a sense of form being frozen for a very short moment after the 1st form post). However, with the V2, the form submission is much smoother, and the end user won't even notice that the form is being submitted twice.