WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
'Auto' fill in parts of the form? (4 posts)

  1. kuran
    Member
    Posted 2 years ago #

    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'

  2. Evan Jacobs
    Member
    Posted 2 years ago #

    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...

  3. kuran
    Member
    Posted 2 years ago #

    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>
  4. featheredowl
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic