yanknudtskov
2/13/2015 - 10:25 PM

Gravity Forms Renderer with Advanced Custom Fields. Dependencies: Gravity Forms Plugin, Gravity-Forms-ACF-Field https://github.com/stormuk/G

Gravity Forms Renderer with Advanced Custom Fields. Dependencies: Gravity Forms Plugin, Gravity-Forms-ACF-Field https://github.com/stormuk/Gravity-Forms-ACF-Field http://www.gravityhelp.com/documentation/gravity-forms/user-guides/getting-started/embedding-a-form/

<?php

/**
 * Advanced Custom Fields Get Image Tag From Image Object
 * Dependencies: Gravity Forms  Plugin, https://github.com/stormuk/Gravity-Forms-ACF-Field
 * Usage:
 * <code>
 * $args = array(
 *     '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) Pass an array of dynamic population parameter keys with their corresponding values to be populated. Example, "array('parameter_name' => 'custom_value')". Defaults to false
 *     'ajax' => (boolean),         				// (optional) Whether or not to use AJAX for form submission.
 *     'tabindex' => (integer)   					// (optional) Specify the starting tab index for the fields of this form. Defaults to troe.
 * );
 *
 *  $args = array( 'display_title' => , 'display_description' => , 'display_inactive' => , 'field_values' => , 'ajax' => , 'tabindex' => );
 *  yanco_render_gravityform('acf_gravity_form_field_name', $args);
 *	</code>
 */

if(!function_exists('yanco_render_gravityform'))
{
	function yanco_render_gravityform($acf_gravity_form_field_name, $args)
	{
		  $display_title = false;
	    $display_description = false;
	    $display_inactive = false;
	    $field_values = null;
	    $ajax = true;
	    $tabindex = 0;

	    if( array_key_exists( 'display_title', $args ) )
       		$display_title = $args['display_title'];

	    if( array_key_exists( 'display_description', $args ) )
	        $display_description = $args['display_description'];

	    if( array_key_exists( 'display_inactive', $args ) )
	        $display_inactive = $args['display_inactive'];

	    if( array_key_exists( 'field_values', $args ) )
	        $field_values = $args['field_values'];

	    if( array_key_exists( 'ajax', $args ) )
	        $ajax = $args['ajax'];

	    if( array_key_exists( 'tabindex', $args ) )
	        $tabindex = $args['tabindex'];

  		if( get_field($acf_gravity_form_field_name) )
  		{
  			$form = get_field($acf_gravity_form_field_name);
  			gravity_form_enqueue_scripts($form->id, true);
  			gravity_form($form->id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex);
  		}
  		else if(get_field($acf_gravity_form_field_name, 'option'))
  		{
  			$form = get_field($acf_gravity_form_field_name, 'option');
  			gravity_form_enqueue_scripts($form->id, true);
  			gravity_form($form->id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex);
  		}
	  }
}

?>