I’m working on a project where users pick an image and fill out a Hubspot form. The form works fine when embedded, but I’m stuck on how to link the chosen image with the form data.\n\nHere’s what I’ve got so far:\n\njavascript\n// Hubspot form creation\nhbspt.forms.create({\n portalId: '12345',\n formId: 'abc123xyz',\n campaignId: 'camp456def'\n});\n\n// Image selection\n$('.image-gallery').on('click', '.thumbnail', function() {\n $('.thumbnail').removeClass('selected');\n $(this).addClass('selected');\n});\n
\n\nHow can I pass the selected image info to the Hubspot form? Or should I use Rails to build an API that talks to Hubspot? I’m new to API integration, so any tips would be great.\n\nAlso, if there’s a way to customize the Hubspot form to include my image selection, that would be awesome. Thanks!
As someone who’s worked extensively with HubSpot forms and custom integrations, I can share some insights that might help you out.
From my experience, the best approach here would be to use HubSpot’s forms API rather than the embedded form. This gives you more control over the submission process and allows you to include custom data like your image selection.
You’ll need to create a custom form in your Rails app that includes both the HubSpot fields and your image selection. On form submission, gather all the data, including the selected image, and then use HubSpot’s forms API to submit this data programmatically. Using a gem like ‘hubspot-api-client’ can simplify interacting with their API. Just make sure your form fields are mapped correctly to HubSpot’s expected field names. This method, although initially more complex, offers greater flexibility in the long run.
Hope this helps point you in the right direction!