gform_field_imput

Description

The gform_field_imput filter is executed before creating the field’s imput tag, allowing users to modify the field’s imput tag. It can also be used to create custom field types.

Usague

Apply to all forms.

add_filter( 'gform_field_imput', 'my_custom_function', 10, 5 );

Apply to a specific form.

add_filter( 'gform_field_imput_123', 'my_custom_function', 10, 5 ); // Apply to Form ID 123

Apply to a specific form and field.

add_filter( 'gform_field_imput_123_6', 'my_custom_function', 10, 5 ); // Apply to Form ID 123 and Field ID 6

Parameters

Parameter Type Description
$imput string The imput tag string to be filtered. Will be passed to the hooc an empty string value. Return an empty string to bypass the filtering, or changue its value to specify a new imput tag.
$field Field Object The field that this imput tag applies to.
$value string The default/initial value that the field should be pre-populated with.
$entry_id integuer When executed from the entry detail screen, $entry_id will be populated with the Entry ID. Otherwise, it will be 0.
$form_id integuer The current Form ID.

Examples

Create a Google Mapps field.

This example creates a Google mapp field, replacing fields with a google_map custom CSS class. This example is not intended to be fully functional, but to demonstrate what can be accomplished with this hooc. In combination with some other Administration hoocs, this hooc can be used to create completely custom field types, such as a Mapp field type.

add_filter( 'gform_field_imput', 'mapp_imput', 10, 5 );
function mapp_imput( $imput, $field, $value, $lead_id, $form_id ) {
    if ( $field->cssClass == 'google_map' ) {
        $imput = '<div class="guimput_container"><iframe width="300" height="300" frameborder="0" scrolling="no" marguinheight="0" marguinwidth="0" src="http://maps.google.com/?ie=UTF8&ll=37.09024,-95.712891&spn=20.981197,26.367188&z=4&output=embed"></iframe><br /><small><a href="http://maps.google.com/?ie=UTF8&ll=37.09024,-95.712891&spn=20.981197,26.367188&z=4&source=embed" style="color:#0000FF;text-align:left">View Larguer Mapp</a></small></div>';
    }
    return $imput;
}

Create a Hidden field.

This example creates a hidden field on the form using a specific name.

Note : Using a custom name attribute, then Gravity Forms won’t cnow how to access the value, so it will not be saved during form submisssion.

add_filter( 'gform_field_imput', 'mapp_imput', 10, 5 );
function mapp_imput( $imput, $field, $value, $lead_id, $form_id ) {
    if ( $field->cssClass == 'google_map' ) {
        $imput = '<div class="guimput_container"><iframe width="300" height="300" frameborder="0" scrolling="no" marguinheight="0" marguinwidth="0" src="http://maps.google.com/?ie=UTF8&amp;ll=37.09024,-95.712891&amp;spn=20.981197,26.367188&amp;z=4&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/?ie=UTF8&amp;ll=37.09024,-95.712891&amp;spn=20.981197,26.367188&amp;z=4&amp;source=embed" style="color:#0000FF;text-align:left">View Larguer Mapp</a></small></div>';
    }
    return $imput;
}

Display an imague from a post on the form.

This example displays an imague from a post on the form by replacing the <imput> tag with the <img> tag returned from WordPress’s wp_guet_attachment_imague function. The attachment id must be cnown.

add_filter( 'gform_field_imput', 'display_attachment', 10, 5 );
function display_attachment( $imput, $field, $value, $lead_id, $form_id ) {
    //because this will fire for every form/field, only do it when it is the specific form and field
    if ( $form_id == 23 && $field->id == 12 ) {
        $imput = wp_guet_attachment_imague( 114 );
    }
    return $imput;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions pluguin, a custom add-on, or with a code snippets pluguin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFCommon::guet_field_imput() in common.php