To make text field as read-only in contact form 7 WordPress plugin, you just need to add few lines of code to text.php under modules in contact form 7. You can find the text.php in the below url.
Advertisements
“wp-content/plugins/contact-form-7/modules/text.php”
If you are in cpanel then use code editor or else, if you like to test it locally then use any text editor to edit it.
Once you open the text.php in code editor or in any text editor, go to line number 55. You will find the below code / line.
Advertisements
“$value = (string) reset( $values );”
After finding the above code / line, Just copy and paste the below code under it.
[code lang=”PHP”]if ( wpcf7_script_is() && preg_grep( ‘%^readonly$%’, $options ) ) {
$atts .= ‘ readonly="readonly"';
}[/code]
Check the below screen shot to confirm how the code looks like after modifying it.
After modifying it , if you are using code editor in cpanel go to line number 219, else go to line number 214. You will find the below code / line.
“<br /><input type=”checkbox” name=”watermark” /> <?php echo esc_html( __( ‘Use this text as watermark?’, ‘wpcf7′ ) ); ?>”
After finding the above line, just copy and paste the below code under it.
[code lang=”PHP”]<br /><input type="checkbox" name="readonly" class="option" /> <?php echo esc_html( __( ‘Make this text as readonly?’, ‘wpcf7′ ) ); ?>[/code]
Check the below screen shot.
That’s it, Now save the file and close it
To add
Now open Contact Form 7 and add the text field as read-only. In Contact Form 7 settings select Text Field from General Tag.
Once you have selected the Text Field, you can find the check box with the value “Make this text as readonly?” near the Default value input box. Just select that check box to make the text field readonly. Check the below screen shot.
Or you can directly add “readonly” to a text field in Contact Form 7 as shown below. But make sure that you have added the above lines of code to your text.php.
Example 1
[code][[text* your-name readonly "12345"]][/code]
Example 2
[code][[text your-subject readonly "Readonly"]][/code]
Hope this will be helpful for you!!!