Title: How to use PHP code inside readonly input field ?
Last modified: February 4, 2017

---

# How to use PHP code inside readonly input field ?

 *  [totallywp](https://wordpress.org/support/users/panatapattu/)
 * (@panatapattu)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/how-to-use-php-code-inside-readonly-input-field/)
 * I have a form and I need to use a readonly input for the Subject field. Therefore
   I need to use current page title (<?php the_title(); ?>). How can I achieve this
   inside Contcat Form 7. Here is my code for the Subject,
 * <div class=”form-group”>
    <label for=”selectedPackage”>Selected Package</label
   > <input type=”text” class=”form-control” id=”selectedPackage” value=”‘.the_title().'”
   placeholder=”Your Package” readonly /> </div>
 * I surf the internet but I couldn’t find anything helpful. Even in the plugin 
   docs.
 * Thanks

Viewing 1 replies (of 1 total)

 *  [redsand](https://wordpress.org/support/users/redsand/)
 * (@redsand)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/how-to-use-php-code-inside-readonly-input-field/#post-8737434)
 * Hi [@panatapattu](https://wordpress.org/support/users/panatapattu/),
 * As far as I know, there isn’t a way to do it in the form itself, and it has to
   be done in post-processing. Your best bet is the `wpcf7_mail_components` filter
   in the `WPCF7_Mail` class.
 * You would need to add some code to your theme file’s custom `functions.php` file.
   The best way to do this is to _not edit theme files directly_, but rather make
   a child theme, and edit the `functions.php` file. Something like this _should_
   work:
 *     ```
       if( defined( 'WPCF7_VERSION' ) ) {
       	add_filter( 'wpcf7_mail_components', 'your_custom_function', 20 );
       }
   
       function your_custom_function( $components ) {
       	extract( $components );
       	$subject = get_the_title();
       	$components = compact( 'subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments' );
       	return $components;
       }
       ```
   
 * This exact script isn’t tested yet, but is similar to one we use. It might need
   some tweaking, but at least this should get you started.
 * Hope that helps!
 * – Scott

Viewing 1 replies (of 1 total)

The topic ‘How to use PHP code inside readonly input field ?’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [readonly](https://wordpress.org/support/topic-tag/readonly/)
 * [the_title](https://wordpress.org/support/topic-tag/the_title/)
 * [wp function](https://wordpress.org/support/topic-tag/wp-function/)

 * 1 reply
 * 2 participants
 * Last reply from: [redsand](https://wordpress.org/support/users/redsand/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/how-to-use-php-code-inside-readonly-input-field/#post-8737434)
 * Status: not a support question