Skip to main content

How to Auto-Download a PDF After Contact Form 7 Submission and Redirect to Thank You Page

 Do you want to give your visitors a PDF file instantly after they submit your Contact Form 7 form? Maybe it’s a brochure, catalog, eBook, or price list.


In this guide, I’ll show you how to:

✅ Automatically download a PDF after form submission
✅ Redirect the user to a custom Thank You page
✅ Keep it simple with just a few lines of code


🛠 Step 1: Upload Your PDF

  1. Go to WordPress Dashboard → Media → Add New

  2. Upload your PDF file

  3. Copy the File URL (you’ll need this for the code)


🛠 Step 2: Create a Thank You Page

  1. Go to Pages → Add New

  2. Name it “Thank You” (or any title you want)

  3. Add your message (e.g., “Thanks for contacting us! Check your email for more details.”)

  4. Publish the page and copy its URL


🛠 Step 3: Add JavaScript Code

Now we’ll add a small script to trigger the PDF download and redirect.

<script> document.addEventListener('wpcf7mailsent', function(event) { // 1. PDF URL (replace with your file link) var pdfUrl = "https://yourdomain.com/wp-content/uploads/yourfile.pdf"; // Trigger PDF download var link = document.createElement('a'); link.href = pdfUrl; link.download = "yourfile.pdf"; document.body.appendChild(link); link.click(); document.body.removeChild(link); // 2. Redirect to Thank You page (replace with your page URL) setTimeout(function(){ window.location.href = "https://yourdomain.com/thank-you"; }, 1000); // 1 second delay so download starts }, false); </script>

📌 Replace:

  • https://yourdomain.com/wp-content/uploads/yourfile.pdf → with your actual PDF URL

  • https://yourdomain.com/thank-you → with your Thank You page URL


🛠 Step 4: Where to Add the Code

You can add the script in two ways:

  • Option 1 (Recommended): Use the Code Snippets plugin → Create a new snippet → Insert into Footer.

  • Option 2: Edit your theme’s footer.php → Paste code before </body>.


🎯 Final Result

Now when a visitor submits your Contact Form 7 form:

  1. The PDF will automatically download

  2. The user will be redirected to your Thank You page

This is a great way to deliver lead magnets, brochures, or eBooks instantly and also track conversions on your Thank You page.


✅ Bonus Tip: Apply to Specific Form Only

If you have multiple forms and want this feature on just one form, you can target it by Form ID. Example:

if (event.detail.contactFormId == "1234") { // run download + redirect only for form ID 1234 }

👉 To find your form ID: Go to Contact → Contact Forms in WordPress, and you’ll see the ID next to your form name.


🎉 Conclusion

With this method, you can easily make Contact Form 7 download a PDF instantly and send visitors to a Thank You page. It’s perfect for businesses that want to share catalogs, eBooks, or guides automatically after form submission.

Comments

Popular posts from this blog

Introduction to HTML, CSS, JavaScript & How Websites Work | Web Development Tutorials #1

Have you ever wondered how websites are created? Maybe you've heard about HTML, CSS, and JavaScript, but you're not quite sure what they are and how they work together to make the websites we use every day. Well, you're in the right place! In this article, we'll take a beginner-friendly journey into the world of web development, where we'll explore HTML, CSS, JavaScript, and the magic that happens behind the scenes to make websites come to life. What is HTML? HTML stands for HyperText Markup Language . Don't let the fancy name scare you; HTML is the backbone of every web page. It's like the skeleton of a website. HTML uses tags to structure content, such as text, images, links, and more. These tags tell web browsers how to display the content. For example, the <h1> tag is used for headings, while the <p> tag is used for paragraphs. HTML provides the structure and content of a webpage. What is CSS? Cascading Style Sheets , or CSS for short, is the...

Optimizing Your E-commerce Site: How to Modify Category Order in WordPress and WooCommerce

Have you ever tried to change the default order of the category in your WordPress and WooCommerce site? If the answer is yes, then you’ll be surprised to know how easily you can change category orders using our effective ways. The arrangement of categories plays a pivotal role in shaping how your audience interacts with your content. However, WordPress, in its default configuration, arranges categories alphabetically, resulting in a rigid and sometimes confusing category list. This situation highlights the importance of customizing category orders in WordPress to create a more engaging and meaningful user experience. WooCommerce site owners face a similar challenge when it comes to product categories, prompting them to seek ways to tailor the order. In this article, we will provide you with step-by-step instructions on how to modify category and taxonomy term orders in WordPress, and how to rearrange product categories in WooCommerce.  Changing the category order in WordPress and W...

How to Save Contact Form 7 Entries in Your WordPress Backend

Contact Form 7 is a fantastic, free plugin that makes it super easy to create and manage contact forms on your WordPress website. You can whip up simple or complex forms in minutes, making it a go-to solution for many website owners. However, one of the default behaviors of Contact Form 7 is that it primarily sends form submissions to your designated email address. While this is essential, what happens if an email gets lost in spam, or you simply want a centralized place to manage all your inquiries? That's where saving Contact Form 7 entries directly in your WordPress backend comes in handy! Having these submissions stored within your WordPress database ensures you never miss a potential lead or important message. So, how do you achieve this? Thankfully, there are excellent plugins that seamlessly integrate with Contact Form 7 to provide this functionality. Let's explore a couple of popular options: Option 1: The Simplicity of Flamingo Developed by the same team behind Contact...