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.

Gravity_form_enqueue_scripts

  1. Greetings,

    I'm totaly new to gravity form, I'm currently playing with a simple one line form (newsletter subscribtion) while reading the documentation to try to understand how it works.

    I'm mostly trying to style it and see the different behaviors, so far so good

    I'm inserting the form directly in my template

    I have a couple of questions

    so that I use the documentation on
    http://www.gravityhelp.com/documentation/page/Gravity_form_enqueue_scripts
    it is said that the enqueue has to be added to the header...
    1° is it possible to add it from my template page using a hook? so that the gravityforms/css/forms.css?ver=1.6.1 is only added to needed page
    what about if I put it onto the functions.php with an if statement to pust it only for a given page?

    2° assuming that I want to fully style from my templace style.css, is there a way to avoid the gravity form own css to be displayed? I understand from some post in this forum that it is a configuration on the admin panel, but just can't find it

    thank you very much in advance

    Posted 12 years ago on Monday December 12, 2011 | Permalink
  2. You can add a function to your theme's functions.php to include it conditionally, based on what page is being loaded or what page is being used. Doing it in the template is too late to get it into the < head >.

    Regarding #2, you can turn off the CSS output with a checkbox in the form builder. It's on the settings page in the Gravity Forms menu. See here:
    http://www.gravityhelp.com/documentation/page/File:Settings-page.png

    Posted 12 years ago on Monday December 12, 2011 | Permalink
  3. @Chris Hajer

    Thank you for your help.

    shall I fire the wp_head or init hook?

    I have written something like

    function gr_gravity_form_enqueue_scripts()
    {
    	if ( is_page(4))
    	{
    	gravity_form_enqueue_scripts(1, true);
    	}
    }
    add_action('wp_head', 'gr_gravity_form_enqueue_scripts');

    is that the correct way?

    Posted 12 years ago on Tuesday December 13, 2011 | Permalink
  4. I believe that's the correct way. There are so many ways it will actually work I am unsure of the absolute proper way. wp_head() seems correct to me. Here is another user's recent experience with doing it just like that (be sure to view the pastebin link): http://www.gravityhelp.com/forums/topic/gravity-form-enqueue-scripts-in-functionsphp-vs-headphp#post-43489

    Have you tried it, and does it work? If not, can you share a link to your page? Thanks

    Posted 12 years ago on Tuesday December 13, 2011 | Permalink
  5. @Chris Hajer

    Thank you very much for your replied

    yes using the head worked, since I'm new to Gravity Form, I was just trying to make sure I was doing the right way.

    it is the very same with WP, there is so many 'roads' that lead to the goal, but some are good use of WP logic while other are just twisted ways.. since I try to learn the best practise as much as possible, hence my question

    playing a bit more with the gravity form, I'm wondering if I'm not going to do a function based on page and fire each needed hook/filter for gravity form from this function

    doing something like below, would that be a smart way to code?

    add_action('wp_head', 'gr_gravity_form_init');
    
    function gr_gravity_form_init()
    {
    	if ( is_page(4)) //
    	{
    	gravity_form_enqueue_scripts(1, true);
    	add_filter("gform_validation_message_1", "gr_gravity_form_nl_wrong_email", 10, 2);
    	}
    }
    
    function gr_gravity_form_nl_wrong_email($message){
      return "<span class=\"validation_error\">Oups, there's an error - please fill with a valid email !</span>" ;
    }

    Thank you in advance

    Posted 12 years ago on Tuesday December 13, 2011 | Permalink
  6. You could, but I think you might be over thinking it. I'm not sure of the exact scenario where you would need this, but I suspect what you are trying to do it already possible within Gravity Forms. The only times I use conditionals as you did is when I want to enqueue the scripts on specific pages or when specific page templates are being used, or when I want to apply the function to just one form. If you post what you're trying to accomplish in a new topic, we'd be happy to help you work it out. Thank you.

    Posted 12 years ago on Tuesday December 13, 2011 | Permalink

This topic has been resolved and has been closed to new replies.