Upcoming: Form element ID attribute is being changed to be more unique

Highlighted
Community Manager

HubSpot forms render a <form> element with a unique id attribute for each page on which the form is used. However, when multiple instances of the same form are added to the same page, the id for each form may not be unique. To resolve this, the id attribute is being changed. If you are targeting form styling or extra javascript functionality based on the id attribute, you will need to revisit your existing forms.

What's Changing?

HubSpot forms render a <form> element with a unique id attribute for each page on which the form is used, formatted as hsForm_<formID>. If a formInstanceId has been provided when customizing the HubSpot form Script, the id attribute looks like this: hsForm_<formID>_<formInstanceID>

If a form is added to the same page multiple times, and a formInstanceId has not been specified, we render multiple HTML elements with the same id. To fix this, form elements include a <TARGET_ID> attribute: hsForm_<FORM ID>_<TARGET_ID>. <TARGET_ID> can be specified through target. If target isn't specified, an id will be randomly generated on render. All forms should then have unique id attributes.

How will existing forms be affected?

This change will result in the form element id changing. This could break any css or javascript that uses the element id to target specific forms.

To allow developers to continue targeting forms by form id, a new css class, hs-form-<form ID>, is being added to the element. This class is already available so you can begin transitioning to these classes. The data-form-id attribute will not be changing. For a full description of all the elements rendered and how to use them for targeting, please see this article.

When is this happening?

The id attribute update will happen May 19th, 2020. Please correct your css and js selectors before then to prevent styling issues.

Questions? Ask below

Jon McLaren

Sr. CMS Developer Advocate

If my reply answered your question, please mark it as a solution, to make it easier for others to find.

Reply
0 Upvotes
4 Replies 4
Occasional Contributor

Will this affect form embed codes?

Reply
0 Upvotes
Community Manager

@Kennan_wmk Yes it will affect SOME forms embedded using embed codes.

Forms that are using themes, and therefore are using an iframe - those forms are not affected.

Forms that are not targetted using the id attribute for styling or javascript will not be affected.

Forms that do not use form themes, and ARE targeted by CSS or Javascript using the id attribute as the selector, will be affected.

Hopefully that makes it clear. Let us know if you have any further questions.

Jon McLaren

Sr. CMS Developer Advocate

If my reply answered your question, please mark it as a solution, to make it easier for others to find.

Occasional Contributor

Thanks for the reply!

This info is certainly helpful. However, I should have been more clear with my question. What I meant to ask was if the embed codes themselves will be affected.

For example, if I have an embed code that I have used on a page, will that embed code need to be adjusted at all or will I only need to adjust css/js that uses the form's id?

Reply
0 Upvotes
Community Manager

The javascript embed codes you get from within the forms tool do not need to be updated/replaced. The HubL form embed code also does not need to be updated/replaced.

The HTML the script generates is controlled by HubSpot and will be updated from our end.

Only custom non-hubspot generated CSS/JS that uses the form element's id attribute needs to be updated.


Jon McLaren

Sr. CMS Developer Advocate

If my reply answered your question, please mark it as a solution, to make it easier for others to find.

Reply
0 Upvotes