Contact Form 7 (CF7) provides many features to make your forms as simple or complex as you need. One of these important features is the ability to use Default Values in your form fields.
In this article, we will show you how to use default values from HTTP requests in your CF7 forms.
When to use default values in your forms
It’s useful to implement default values in form fields for a variety of cases:
- Help your user fill out a form faster.
- If your forms target registered users of the site.
- If the form needs to be called with a different default value depending on the referrer of the form.
- When you have a fixed value for a field but still need to display it to the user.
Getting default values from HTTP requests
You can use the value of either the GET request or the POST request to use as the default value in your forms.
GET
Use the “get” keyword in the form tagForm Tag Form Tags in Contact Form 7 (CF7) (in the Form Tab) are used to define all CF7 form fields. Each Form Tag is replaced with an HTML element, which represents an input field, when it is displayed in an actual form. to get the default value from HTTP GET variables.
[text* name default:get]
Now, you can access the page containing the form using a similar URL:
http://www.yoursite.com/form-page/?name=Clarke
You will now see the value sent via GET in your form.
Note: The name of the GET variable must be the same as the name of the form tag for this to work.
POST
The use of POST is very similar to that of GET. You have to use the “post” keyword in the form tag to get the default value from HTTP POST variables.
[text* name default:post]
Now, when you access this page via a POST request with the variable “name” sent, you will see the value of the variable in your form.
Example
The following form will have the default subject value as “Inquiry” when a GET variable with that name is sent. Use the following URL to test this:
Form Code
Further reading
- Contact Form 7 – Getting Default Values from the Context
- Contact Form 7 – Setting Default Values to the Logged-In User
- Getting default values from post meta in Contact Form 7
- Using multiple default values in Contact Form 7
- Getting default values from logged-in user in Contact Form 7
Have questions or need help?
If you are using the free version of CF7 Skins, you can get help via the CF7 Skins community and also the Contact Form 7 Support forum.
If you are using any of our Add-ons, we provide Premium Email Support to help with your questions and problems.