CMS Development

DRWBA
Member

Adding WordPress post title as hidden form field

I need to set up a form where the post title is added to a user's profile.

 

We have 60 courses (posts) on our site and need our sales reps to see which course the user has selected but without them selecting it from a list.

 

Is this possible?

0 Upvotes
2 Replies 2
miljkovicmisa
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Adding WordPress post title as hidden form field

Hello @DRWBA , this is possible, you just need to create a hidden form field in your hubspot form, take the internal name of that field and then use the global form events to check when the form is ready and populate the fild using the title of the page. An example would be like this:

window.addEventListener('message', event => {
   if(event.data.type === 'onFormReady') {
       const pageTitle = document.querySelector('title').value;
       const formField = document.querySelector('.your_hidden_filed_internal_name');
       formField.value = pageTitle;
   }
});

 

If you need any further help don't hesitate to write here.
Cheers!

If my answer was helpful please mark it as a solution.

DRWBA
Member

Adding WordPress post title as hidden form field

Thank you. 

 

I have tested this and the field is added to the user after form submission but the page title isn't showing, just a blank field...

0 Upvotes