Skip to content

Commit fe60e48

Browse files
authored
Create gpro-readonly-when-dynamically-populated.php
1 parent 9bdf860 commit fe60e48

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Read Only // Readonly When Dynamically Populated
4+
* https://gravitywiz.com/documentation/gravity-forms-read-only/
5+
*
6+
* Use this snippet to make fields readonly if they are dynamically populated. You must enable the "Read-only" field
7+
* setting for this functionality to apply.
8+
*
9+
* See video:
10+
*/
11+
add_filter( 'gform_pre_render', function( $form, $ajax, $field_values ) {
12+
13+
foreach ( $form['fields'] as &$field ) {
14+
if ( $field->gwreadonly_enable ) {
15+
$value = GFFormsModel::get_field_value( $field, $field_values, false );
16+
if ( ! $value ) {
17+
$field->gwreadonly_enable = false;
18+
}
19+
}
20+
}
21+
22+
return $form;
23+
}, 10, 3 );

0 commit comments

Comments
 (0)