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.

Using conditional logic means form no show...?

  1. Hi,

    I am having the same problems as the below post;
    http://www.gravityhelp.com/forums/topic/another-conditional-logic-problem

    But after reading it, I still do not understand what I need to do to fix the problem, as the form code is showing, just not it's physical self on my page...

    http://dev.the-cakeshed.com/products/ - it is supposed to be in the sidebar, which is currently left blank.

    Any and all advice or help, greatly received :)

    Bklahrke

    Posted 12 years ago on Sunday May 8, 2011 | Permalink
  2. When embedding a Gravity Form via a function call you must also manually include the necessary Gravity Forms related Javascript and CSS via the built in WordPress enqueue capabilities. Gravity Forms does not include these by default when calling a form via a function call and they are necessary for forms that contain conditional logic or the date picker field.

    We strongly recommend you enqueue the scripts rather than including them as hard-coded calls in your theme. Implementing it this way will insure that Gravity Forms does not include them on the page if they are already present. It is also a good practice to only load these scripts on the front end.

    Gravity Forms 1.5 introduced the gravity_form_enqueue_scripts function which allows you to easily enqueue the necessary Gravity Forms' scripts and styles when manually embedding a form. This is also useful if you are using a GF widget and do not wish for the styles and scripts to be loaded inline.

    You will need to manually enqueue the scripts and CSS by placing a short script block in your theme's header.php file.

    You can find more information at the URLs below

    http://www.gravityhelp.com/documentation/page/Embedding_A_Form

    http://www.gravityhelp.com/documentation/page/Gravity_form_enqueue_scripts

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  3. Hi Kevin,

    I understand what you have written and thank you very much for taking the time to do so...

    BUT

    I really don't understand how to implement the "<?php gravity_form_enqueue_scripts(2, true); ?>" bit...

    I understand it needs to go into the gravityforms.php but I do not understand where... And looking at too much code like that is daunting for me :-/

    Can you shed any more light, please?

    Kind regards,

    Bklahrke

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  4. It doesn't go in gravityforms.php. The gravity_form_enqueue_scripts function call is only used when displaying a Gravity Form using a PHP function call.

    How are you displaying your form? You mention it is in a sidebar, is it being displayed in a widget in your sidebar?

    I'm unable to view your page because of an error. When I go here: http://dev.the-cakeshed.com/products/ I get an error. This is most likely because you are editing the gravityforms.php file, which you should not be doing. Never edit the core Gravity Forms files.

    If you can correct the page so I can view it i'd be glad to take a look and see what is going on. With conditional logic it most likely isn't displaying because of a Javascript error on your page. Correct the page, undo any changes you have made to gravityforms.php and I can take a look.

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  5. Hi Carl,

    Can you try it again, please... I just fixed that error...

    I am calling the sidebar a sidebar, but in fact it is not... It's an area displaying a post (real backwards way of doing this I know)...

    Thank you :)

    Bklahrke

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  6. That is different then. If you are displaying a post there then the problem is going to be related to how you are doing this (which is backwards). It's hard to tell what the issue is because I can't see your template code.

    If you send me a WordPress admin login for this site along with an FTP login via our Contact Us form and let me know which theme template file this custom code is in I can take a look.

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  7. Hi Carl,

    I have just posted an email. Just going to send another w/ my FTP details.

    Thank you.

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  8. Ok I changed your page.php so the function call to the form looked like this:

    gravity_form(2, true, true, false, '', false);

    What you had copy-n-pasted wasn't the example function call, it was the function definition which had the full parameters listed.

    I then added this to your themes functions.php file:

    gravity_form_enqueue_scripts(2, false);

    This enqueues the necessary scripts and CSS. Since you aren't calling the form the traditional way (via the shortcode in a page or post or via a widget in a sidebar) you need to manually enqueue these scripts when displaying the form via the PHP function call.

    Your form is now working and displaying.

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  9. Sorry, I may have misunderstood the situation earlier. Apologies for any confusion. I'll bow out and let Carl take it from here.

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  10. Thank you Carl!

    I can see it now :)

    Thank you sooooooo much!

    Bklahrke

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  11. Melvin Neo
    Member

    Hey,

    I know this post is more than a month old. But I have a question though. I know the number "2" is the ID of the form. What if I have 3 pages and in each page there's a form, and all these forms have different IDs, like 2, 3 or 4? In this case, how and where do I put them?

    Posted 12 years ago on Tuesday June 28, 2011 | Permalink
  12. @cmeihoong You can place them all in your themes functions.php file and wrap each one in an if statement that checks the page so it only executes if you are on one of those pages.

    For example this code would only execute if it's page id 5:

    <?php
    if (is_page(5)) {
        gravity_form_enqueue_scripts(1, true);
    }
    ?>

    But the real question is if you have 3 pages and each page there is a form why are you manually using the function call rather than simply using the Gravity Forms shortcode on each page you want to display a form? This custom code is only necessary when manually displaying a form using a PHP function call.

    Typically you should primarily be using the shortcode or Widget to display a form.

    Posted 12 years ago on Tuesday June 28, 2011 | Permalink
  13. Melvin Neo
    Member

    Hey Carl,

    Because the shortcodes didn't work for me due to the W3 Total Cache plugin. So I was thinking of alternatives. We've just 'spoken' via email actually. :)

    Posted 12 years ago on Tuesday June 28, 2011 | Permalink
  14. The shortcodes should work with W3 Total Cache. You have to configure W3 Total Cache so it ignores any Gravity Forms related queries in it's database settings by ignoring the query stem rg_* or yourprefix_rg_*. But as far as I am aware it should work. What specific issue are you running into?

    Posted 12 years ago on Tuesday June 28, 2011 | Permalink