Set Fields as Readonly On Edit

This snippet allows you to set read only for fields when editing.

Instructions

See “Where do I put snippets?” in our documentation for installation instructions.

Usage

  1. Install this code as a plugin or as a snippet.
  2. Add the gpro-readonly-on-edit CSS Class Name to field’s Custom CSS Class setting.
  3. Optionally, set GPRO_READONLY_GF_ENTRIES to true below to also make the fields readonly when editing an entry in the GF Entries edit. Defaults to false so administrators can still correct these values from the Entry Detail view.

Code

Filename: gpro-readonly-on-edit.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
 * Gravity Perks // GP Read Only // Set Fields as Readonly On Edit
 * https://gravitywiz.com/documentation/gravity-forms-read-only/
 *
 * Configure fields to be readonly when editing via Gravity Forms Entries Edit, Entry Blocks, GravityView or Gravity Flow User Input Step.
 *
 * Usage:
 *
 * 1. Install this code as a plugin or as a snippet.
 * 2. Add the `gpro-readonly-on-edit` CSS Class Name to field's Custom CSS Class setting.
 * 3. Optionally, set GPRO_READONLY_GF_ENTRIES to true below to also make the fields
 *    readonly when editing an entry in the GF Entries edit. Defaults to false so
 *    administrators can still correct these values from the Entry Detail view.
 *
 * Plugin Name:  GP Read Only —  Set Fields as Readonly On Edit
 * Plugin URI:   https://gravitywiz.com/documentation/gravity-forms-read-only/
 * Description:  This snippet allows you to set read only for fields when editing.
 * Author:       Gravity Wiz
 * Version:      0.2
 * Author URI:   https://gravitywiz.com/
 */
// Set to true to also apply read-only when editing an entry in the GF Entries.
define( 'GPRO_READONLY_GF_ENTRIES', false );

add_filter( 'gform_admin_pre_render', 'gpeb_set_readonly_on_edit' );
add_filter( 'gform_pre_render', 'gpeb_set_readonly_on_edit' );
add_filter( 'gform_pre_process', 'gpeb_set_readonly_on_edit' );

function gpeb_set_readonly_on_edit( $form ) {

	$is_block = (bool) rgpost( 'gpeb_entry_id' );
	if ( ! $is_block ) {
		$is_block = class_exists( 'WP_Block_Supports' ) && rgar( WP_Block_Supports::$block_to_render, 'blockName' ) === 'gp-entry-blocks/edit-form';
	}

	$is_gravityview  = function_exists( 'gravityview' ) && gravityview()->request->is_edit_entry();
	$is_gravity_flow = rgget( 'lid' ) && rgget( 'page' ) == 'gravityflow-inbox';
	$is_entry_detail = GPRO_READONLY_GF_ENTRIES && GFCommon::is_entry_detail();

	// disable the target field for GPEB, GravityView and Gravity Flow User Input step.
	if ( $is_block || $is_gravityview || $is_gravity_flow || $is_entry_detail ) {
		foreach ( $form['fields'] as &$field ) {
			if ( strpos( $field->cssClass, 'gpro-readonly-on-edit' ) !== false ) {
				$field->gwreadonly_enable = true;
			}
		}
	}

	return $form;
}

add_filter( 'gform_field_input', function( $input_html, $field ) {
	if ( GPRO_READONLY_GF_ENTRIES && GFCommon::is_entry_detail_edit() && rgar( $field, 'gwreadonly_enable' ) ) {
		add_filter( 'gform_is_entry_detail', '__return_false' );
	}

	return $input_html;
}, 9, 2 );

add_filter( 'gform_field_input', function( $input_html ) {
	remove_filter( 'gform_is_entry_detail', '__return_false' );

	return $input_html;
}, 12 );

Comments

  1. gahuml2
    gahuml2 August 13, 2025 at 9:52 am

    We’re seeing a repeatable issue with a Gravity Forms List field when editing entries via GravityView → Edit Entry. The List field is made read-only on edit using the this snippet. When the entry is updated, one row is removed on each save. This happens every time we edit and save.

    Reply
    1. Matt Andrews
      Matt Andrews Staff August 13, 2025 at 11:27 am

      Hi there,

      I’ve tested this on my end, but haven’t been able to reproduce the issue so far. I see you have an active Gravity Perks license, so I’ve followed up via email for some additional information about the issue.

      Best,

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.