07 Nov 2011

Contact Form 7: Get Parameter from URL into Form Plugin

Wordpress 59 Comments

Updated 3/10/2014
-Update shortcode init for Contact Form 7 3.7.2

There are times when using the Contact Form 7 WordPress plugin where I need to pass a parameter from the URL and into a hidden field or display it in the form. This is great for passing things such as order numbers, selected packages, or even security information.

Download Contact Form 7 – GetParam (v0.9.6)

Automatic Installation

  • It is listed in the WordPress Plugin directory, so you will be able to find it in your WordPress installation’s plugin browser

Manual Installation

  • Go to the “Plugins” section of your WordPress admin panel
  • Click “Add New” at the top
  • Click “Upload” at the top
  • Upload the downloaded zip file
  • Activate the plugin through the ‘Plugins’ menu in WordPress

Adding a Hidden Field

When editing a form in Contact Form 7, enter the getparam shortcode. There is only one valid parameter which is the name of the $_GET value.

[getparam value]

For example, if the URL is http://mysite.com/contact?ordernum=12345, the shortcode will be:

[getparam ordernum]

Then when building the response email, you can pass the value with [ordernum]

Showing the $_GET Value on the Form

When editing a form in Contact Form 7, enter the showparam shortcode. There is only one valid parameter which is the name of the $_GET value.

[showparam value]

For example, if the URL is http://mysite.com/contact?ordernum=12345, the shortcode will be:

[showparam ordernum]

You cannot pass a value to the response email using this method, to do that, you will also have to add a hidden field.

59 Responses to “Contact Form 7: Get Parameter from URL into Form Plugin”

  1. Igor says:

    Chad, I did it. Thank you again.

  2. klusterama says:

    Hi,
    very interesting, but how do i fiil the contact form value in the CTF7 form builder?

    Example: inserting an hidden input name “hidden-ordernu” width id=”myID” autofilled by querystring params “ordernum” you will enter this?

    [hidden hidden-ordernum id:myID [getparam ordernum]]

    Thank you in advance

  3. chad says:

    @klusterama: Just use [getparam ordernum], that will automatically create a hidden element for you to use.

  4. Ahmed Hussein says:

    Please write some tutorial for the non developers how to use it in the form and what to do to achieve it.

    Thank you

  5. chad says:

    @Ahmed,

    I recommend going through the official Contact Form 7 docs to get a better understanding of how this plugin works: http://contactform7.com/docs/

  6. Ken Stadden says:

    Chad,

    First of all, thank you for this function/plugin, which I’ve used for a while now with great success. It filled an important need.

    The latest version crashes my website, however. with this message:
    Fatal error: Call to undefined function wpcf7_add_shortcode() in /home/content/21/3814121/html/wp/wp-content/plugins/contact-form-7-get-and-show-parameter-from-url/getparam.php on line 31

    Can you look into this? I can’t imagine this issue is mine alone.

    Thanks-

    Ken S.

  7. chad says:

    @Ken, the plugin has been updated to 0.9.6 which fixes compatibility with the latest version of Contact Form 7. Thank you for the heads up!

  8. Robert says:

    Hello,

    Thanks for the plugin!
    Is there a way to include the $_GET value in the body?

    Thanks!

  9. chad says:

    @Robert, Are you referring to the body of the form? If so, refer to the showparam shortcode of this plugin.

Leave a Reply