This is an Advanced Custom Field custom field to select one or many Gravity Forms.
This provides a field that lets you select from a list of active Gravity Forms.
This add-on will work with:
- version 4
- Version 5
This add-on can be treated as both a WP plugin and a theme include.
Plugin
- Copy the 'Gravity-Forms-ACF-field' folder into your plugins folder
- Activate the plugin via the Plugins admin page
Include
- Copy the 'Gravity-Forms-ACF-field' folder into your theme folder (can use sub folders). You can place the folder anywhere inside the 'wp-content' directory
- Edit your functions.php file and add the code below (Make sure the path is correct to include the acf-gravity_forms.php file)
include_once('acf-gravity_forms.php');
The field lets you pick one or many fields.
The data returned is either a Form object, an array of Form objects or false if an error occurred.
If you have selected a single form and you want to display the form on the page, you can use:
<?php
$form_object = get_field('your_form_field');
gravity_form_enqueue_scripts($form_object['id'], true);
gravity_form($form_object['id'], true, true, false, '', true, 1);
?>
or
<?php
$form_object = get_field('your_form_field');
echo do_shortcode('[gravityform id="' . $form_object['id'] . '" title="true" description="true" ajax="true"]');
?>
You can find out more about the gravity_form method to embed a form on a page in their documentation
If you are using the field to select multiple forms, you will have to iterate over the array. You can then use the form object as you like:
<?php
$form_objects = get_field('your_forms');
foreach($form_objects as $form){
echo $form['title'];
}
?>
Version: 1.2
Written by Adam Pope and Liam Gladdy of Storm Consultancy and the amazing contributors on Github
Storm Consultancy are a web design and development agency based in Bath, UK.
If you are looking for a Bath WordPress Developer, then get in touch!
Thanks for Lewis Mcarey for the Users Field ACF add-on on which we based this - https://github.com/lewismcarey/User-Field-ACF-Add-on
Thanks to rocketgenius for the Gravity Forms plugin!