Hi -
I need help with a hubspot form. I have a embedded form that I need to be able to auto submit with a script and the inline message to show up once the form has been submitted. I currently have a script in place to auto populate the email address field, I need to have the form auto submit when the page loads and the message to show up. I have read past posts but there isn’t a solution in any of them. Any help provided would be great. The customer would have already provided consent prior to submission. This is for an optout form. Thank you
Hey @CD20623, is this a hubspot form hosted on a HubSpot landing page/website page? Or is it a custom from that you’ve created?
If it’s the former - you should just be able to use some Javascript to handle the form submit automatically when the page loads. There is a good example of how to do this here on Stack Overflow.
If it’s the latter you can use the Submit form data endpoint to trigger the submission with whatever data you like.
It’s a hubspot form that is being hosted in a hubspot module. I have built a module that we can put on a page that will pull the email address out of the website url and pre-fill the email field, I’m having a issue with submitting the form automatically once the page is loaded in the browser.
Hey @CD20623 ok thanks for clarifying. Next question is what specific issues are you seeing? Can you share the script you are currently using to attempt to produce the auto-submission?
<script>
function getLastPart(url)
{
const parts = url.split(‘=’);
return parts.at(-1);
}
var url = new URL(“{{ module.url.href }}/opt-out?email={{ module.contact_email }}”);
window.addEventListener(‘message’, event => {
if(event.data.type === ‘hsFormCallback’ && event.data.eventName === ‘onFormReady’) {
$(‘input[name=“email”]’).val(“{{ module.contact_email|replace(‘[’, ‘’)|replace(‘]’, ‘’) }}”);
}
});
console.log(url.href);
console.log(url.search);
console.log(url.searchParams.get(‘email’));
</script>
{% form
form_to_use=“{{ module.form_field.form_id }}”
response_response_type=“{{ module.form_field.response_type }}”
response_message=“{{ module.form_field.message }}”
response_redirect_id=“{{ module.form_field.redirect_id }}”
response_redirect_url=“{{module.form_field.redirect_url}}”
%}