$form object is undefined
-
We’re using a shortcode to embed a form that allows users to download a PDF after submitting the form. It was working fine until something changed with the plugin. We’re currently running v8.15.76. The error I’m getting is
[forms-embed-1.2071] There was an error when running onFormSubmitted function from hbspt.forms.create TypeError: Cannot read properties of undefined (reading '0') v2.js?ver=8.15.76
The error seems to be referring to the $form object passed to the ‘onFormSubmitted’ callback.
Here’s the code that embeds the form. It’s partially generated by the plugin, with the ‘onFormSubmitted’ part added using the ‘leadin_forms_payload’ filter
<script> window.hsFormsOnReady = window.hsFormsOnReady || []; window.hsFormsOnReady.push(() => { hbspt.forms.create({ portalId: XXXXXXX, formId: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", target: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", region: "", onFormSubmitted: function( $form ){ // This is the snippet I added var class_list = $form[0].offsetParent.className; // Check for the wrapper class name if( class_list.includes( 'fl-insight-secondary' ) ) { // Open the PDF in a new tab/window simulateClick( 'https://xxx/xxx/xxx.pdf' ); } return true; } // / onFormSubmitted function }) // / .forms.create }); </script>
- The topic ‘$form object is undefined’ is closed to new replies.