PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Enqueueing scripts dynamically to embed multiple forms

  1. Hello!

    I'm using Gravity Forms on a site for a client. I need him to be able to embed forms dynamically in a page template - so he can create a new form, create a new page, and embed his form in the page - but I need to be able to do it using the function call rather than shortcodes.

    I'm creating an array for a drop-down in the page admin (using Developers Custom Fields) so the client can select from the Gravity Forms he's created.

    I'm then using the function call in a page template, and adding the value of the custom field (as the form id) to the function call.

    This works great if I know in advance which form is on which page so I can enqueue the scripts. But if the client creates a new form, creates a new page, and selects his form in the custom drop-down, then the scripts are not enqueued.

    So - is there a way to use gravity_form_enqueue_scripts() without specifying the form id?

    Thanks!

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  2. How about some logic in the header.php of the theme that checks for the existence of the custom field (whatever your key is) and if that's present, enqueue the scripts for the form ID, which is the meta value. Would that work for you?

    Posted 13 years ago on Friday November 25, 2011 | Permalink
  3. Yep - that's where I got to too - it's working great!

    It's actually a really nice solution - using a certain template with a custom field registered, you can choose any form you've created from a dropdown and it displays on the page. Just keeps the wysiwyg area clear of shortcodes which might help with certain styling and keep things simpler for users.

    If anyone wants the code let me know and I'll post it here!

    Posted 13 years ago on Friday November 25, 2011 | Permalink
  4. Please do post it. I'm sure it will be helpful to someone. Thank you for sharing.

    Posted 13 years ago on Friday November 25, 2011 | Permalink