0

I'm using Divi, ACF and Hubspot.

I have a hubspot form, added in a Code Module within Divi (which, I have learned, can not have any php in it), that redirects to gated content on my clients site. I would like for the client to be able to change the URL using an ACF field in the backend rather than having to dive into the code.

I can see that the ACF field URL is available as I can attach it to a button.

    <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js"></script>
    
    <script>
        hbspt.forms.create({
            region: "XXX",
            portalId: "XXX",
            formId: "XXX",
            onFormSubmit: function($form) {
                setTimeout( function() {
                    var formData = $form.serialize();
                    window.location = acf.get_field('gated_content_url');
                }, 300 ); 
        
            }
        });
    </script>

The code that I have works when using an absolute URL but I'm trying to feed the ACF field in as the redirect URL.

  • If you are in a `php` file you will need to wrap your code within the appropriate `php` tags as `` – wouch Apr 27 '23 at 23:35
  • Thanks @wouch – Unfortunately that doesn't seem to help. but it does get some info up into the address bar, which is more than I can say for the other things that I have tried. But it just seems to echo the `https://www.example.com/%3C?php%20echo%20get_field(%27gated_content_url%27);%20?%3E` I found out that the `Divi Code Module` can not have `php` in it. Is there a way to get an `ACF` field using javascript? – Bryan Canning Apr 28 '23 at 14:43
  • ACF has a [JavaScript API](https://www.advancedcustomfields.com/resources/javascript-api/#acf.field) that you could try utilizing (haven't tried myself). Looks like the script would be `acf.getField('gated_content_url')` – wouch Apr 28 '23 at 16:10
  • Edited original post to show the latest test which still doesn't seem to pull the field value in to the `window.location` line. – Bryan Canning Apr 28 '23 at 20:16

0 Answers0