The gform_field_input filter in Gravity Forms allows you to modify the field’s input tag or create custom field types before the input tag is created.
Usage
// Apply to all forms add_filter('gform_field_input', 'my_custom_function', 10, 5); // Apply to a specific form add_filter('gform_field_input_123', 'my_custom_function', 10, 5); // Apply to a specific form and field add_filter('gform_field_input_123_6', 'my_custom_function', 10, 5);
Parameters
$input
(string) – The input tag string to be filtered. Pass an empty string to bypass filtering or change its value to specify a new input tag.$field
(Field Object) – The field that this input tag applies to.$value
(string) – The default/initial value that the field should be pre-populated with.$entry_id
(integer) – The Entry ID when executed from the entry detail screen, otherwise 0.$form_id
(integer) – The current Form ID.
More information
See Gravity Forms Docs: gform_field_input
Examples
Create a Google Map field
Replace fields with a google_map
custom CSS class to create a Google Map field.
add_filter('gform_field_input', 'map_input', 10, 5); function map_input($input, $field, $value, $lead_id, $form_id) { if ($field->cssClass == 'google_map') { $input = '<div class="ginput_container"><iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="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 Larger Map</a></small></div>'; } return $input; }
Create a hidden field with a custom name
Create a hidden field on the form using a specific name. Note that Gravity Forms won’t save the value during form submission if you use a custom name attribute.
add_filter('gform_field_input', 'tracker', 10, 5); function tracker($input, $field, $value, $lead_id, $form_id) { if ($form_id == 23 && $field->id == 11) { $input = '<input type="hidden" id="hidTracker" name="hidTracker" value="test">'; } return $input; }