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.

How do I send dynamic values with the gravity_form() function?

  1. Hi there,

    For some reason, I can't find the documentation on how to send my values to dynamic fields using the gravity_form() function. I see plenty of examples using the shortcode, but nothing about the function. I even searched on Google and came up empty handed.

    Posted 11 years ago on Thursday October 7, 2010 | Permalink
  2. I'm surprised this code is not better explained in the Function Call section on this documentation page: http://www.gravityhelp.com/documentation/embedding-a-form/

    Posted 11 years ago on Thursday October 7, 2010 | Permalink
  3. We're working on some really extensive documentation and it should be ready to release shortly. Here's the run down on the embed options using the function...

    If you would like to call a form from within a WordPress theme file, you may do so using a function call. The function and it's available parameters are outlined below.

    <?php gravity_form($id, $display_title=true, $display_description=true, $display_inactive=false, $field_values=null, $ajax=false); ?>

    $id
    (integer) (required) The id of the form to be embedded.

    $display_title
    (boolean) (optional) Whether or not do display the form title.
    Defaults to false.

    $display_description
    (boolean) (optional) Whether or not do display the form description.
    Defaults to false.

    $display_inactive
    (boolean) (optional) Whether or not to display the form even if it is inactive.
    Defaults to false.

    $field_values
    (array) (optional)
    Defaults to false.

    $ajax
    (boolean) (optional) Whether or not to use AJAX for form submission.
    Defaults to false.

    Usage Examples
    ---------------------------------

    Basic Function Call

    <?php gravity_form(1, false, false, false, '', false); ?>

    This snippet will display the form with an id of '1'; the title and description will not be displayed, the form itself will not display if it is inactive, and it will not use AJAX for form submission.

    With Ajax

    <?php gravity_form(1, false, false, false, '', true); ?>

    This snippet will display the exact same form as above except it will use AJAX for form submission.

    Enqueue Scripts and Styles

    When embedding a 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 hardcoded 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.

    By default, the wp_enqueue_script function will load the scripts in both the front and back end. To avoid this, we advise checking to make sure you are not inside the admin by using another built in WordPress function is_admin().

    <?php
    if(!is_admin()) {
        wp_enqueue_script("gforms_ui_datepicker", WP_PLUGIN_URL . "/gravityforms/js/jquery-ui/ui.datepicker.js", array("jquery"), "1.4", true);
        wp_enqueue_script("gforms_datepicker", WP_PLUGIN_URL . "/gravityforms/js/datepicker.js", array("gforms_ui_datepicker"), "1.4", true);
        wp_enqueue_script("gforms_conditional_logic_lib", WP_PLUGIN_URL . "/gravityforms/js/conditional_logic.js", array("gforms_ui_datepicker"), "1.4", true);
        wp_enqueue_style("gforms_css", WP_PLUGIN_URL . "/gravityforms/css/forms.css");
    }
    ?>
    Posted 11 years ago on Thursday October 7, 2010 | Permalink
  4. Ahah! I see now.

    For others, here is an example of setting field values with the function:

    gravity_form(1, false, false, array('myfieldname'=>'Hello World') );

    Posted 11 years ago on Thursday October 7, 2010 | Permalink
  5. marketmike
    Member

    Thanks Kevin

    Posted 11 years ago on Saturday October 23, 2010 | Permalink