Is it possible to force values in fieds of a popup or an embedded form?

Good morning,

On a page of my website, I can choose:
- trigger a popup with a lead capture form when you click on a button (see Embed CTAs (legacy) on your external site)
- integrate the same form directly into the page (see https://knowledge.hubspot.com/forms/how-can-i-share-a-hubspot-form-if-im-using-an-external-site# add-the-form-embed-code)

Is it possible to force the value of certain fields in one way or another please?

Have a nice day and thanks
+camille

Hey @camilleblaise the only “out of the box” way to do this would be through adding a query string within the url, if you link to the page or form you can add a query string into your URL to populate a value.

.

Outside of this the only way to do this would be through custom javascript, which would require some custom development skills.

Hi @TomM2 ,

Thanks for your reply and sorry for the delay from my side.

I created a custom javascript to force the value of an hidden value.

For some reasons, the script can’t retrive the input element with the method “document.getElementsByName()” until I select the element through “Developper > Developper Tools > Elements” in my Chrome navigator.

Do you any behavior from Hubspot that could prevent me to access the element properly before ‘inspecting’ it trough the developper tool ?

Thanks again and I keep on looking for a solution - if I find something, I will post here what I found :slightly_smiling_face:

Hey @camilleblaise have you enabled the set as raw html feature on the form? If not this would be rendering inside an iframe which would likely affect this.

Thanks a lot @TomM2 !

We added a function to be sure the input element exists before forcing its value if it can help

function waitForElementToExist(name) {
 return new Promise(resolve => {
 if (document.getElementsByName(name)[0]) {
 return resolve(document.getElementsByName(name)[0]);
 }
 const observer = new MutationObserver(() => {
 if (document.getElementsByName(name)[0]) {
 resolve(document.getElementsByName(name)[0]);
 observer.disconnect();
 }
 });
 observer.observe(document.body, {
 subtree: true,
 childList: true,
 });
 });
}

My JS is terrible to be honest so I can’t help with the specific syntax. Maybe the pro @coldrickjack might be able to help a bit more though!

Thanks @TomM2 - my english is terrible ; I just wanted to share a piece of script that allowed us to deal with this issue :slightly_smiling_face:

Not at all! My English is quite bad too so my apologies for the misunderstanding! Thank you for sharing!