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

  1. kuran
    Posted 4 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?


    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
    Posted 4 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
    Posted 4 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 class="formright">
        [text* your-subject class:forminput watermark "Subject *"]
    <div class="buttonsend">
    [submit class:submit_button "Send"]
    <div class="response">
  4. featheredowl
    Posted 3 years 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

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic