6 Ways to Use JavaScript to Enhance Your Pardot Forms


Want to do something with your Pardot form that is not available in the editor? Try using JavaScript! Enhance your forms by using these 6 advanced Pardot form techniques. Learn how to add text between form fields, how to capture URL parameters in hidden fields and more.

Adding JavaScript to your Pardot forms

Custom JavaScript can be placed within your Pardot forms under Look and Feel > Below Form. Click on the HTML button within the WYSIWYG editor and add in the JavaScript.

1. Add text between form fields

Edit the form field you want to add the text before in the form editor. Click on the advanced tab and add a CSS class with the name “add-text-before”.

Once the class has been added to the form field, you can add the following JS to your form and update the message.

2. Redirect to a thank you page based on field values

This tip is from the Pardot Help Docs, but with a couple updates. The article recommends using JavaScript-encoding for variable tags using {js}. I’ve never had success while using this method. Instead using this JavaScript does the trick.

3. Use a hidden field to capture page url

Edit the hidden form field, click on the advanced tab and add a CSS class with the name “get-page-url”.

Insert this JS into your form to capture the page url in the hidden field.

4. Use a Hidden field to capture page name

Edit the hidden form field, click on the advanced tab and add a CSS class with the name “get-page-name”.

Insert this JS into your form to capture the page url in the hidden field.

5. Pass URL parameters to a Pardot form

You can use this script to parse out URL parameters and put them into fields within your Pardot form. In this example, I’m passing utm_source, utm_medium and utm_campaign into hidden form fields.

6. Turn your form labels into placeholder text

There’s currently no feature for Pardot forms that allow you to use placeholder text instead of the label text. So, in this tutorial, I will show you how to add a bit of JavaScript to your Pardot forms to use the field labels as placeholders.

Related Posts

  • 15/10/2020
    How to Use Flex Fields in Pardot

    Flex fields are custom fields that can be used over and over again to limit the number of one-time-only fields within Pardot and Salesforce. They contain data that is required temporarily to execute a specific event or campaign. Once the data is no longer needed, the fields can be reset to blank using an Engagement Program or Automation Rule

  • 04/10/2020
    How To Embed a Pardot Form on Your Website The Right Way

    Pardot offers 2 methods for embedding forms on your website; embedding using an iframe, and form handlers. While the embedded iFrame forms allow marketers to have control over updating and configuring the forms, using an iFrame isn’t always ideal for website usability. In this tutorial, I will show you how to take advantage of the Pardot iFrame forms and make it look great embedded on your website.

  • 23/09/2020
    7 Ways Pardot Users Can Use Chrome Developer Tools For Troubleshooting & Testing

    Chrome Developer Tools is widely used by developers to help edit pages on-the-fly and diagnose issues. Pardot users can use DevTools to troubleshoot and test landing pages and forms. In this post, I’ll show you 7 ways you can use DevTools, including how to identify errors on a landing page, how to customize the CSS of a form and how to view hidden form field values.

49 comment(s)
  • Jaime López

    08/10/2018 at 12:35 am

    Hi Jenna! Your blog is a real gold mine for a Pardot admin :) Thanks for all the work you put in! I was wondering, would you know how to write a script to validate input for a Phone number field form? I would want to force prospects to input their phone number as +123456789, and prevent submission if any other format is used. Thanks!

    • Jenna Molby
      to Jaime López

      09/10/2018 at 11:29 am

      Hi Jaime, So happy you love my blog! It's certainly possible to force prospects to input their phone number in a particular format, but I haven't tried it myself, yet. Cheers, Jenna

    • Joe Martinez
      to Jenna Molby

      14/01/2019 at 2:49 pm

      Hi Jenna, I was wondering if you could point me to any resources to handle the phone validation that Jaime Lopez commented about. Any help would be appreciated. Thank you!

    • Skender
      to Jenna Molby

      04/05/2020 at 12:50 am

      Hi Jenna, thank you for so much for this really useful website. While I understand how to insert css classes into a Pardot form, would be possible to insert also a URL link of a CSS file inside the form? The for will be embedded into an iframe. Thank you so much,

    • Jenna Molby
      to Skender

      04/05/2020 at 10:59 am

      Hi Skender, You're welcome! Yes, you can also insert a URL to link a CSS file within your form. Just make sure that if you are using https:// for your Pardot form that the CSS you use is also https://. Cheers, Jenna

  • John

    11/09/2018 at 2:35 pm

    js encoded fields is what broke the dynamic redirect for me as well, removing the js encoding from my field fixed it. Great tips here, will definitely make use of the url parameter hack! Thanks

  • Brian

    08/08/2018 at 3:44 pm

    Jenna, Thanks for the great info. Any thoughts on how to leverage the 'Passing URL Parameters to a Form' within an iframe? Thx Brian

    • Jenna Molby
      to Brian

      08/08/2018 at 4:06 pm

      Hi Brian, you would need to add a piece of JavaScript to the parent page that will pass the parameters to the iFrame. You would still need to include the JavaScript in this post to your Pardot form. var loc = window.location.toString(), params = loc.split('?')[1], iframe = document.getElementById('pardot-form'); iframe.src = iframe.src + '?' + params;​​​​​​​​​​​​​​​​

    • Elisha
      to Jenna Molby

      31/01/2019 at 2:59 am

      For anyone trying to pull through the Page URL when using an iframe and struggling to understand the complicated tech talk on the link above - simply follow Jenna's (super helpful!) steps above, but use this code in in your javascript instead: document.querySelector(".get-page-url input").value = document.referrer;

      to Elisha

      15/06/2020 at 11:02 pm

      Thank you very much Jenna and Elisha. This solved a big issue for me.

    • Ethan
      to Elisha

      25/08/2020 at 4:33 pm

      Elisha, that is so helpful. Thank you! How would you modify the JS to pull in the page name with an iFrame form?

  • Jordan

    20/06/2018 at 11:24 pm

    Hello, Jenna. I've been using your Landing Pages a lot. I really appreciate that. About these tips, is it possible to get URL or title of the parent page when I use form as an iframe form? If it's impossible, what's the case to use these scripts to get URL or titles while we could use Completion Action to change the field instead?

    • Jenna Molby
      to Jordan

      22/06/2018 at 1:38 pm

      Hi Jordan, I haven't tried it myself, but this article should help you https://www.nczonline.net/blog/2013/04/16/getting-the-url-of-an-iframes-parent/ Cheers, Jenna

  • Mardi

    13/06/2018 at 12:05 am

    How do you go about implementing these features for Pardot Form Handlers? Have a good now at trying to capture the page URL with an existing form handler but not having much luck.

    • Jenna Molby
      to Mardi

      13/06/2018 at 12:18 pm

      Hi Mardi, Great question! You would need to figure out what the selector is for your hidden field. It should have an ID or Class which you can use to target the field. Then you would add this script document.querySelector(".get-page-url input").value = window.location.href; to your page and replace .get-page-url input with the selector of your hidden field. Cheers, Jenna

1 2 3 5

Leave A Comment

Your email address will not be published. Required fields are marked *

About Me

Welcome to my blog, where I share, tips, tricks, thoughts and solutions that I learn in my daily life as a Marketing Operations leader.

Most Commented
Popular Posts