07 Nov 2011

Contact Form 7: Get Parameter from URL into Form Plugin

Wordpress 22 Comments

Updated 11/18/2012

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 GetParam Here

Installation

  • Copy the getparam.php file into: /wp-content/plugins/contact-form-7/modules/

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.

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

  1. efendi says:

    great! really! very thank you!

  2. Bo Kylberg says:

    Hello!
    How do I display the content of the value in the form before Submit…?
    rgds
    Bo

  3. chad says:

    Bo,

    That sounds like a good idea for an update to the plugin, I will put that in my schedule to work on.

  4. Kobi says:

    Hi…

    Displaying the parm in the submit form is exaclty what I need!

    Please help us Chad!

    Thanks

  5. chad says:

    @Kobi, I have updated the plugin to include that functionality.

  6. chad says:

    @Bo Kylberg, I have updated the plugin to include the “showparam” shortcode. This will allow you to display the value on the form.

  7. Krish A Manohar says:

    Awesome plugin…. Search everywhere … was about to go write one.

  8. Передача параметра Get в форму Contact Form 7 | Wordpress inside says:

    [...] К счастью, такое решение уже существует – это GetParam. С помощью данного хака вы можете передать в форму Contact [...]

  9. Jason says:

    Hi guys,

    I am pretty new to this and your plugin is exactly what i need. Could you please walk me through in a few steps what exactly i do here?

    I have been playing around with the contact form but cant seem to get it right.

    I appreciate your time.

    Jason

  10. chad says:

    Jason,

    What issues are you having with it exactly? If you follow the instructions on this page you should be up and running.

  11. Phil says:

    Works like a charm….. and it gives greater field control. I wanted to set the field to be a text field and it did so. I also set the field as read only and it worked.
    Thanks man :-)

  12. Jason says:

    Hi Chad

    Thanks for the reply, i am a wordpress novice so please forgive me here. I have figured out how to get the hidden fields in contact form but not sure what to enter in the 3 fields, name id and default value. no matter where is enter the shortcode [getparam affid] i cannot get the email to work.

    yes i have the file getparam.php in /wp-content/plugins/contact-form-7/modules/ and my URL string is domain/page?affid=1

    thanks
    Jason

  13. chad says:

    Jason,

    As long as you have [getparam affid] with the url: domain/page?affid=1, you will be able to return the value in the email form by inputting [affid] into the email form (in this case, the email form will display “1″ in place of [affid]).

    I hope that helps!

  14. devrawat says:

    SWEET…. you saved my lot of time…. thanks…

  15. ladypop2012 says:

    Hello @Jason

    First I wanna say thank you for creating this I was looking EXACTLY for this. I have the plugin module working, however I wanted to ask you about this tricky scenarios im experiencing.

    #1. I have my aff script code set to HIDE the AFF URL once the visitor lands on my site. So what happens is when a visitor for example clicks http://www.ABC.com/Survey/?aff_id=joe When they visitors arrive at my site the URL in the browser will only have http://www.ABC.com/survey The aff id is saved as a cookie at this point.

    ISSUE: when the visitor fills out the survey form (contact form 7) I have your code set to look for aff_id from the URL parameter, but since my site is hiding the URL once the visitor land on the page, your code is NOT grabbing the AFF_ID. and passing it into my contact form

    Possible: Solution Is there a way I can or code, GET the current COOKIE on the users browser for AFF_ID

    Possible: Solution GET the hidden URL before the AFF_ID is dropped

    I know your code works because I tested on DO NOT HIDE AFF_id and it grabs it just fine. but In my case my site I really need to drop the aff id when the visitor arrives for other reasons. thanks so much

  16. Chris says:

    Great plugin mate! Very useful!

  17. Zeally7 says:

    Thank you very much for this enhance :D

  18. Mike says:

    I am really curious why this doesn’t work for me , guys.
    Maybe I am blundering terribly ?

    Here is my code :

    In the page there exists this link

    http://example.com/page?tp=orange

    In the Contact Form 7, among other things :

    [showparam tp]

    I have copied the .php file in the plugins’s directory and permissions are 644, but I get this :

    [showparam tp]

    on the browser page, so I believe the short code doesn’t translate properly.

    I would appreciate some help :( ((

  19. chad says:

    Mike, triple-check that the plugin is installed correctly! Also, maybe try more relaxed permissions? 777 just to verify it is working. If so, then bring those down a bit.

  20. michauko says:

    Many thanks !!!!
    I just wanted to check some key in the $_GET and pass it on silently to the WP Contact-Form
    First link on Google !

    works out-of-the-box ; chmod 644 is enough (see post above)

  21. JohnLenin says:

    This plugin works great, but I’d like to do something similar to what Phil has done “I wanted to set the field to be a text field and it did so. I also set the field as read only and it worked.” @Phil, how did you do that, could you share what you put into your Form? @Chad maybe you know how to do this?

  22. Mike says:

    Chad, thank you ! It was a silly mistake : instead of copying into /modules, the .php was copied to the upper directory . Now working like a breeze ;-)

Leave a Reply