CRM

garywhocares
Membre

Pre-populating the form field with Wordpress post title

This is what I've got so far:

 

<script>

hbspt.forms.create({
region: "na1",
portalId: "xxxx",
formId: "xxxxx",
onFormReady: function($form) {
$form.find('input[name="message"]').val("post_title").change();
}
});
</script>

 

How can I insert the value to the message field dynamically with the Wordpress post title?

2 Réponses
Ben_M
Conseiller clé

Pre-populating the form field with Wordpress post title

Is that all of your code?  If so, "post_title" is not defined anywhere.  Also, if you put the title of the page/post into your "message" that an end-user can edit and remove, what is the point?  If you are trying to grab a value from the page I would recommend storing it as a hidden value on the form so that it cannot be overwritten by the user.  If you just want the basic title from the HTML you could reference the "document.title" from the DOM and eliminate defining your "post_title" field altogether, but it depends on your application or if there's anything else you are trying to do with your setup.

JenWeiss
HubSpot Employee
HubSpot Employee

Pre-populating the form field with Wordpress post title

Hi @garywhocares , 

 

Thank you for reaching out to us! 

 

I would like to tag in some of our experts into this @webdew@DavidDennison , and @Ben_M 

 

Best, 

@JenWeiss 

Whether you're a student or a lifelong learner. Join StudentSpot to be inspired.