WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Contact Form 7] 'Auto' fill in parts of the form?

[Plugin: Contact Form 7] 'Auto' fill in parts of the form?

  • Happy holidays everyone!

    I have a button on a page that leads to a Contact Form 7 form. Is it possible to have the button automatically fill in one of the text fields on that form?

    http://wordpress.org/extend/plugins/contact-form-7/

    For example, if the form button is on a page with a Tomato, the form would have the ‘name’ input field filled in with ‘Tomato’

Viewing 3 replies - 1 through 3 (of 3 total)
  • I believe you can use PHP within the CF7 designer. You could append #tomato to the end of the link leading to the page and then use PHP to pull the text after the hash in the URL for the “name” value.

    So you could do…

    <?php $field = strtok($_SERVER["REQUEST_URI"], "#"); ?>

    and then echo $field…

    Hi Evan,

    Thanks for responding, and Happy New Year!

    I added example code of a simple form, where on it would I place the <?php — ?> string? At the top?

    And if I want the contents after the hash to go in my Subject field, where do I put the ‘echo’ string?

    Thanks so much for your help!

    <div class="formleft">
        [text* your-name class:forminput watermark "Your Name *"]
        [text* company-name class:forminput watermark "Company Name *"]
        [email* your-email class:forminput watermark "Your Email *"]
    </div>
    
    <div class="formright">
        [text* your-subject class:forminput watermark "Subject *"]
    </div>
    
    <div class="buttonsend">
    [submit class:submit_button "Send"]
    </div>
    
    <div class="response">
    [response]
    </div>
    featheredowl
    Member

    @featheredowl

    You can also do it using the Contact Form 7 Dynamic Text Extension plugin and a URL query variable, see auto populate contact form 7 input field on my blog for details

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Contact Form 7] 'Auto' fill in parts of the form?’ is closed to new replies.