Capturing Full URL from Referring Web Page to Form Submit | Community
Skip to main content
Brenda_Denting1
New Participant
September 25, 2020
Solved

Capturing Full URL from Referring Web Page to Form Submit

  • September 25, 2020
  • 1 reply
  • 9589 views

Hello all. I am having a similar issue that others have had regarding capturing referral URL on form submit. We've read a bunch of other threads about this topic and we can't figure out exactly how to apply those instructions to our special circumstance. 

 

We have a custom Wordpress site and we are moving from ContactForm7 to Marketo Forms. Current ContactForm7 captures full referrer URL and includes it in the email alert to sales, which is super helpful information.

 

The behavior I want:

1) User clicks on a product page, then clicks the "request info" button.

2) We want to pass that product page URL to the WordPress landing page with the new Marketo form embedded on it.

3) User submits the form and the URL from the product page gets passed to our unique custom field (Form URL) we created to capture the URL. 

4) Email alert uses the custom field (Form URL). 

 

Questions: 

1) What type of field should the URL field be? String or URL? 

2) Other posts said to create an HTML block and put in the java script. Where does the HTML block go? On the Marketo form (rich text) or the WordPress product page, or the WordPress form landing page? 

3) What is the javascript I would use? 

 

Thanks in advance!! 

Brenda

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

Opps, here is the code (I must have copied the wrong one). 

 

<script> MktoForms2.loadForm("//app-ab37.marketo.com", "525-EAQ-286", 1056, function (form) { form.vals({ "lastFormReferralURL":document.referrer }); }); </script>

OK, that code has exactly the same effect as the code posted above. In fact it's more fragile because the hidden field needs to be added to the form in Form Editor if you use setValues() or vals(). Using addHiddenFields() doesn't require the field to be on the form to begin with.

 

whenReady() adds the value to all forms, while the final argument to loadForm() adds the value to only that form.

 

Other than that, these 2 pieces of code are are not substantively different. They both set the value of a hidden field when a form is ready:

 

#1

MktoForms2.whenReady(function(mktoForm){ mktoForm.addHiddenFields({ lastFormReferrerURL : document.referrer }); });

 

#2

MktoForms2.loadForm("//app-ab37.marketo.com", "525-EAQ-286", 1056, function (form) { form.vals({ "lastFormReferralURL" : document.referrer }); });

 

1 reply

SanfordWhiteman
New Participant
September 26, 2020

1) What type of field should the URL field be? String or URL? 

String.

 


2) Other posts said to create an HTML block and put in the java script. Where does the HTML block go? On the Marketo form (rich text) or the WordPress product page, or the WordPress form landing page? 


I wouldn't recommend putting it in the form, because Marketo recently introduced a bug that makes that much more difficult. it should be a separate <script> on the WP page hosting the form, placed anywhere after the form embed code.

 


3) What is the javascript I would use? 


MktoForms2.whenReady(function(mktoForm){ mktoForm.addHiddenFields({ lastFormReferrerURL : document.referrer }); });

 

replacing lastFormReferrerURL with the SOAP API name of your new String field. 

Brenda_Denting1
New Participant
October 1, 2020

Ok, I tested the script and it didn't work. I put the script directly under the form script. I put the lastFormReferrerURL hidden field in the form but didn't specify a Referrer Parameter or a URL Parameter. Any advice? 

SanfordWhiteman
New Participant
October 1, 2020

The field doesn't even need to be on the form for this (addHiddenFields takes care of it).

 

What page is this on?