• 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)
  • Hi @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.