forms that capture urls from embeded page its on

For all those that need a more robust answer…with a solid example that works:
We have a form that has Contact Table fields (basics: name, email, phone) plus two separate Custom Object Table fields to automatically tie a single submission as relationships (clever, simple, and reliable).

Next, wanting to auto-populate the webpage title (using wordpress) to these two custom object fields’ input values that are also hidden. This became difficult, cursing ensued, but we have conquered it! The key was finding the “name” of the input fields. Simplistic example code didn’t ‘cut it’.

The above mentioned code was instrumental in crafting this solution (as well as kudos to @derekcavaliero on Solved: HubSpot Community - Embedded Form: Populating form fields - HubSpot Community), but the documentation does NOT ever explain how to fulfill this successful code:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js"></script>
<script>
 hbspt.forms.create({
 region: "na1",
 portalId: "12345678",
 formId: "a341x83a-147e-4fd1-8axc-9367e2b9a179",
 onFormReady: function($form) {
 var v = document.title;
 // strip out the site title addon so I just get the page title
 var v = v.replace(' - titleofmywordpresssitethatidonotwantadded', '');
 // find then OVERRIDE the values of the two custom object fields
 $form.find('input[name="2-9710866/title"]').val(v).change();
 $form.find('input[name="2-9451010/matter_title"]').val(v).change();
 }
 });
</script>

It took ‘inspecting’ the form on the rendered webpage to discover the true name of the custom object input fields. Seems to be a concatenation of the properties ‘objectTypeId’ + ‘/’ + ‘name’.

Overall, it took coffee, cursing, and rage-filled persistence. But now I am calm and happy. Now this one form can dynamically satisfy our need for 45 (only?!) different individual forms to be created. PHEW! :drooling_face:

Happy coding y’all and hope this helps round out HubSpot’s documentation. Please add this example or one similar for our “complex users” :smiling_face_with_sunglasses:

Always remember to mind your Ps and Qs…and commas, semi-colons, and curly braces. Rock on coders! :nerd_face: