Last active
August 29, 2015 13:58
-
-
Save remcotolsma/10357847 to your computer and use it in GitHub Desktop.
Gravity Forms readonly fields (no JavaScript).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Read only | |
* | |
* @param string $field_content | |
* @param array $field | |
* @return string | |
*/ | |
function prefix_gform_field_readonly( $field_content, $field ) { | |
if ( isset( $field['cssClass'] ) && false !== strpos( $field['cssClass'], 'readonly' ) ) { | |
$attr = 'readonly="readonly"'; | |
if ( false === strpos( $field_content, $attr ) ) { | |
$search = array( | |
'<input ', | |
'<textarea ', | |
'<select ', | |
); | |
$replace = array( | |
"<input $attr ", | |
"<textarea $attr ", | |
"<select $attr ", | |
); | |
$field_content = str_replace( $search, $replace, $field_content ); | |
} | |
} | |
return $field_content; | |
} | |
add_filter( 'gform_field_content', 'prefix_gform_field_readonly', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment