Set Fields as Readonly On Edit

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

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.

Code

Filename: gpro-readonly-on-edit.php

<?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 Entry Blocks or 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.
 *
 * 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.1
 * Author URI:   https://gravitywiz.com/
 */

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';

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

	return $form;
}

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.