Modifying the output of the Edit Entry form
If you want to modify how the HTML of the fields render in the Edit Entry form, there's a filter you should use: gform_field_content. The key is to use it inside GravityView; add the filter inside the gravityview/edit-entry/render/before action and remove it inside the gravityview/edit-entry/render/after action.
About the gform_field_content filter
You can read a full write-up on the filter—including additional examples—on the Gravity Forms filter documentation page.
Sample code
Here's an example of using the filter to hide fields that have an empty value:
/**
* Add filters to the edit entry inputs when GravityView starts to render an entry.
*/
add_action( 'gravityview/edit-entry/render/before', function() {
// GravityView methods are run at priority 10; by running at 20, this will run after GV.
add_filter( 'gform_field_content', 'gravityview_hide_empty_fields_in_edit_entry', 20, 5 );
} );
/**
* Remove the added filters.
*/
add_action( 'gravityview/edit-entry/render/after', function() {
remove_filter( 'gform_field_content', 'gravityview_hide_empty_fields_in_edit_entry', 20 );
} );
/**
* Modify the Edit Entry field HTML so that inputs aren't displayed for fields with empty values
*
* @param string $content The edit entry field
* @param array $field The Gravity Forms field array, with extra GravityView keys such as `gvCustomClass`
* @param string $value The value of the field
* @param int $entry_id The entry ID
* @param int $form_id The form ID
*
* @return string HTML output for the field in the Edit Entry form
*/
function gravityview_hide_empty_fields_in_edit_entry( $content = '', $field = array(), $value = '', $lead_id = 0, $form_id = 0 ) {
// This code makes the private method `get_field_value()` available publicly.
$reflection = new \ReflectionClass( 'GravityView_Edit_Entry_Render' );
$method = $reflection->getMethod( 'get_field_value' );
$method->setAccessible( true );
$value = $method->invokeArgs( GravityView_Edit_Entry::getInstance()->instances['render'], array( $field ) );
// If the value is empty, return nothing.
if ( '' === $value || is_array( $value ) && ! array_filter( $value ) ) {
return '';
}
// Otherwise, return the original HTML output
return $content;
}
Read here how to add these code samples to your website: Where to put code samples.