Add submitted page to email in Divi contact module

How to add the page name and url to the confirmation email that gets sent out using the Divi Contact module.

Have you ever wanted to know what page the contact module is submitted from? Maybe you have a website with dynamic content such as real estate and you want to know what property the visitor is enquiring about.

How do you know this? How do you know what page the contact form is submitted from?

Divi by default does not have a way to do this, but after this tutorial, you will know how.

What we will be doing is to add two input fields to the contact form, hiding them and then using jQeury to add the name and URL of the page. When the user submits the form, these fields have the content that we can show in the email form.

1. Set up your Contact module.

The first thing you need to do is to add the contact module to your page.

Add two fields like we have done in the below image. The important thing to do here is:
– add a custom field ID (you need this later)
– add “display: none !important;” to the custom CSS tab. This will hide it from being visible

how to add the page id/name to divi contact module
how to add the page id/name to divi contact module
how to add the page id/name to divi contact module

2. Add Jquery to Child Theme.

We need to use a mixture of PHP and jQuery to get the page name and URL, so we can’t use the Divi Intrgrations tab. We will have to create a child theme and add some code in the functions.php file.

The code has comments next to it to explain but in a nutsell we are adding a WordPress action “wp_footer” which adds code to the footer of your website. In this action we are defining variables which are the page name and url. We then use jQuery to change the value of the inputs to these variables and make them readonly so no autofill will change it.

The code is as follows.

3. Add to email.

The final step is to add these inputs to our email form. You can choose how you want to do this, below is an example of how I added them to the form and how it looks when you get the email.

how to add the page id/name to divi contact module
how to add the page id/name to divi contact module

4. Celebrate with a high-five!

Virtual high-five us as you see this appear on your emails. We hope this has helped you in some way and that you have a great time implementing this on your websites.

Any issues, let us know

37 Comments

  1. Hi there ! I was so happy to find this tuto ! 🙂
    It works fine but in my (particular case) I need to retrieve an URL including a GCLID parameter.

    My url looks like : https://mydomain.com/contact/?gclid=12345

    Can the script be changed to include the full URL including the gclid parameter ?

    Thanks

    • Me again 🙂
      Fixed !!!!

      Here is the code pushed in functions.php
      (page_name removed because not required in my case)

      It looks like code is not accepted in posts here, so here is the illustration screenshot: https://snipboard.io/92hZ08.jpg

      isset($_GET[‘gclid’]) ? $_GET[‘gclid’] : “”;
      has been taken from my gclid injection script

      Don’t forget to set page_url as a non required field in the Divi contact form setting (in order to allow the mail to be sent if there NO gclid in the url).

      Hope it will helps 😉

      • Thanks so much for posting your answer, I think it will help so many other users 😀

        Have a great day!

  2. Very good. It’s worksfor me. Thank you for the tutorial 🙂

    All the best,
    Neil.

    • Very good – thank you for letting us know!

  3. No uso childtheme por lo que intente poner el código con el plugin Code Snippets y no funciono. Probe con 4 o 5 plugins mas para poner code snippets y no funcionaron. Probe poner el código directamente en el functions.php de divi y funciona pero eso no es recomendable pues cuando actualice divi el snippet se ira…
    Alguna idea de como puedo ejecutar el código sin usar un child theme y sin ponerlo directamete en el functions.ph de divi?

    • Should work with a code snippet plugin too..

      When you do this and inspect the page, can you see the code in the footer of your site?

  4. Unfortunately it doesn’t work anymore. We didn’t change anything. Is it because of an DIVI or wordpress update?

    • The page_name works but I’m not getting the page_url when receiving the emails. My custom fields have the same name as the code provided. any ideas?

      • Actually it works, I just forgot to save the functions.php file.

        • Good news – thanks for letting us know 😀

          • Actually it’s not working anymore for me. Lou hijacked my comment 😉 So how can I fix the problem now?

  5. Hola, Lo he probado y funciona a la perfección.

    Lo único que necesito que envíe la descripción corta del producto en vez de la URL.

    Saben como puedo hacerlo?

    Gracias

    • Sorry we do not have a tutorial for this – but it would be similar method of hiding the short description on the page and then on load, to automatically add this text

  6. hey there! I think i’ve tried this correctly – would it make any difference on a WP Multisite? I’m receiving the email, but where the info would be is blank / empty.

    To recap I’ve added two fields (Input Field), made them display:none, added the code to my functions.php file in child theme, and added the fields to my email, e.g. %%page_name%%

    • Yes should work – send a link to the page so I can see, might be able to find out

  7. Please disregard my previous comments, it’s working now!

    • Perfect thanks!

  8. This works BRILLIANTLY in a post or regular page, but I’m having trouble using it in a Product template in the Theme Builder. I get the error message “invalid email” (even though email is valid) when attempting to submit the form. Any advice?

  9. Wonderful tip and clear instructions, thank you! I’m trying to use this in the Theme Builder for a Woo Commerce Product Template, but get the error message “invalid email” when submitting the form (even though the email is valid). I tested your method in a regular post and it works great, but it won’t work in a Theme Builder template for “All Products.” Any suggestions?? Thanks in advance!

  10. Nice, It’s working! The only problem is that when I include ID’s in the content of the message, I start getting emails in spam

    • What do you mean including ID’s?

  11. when I select an attribute, the url changes, but it is not visible at the url address in the received message … what i’m missing here

    • What attribute?

  12. Thank you ! It’s working !

    • Perfect thanks!

  13. Hi! Thanks for this.

    I tried it on Divi 4.7.5, but it doesn’t work.

    Peeked into the source of the generated page, and the script is inserted into the page, but other than that, I can’t see the variables within the page.

    Any hint is highly appreciated.

    • Hahahaha. Silly me. I forgot to thoroughly read the instructions.

      • The same is happening to me… what i’m missing?

  14. this is very interesting!! Thanks! I would like to change also the name of the mail when arrive to the owner. Default it arrive with “mail@domain…”. is it possible to change “mail” with somenthing like. fromcontactform@domain…” ?

    • Do you mean to change who the email goes to?

      • no, just the name of the mail that arrive from the form to my computer. My site is cristina.com and the emails from my contact form arrive like : ma**@cr******.com in my PC. To identify the emails from the form I would like to receive : fr*************@cr******.com Don’t know if is possible 😉

        • Not sure, if you are using Gmail or similar, you could set up a filter to add a tag or put it in a folder automatically

  15. Is there a way to do this without creating a child theme and without having the custom code overwritten with any updates?

    Perhaps with a plugin that can dynamically insert the necessary code in function.php?

    • maybe, this is our solution for now

    • Pleasure – have a great week!

Submit a Comment

Explore more from Divi Engine