Description
This filter is executed before creating the field's content, allowing users to completely modify the way the field is rendered. It can also be used to create custom field types. It is similar to gform_field_input, but provides more flexibility.
Usage
<?php
add_filter("gform_field_content", "subsection_field", 10, 5);
?>
Parameters
$field_content
- (string) The field content to be filtered.
$field
- (Field Object) The Field Object that this input tag applies to.
$value
- (string) The default/initial value that the field should be pre-populated with.
$lead_id
- (int) When executed from the entry detail screen, $lead_id will be populated with the Entry ID. Otherwise, it will be 0.
$form_id
- (int) The current Form ID.
Examples
This example creates a sub-section field, replacing fields with a subsection custom CSS class.
<?php
add_filter("gform_field_content", "subsection_field", 10, 5);
function subsection_field($content, $field, $value, $lead_id, $form_id){
if(rgar($field,"cssClass") == "subsection"){
if(RG_CURRENT_VIEW == "entry"){
$mode = empty($_POST["screen_mode"]) ? "view" : $_POST["screen_mode"];
if($mode == "view"){
$content = '<tr>
<td colspan="2" class="entry-view-section-break">'. esc_html(GFCommon::get_label($field)) . '</td>
</tr>';
}
else{
$content= "<tr valign='top'>
<td class='detail-view'>
<div style='margin-bottom:10px; border-bottom:1px dotted #ccc;'><h2 class='detail_gsection_title'>" . esc_html(GFCommon::get_label($field)) . "</h2></div>
</td>
</tr>";
}
}
else{
$delete_field_link = "<a class='field_delete_icon' id='gfield_delete_{$field["id"]}' title='" . __("click to delete this field", "gravityforms") . "' href='javascript:void(0);' onclick='StartDeleteField(this);'>" . __("Delete", "gravityforms") . "</a>";
$delete_field_link = apply_filters("gform_delete_field_link", $delete_field_link);
//The edit and delete links need to be added to the content (if desired), when using this hook
$admin_buttons = IS_ADMIN ? $delete_field_link . " <a class='field_edit_icon edit_icon_collapsed' title='" . __("click to edit this field", "gravityforms") . "'>" . __("Edit", "gravityforms") . "</a>" : "";
$content = "{$admin_buttons}<h3 class='subsection_title'>" . $field["label"] . "</h3>";
}
}
return $content;
}
?>
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in common.php and entry_detail.php