Grab Your Free 17-Point WordPress Pre-Launch PDF Checklist: [ Ссылка ]
Contact Form 7 - Adding Hidden Fields Using The Contact Form 7 Modules Plugin | WP Learning Lab
Download your exclusive 10-Point WP Security Checklist: [ Ссылка ]
The ability to create hidden fields is one of the major things missing from Contact Form 7. Luckily there's a nice little plugin that will add that ability to CF7 and as a bonus it will allow you to add dynamic data to the hidden fields as well. I'll explain all of that below.
The first thing we have to do is install the Contact Form 7 Modules plugin.
To install this plugin please log into your WordPress dashboard, hover over Plugins and then click on Add New.
On the next page type "Contact Form 7 Modules" into the search bar. The plugin we want should be the first one in the top left.
Click on the Install Now button and then click Activate after it's installed.
Now go to your Contact Form 7 editor (click on the Contact menu item on the side menu, then click Edit below the form you want to add the hidden field to).
Inside the editor you will see a button labelled "hidden". If you click inside the editor where your form code exists and then click on the "hidden" button a dialog box will open up.
Fill in the details and you have your hidden field.
I recommend you use a descriptive name for the Name field so that you know what the hidden field is for.
Then in the Value field you can enter a shortcode for dynamic content. Some of the available short codes and what they do are listed there and the rest are on this page ([ Ссылка ]).
I've compiled them all below, so you can read them right in the description.
- post_title - Inserts the title of the post/page
- post_category - The categories of the post or page
- post_url - The URL of the post or page
- post_author - The author of the post or page
- custom_field-[Name] - The value of a post or page's custom field. If you had a custom field "Foo", you would use the following as the hidden field value: custom_field-Foo
The following values will be replaced if an user is logged in:
- user_name: User Login
- user_id: User ID
- user_email: User Email Address
- user_display_name: Display Name (Generally the first and last name of the user)
- user_url: User Website
And you can also use it for user custom meta data using the format of user-{field}:
- user-aim: AIM
- user-jabber: Jabber / Google Talk
- user-description: User Bio
You can also use a filter: hook into the wpcf7_hidden_field_value filter to modify the value of the hidden field using add_filter(). If you know the ID of the input, you can also use the wpcf7_hidden_field_value_[#ID] filter.
There are lots of options for adding dynamic content to your hidden fields.
If the content you want to add is different that what the shortcodes provide then you will have to create a Javascript/jQuery and CSS solution.
Using those technologies what you can insert into hidden fields on a form is only limited by your imagination.
Don't forget, after you add the hidden fields to the form, you have to add them to the mail tab as well. Otherwise the information won't be sent to in the email that the form generates.
If you want to know more about customizing the email sent in the mail tab check out this tutorial: [ Ссылка ]
I hope this information helps you! If you have any questions leave a comment below or ping me @WPLearningLab on Twitter.
--------------
If you want more excellent WordPress information check out our website where we post WordPress tutorials daily.
[ Ссылка ]
Connect with us:
WP Learning Lab Channel: [ Ссылка ]
Facebook: [ Ссылка ]
Twitter: [ Ссылка ]
Google Plus: [ Ссылка ]
Pinterest: [ Ссылка ]
Ещё видео!