bookmark_bordergform_shortcode_ACTION

Description

Use this filter to implement custom shortcode actions.

Usage

Specify the action name after the gform_shortcode_ hook name e.g.

add_filter( 'gform_shortcode_form_property', 'custom_action', 10, 3 );

Parameters

  • $string string

    The current shortcode text.

  • $attributes array

    Array of the shortcode attributes.

        array (
             'id' => '22',
             'name' => 'Poll',
             'action' => 'form_property',
             'property' => 'title'
        );
        

  • $content string

    The content text of the shortcode if it exists.

Examples

The example below has the following shortcode setup on a page:

&lbrkt;gravityform id="22" name="Poll" action="form_property" property="title"&rbrkt;
my content
&lbrkt;/gravityform&rbrkt;

…and uses the following hook setup with the action “form_property”. The “property” is retrieved and used to display the title of the form.

add_filter( 'gform_shortcode_form_property', 'custom_action', 10, 3 );
function custom_action( $string, $attributes, $content ) {
    //get the shortcode attributes into variables, default values set for some
    //the "property" attribute set in the shortcode has been added to the shortcode array
    extract( shortcode_atts( array(
         'title' => true,
         'description' => true,
         'id' => 0,
         'name' => *,
         'field_values' => "",
         'ajax' => false,
         'tabindex' => 1,
         'action' => 'form',
         'property' => *
    ), $attributes ) );
    $form = RGFormsModel::get_form_meta( $id ); //get the form object
    $property_value = $form[ $property ]; //retrieve the "property" from the form object
    $info = "The property to retrieve is {$property} with value {$property_value}.";
    return $info;
}

Placement

This code may be placed in the functions.php file of your active theme OR in your plugin code.

Source Code

This filter is located in GFForms::parse_shortcode() in gravityforms.php.