• Resolved marcmarcmarc

    (@marcmarcmarc)


    For a B2B website I have 10 forms in Hubspot for specific services they provide.
    Each product has its own blog/product page, made in Elementor and using the ACF(Advance Custom Fields) plugin.


    These pages are populated using dynamic fields so that the client just adjusts these themselves.
    These are headings, texts, images etc. But here I also want them to be able to add or select the right Hubspot form. This is the conversion that needs to happen on the page.

    If anyone has made this work please let me know how you did it, my failed approach thus far:

    My idea was to add a code block in the Elementor builder that then loads the code dynamically from the blog/product post. The same way I do headings. But this sadly does not work. It only renders a part of the code as plain text. For example:

    The embed code (that works statically but here made anonymous):

    <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: “XXXX” }); </script>

    On the rendered page it only outputs:
    hbspt.forms.create({ region: “na1”, portalId: “12345678”, formId: “XXXX” }); as text inside a div.

    Anyone have an idea to fix this.
    Elementor does have native Hubspot support and I am talking to their support but no help so far.

Viewing 1 replies (of 1 total)
  • Plugin Support gsugrue

    (@gsugrue)

    Hey @marcmarcmarc,

    Thank you for reaching out!

    Our plugin includes an Elementor and Gutenberg widget named ‘HubSpot Form’. This widget functions like a standard widget and features a searchable dropdown menu listing all your forms. This is the simplest and most officially supported method for changing the form on a page.

    While we don’t officially support integrating with alternative plugins, it should be feasible to dynamically set a form ID using ACF that Elementor can recognize through its Dynamic Tag feature. You could then insert a HubSpot form shortcode within an Elementor Shortcode widget, using a dynamic tag for the form ID value.

    Please note: Elementor Dynamic Tags are an Elementor Pro feature. As I don’t have a Pro license, I haven’t been able to test this thoroughly.

    Here’s a step-by-step guide:

    1. Create an ACF Field Group and a corresponding Field for each of your forms.
      Example for my form ‘Form A’ I created:
      ACF Group: Form A Group
      Field: Form A
      Name: hubspot_form_id (Use the same name for all your fields as this will be referenced in the shortcode.)
      Default value: a447cd08-7939-4d17-ade5-a806ba5f03c8 (Replace with your form UUID)
    2. Set a Location Rule in the ‘Form A Group’ settings so that the field only appears on desired pages/posts.
      For instance:
      Rule: Show this field group if => ‘Post Category’ equals ‘Test Category’.
    3. In the Elementor editor, add a Shortcode widget to your Page/Post that meets your rule condition and select the Dynamic Tag button (it looks like a database icon).
      Your shortcode might look something like this:
      [hubspot type="form" portal="YOUR_PORTAL_ID" id="{{acf:hubspot_form_id}}"]

    4. Provided the Page/Post satisfies the rule condition, the form should render correctly.

    If you don’t have an Elementor Pro license, an alternative and more complex workaround involves creating a custom shortcode in your theme’s functions.php file using ACF’s get_field function.
    Always back up this file before making changes.

    The code snippet would resemble the following:

    function acf_hubspot_form_shortcode($atts) {
        // Retrieve the ACF field value, ensuring it matches your actual ACF field name
        $form_id = get_field('hubspot_form_id');
    
        // If there's no form ID returned, do nothing
        if(!$form_id) {
            return '';
        }
    
        // Return the HubSpot form shortcode with the dynamic form ID. You could also hardcode the portal ID here to avoid including it in each shortcode instance.
    
        return do_shortcode('[hubspot type="form" portal="'.esc_attr($atts['portal']).'" id="'.esc_attr($form_id).'"]');
    }
    
    // Register your new shortcode with WordPress
    add_shortcode('acf_hubspot_form','acf_hubspot_form_shortcode');

    Then, in your Elementor or Gutenberg Shortcode widget, simply use:[acf_hubspot_form portal="YOUR_PORTAL_ID"]

    Hopefully, one of these solutions helps!

    Best Regards,
    Gearoid

Viewing 1 replies (of 1 total)
  • The topic ‘Dynamic Hubspot forms per blog page’ is closed to new replies.