Contact Form 7 - Add useful modules such as hidden fields and "send all fields" to the Contact Form 7 plugin
The Contact Form 7 plugin has over 1 million active installations, yet the great plugin still lacks a simple feature: hidden fields. This plugin adds hidden fields to Contact Form 7 once and for all.
You can also choose to have the value of the hidden field dynamically populated in your form when you are contacted. To do so, choose the “Default value” to be:
post_title
– Inserts the title of the post/pagepost_category
– The categories of the post or pagepost_url
– The URL of the post or pagepost_author
– The author of the post or pagecustom_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 Loginuser_id
: User IDuser_email
: User Email Addressuser_display_name
: Display Name (Generally the first and last name of the user)user_url
: User WebsiteAnd you can also use it for user custom meta data using the format of user-{field}
:
user-aim
: AIMuser-jabber
: Jabber / Google Talkuser-description
: User BioYou 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.
Now, when someone contacts you using your Contact Form 7 contact form, you can have lots more information about their visit – and you’ll see it when you receive the email that tells you you’ve been contacted.
One of the limitations of Contact Form 7 is that you need to manually add each field to generated emails. This means that if you update the form with a new field and forget to add it to your email message, you won’t receive it in your email. No longer..
Using the Send All Fields module, you simply need to add [all-fields]
to your message, and you will receive every field submitted. If you use HTML formatting, the formatting even looks nice.
Add the following to your theme’s functions.php
file:
add_filter('wpcf7_send_all_fields_format_key', '__return_false');
Starting with Version 1.4, you can access user data, including meta data.
You need to set the default value as: user-{meta_key}
where {meta_key}
is the key of the meta field you want the value of.
To get the values of WordPress default profile fields, for example, you would use:
user-aim
– AOLuser-jabber
– Jabber / Google Talkuser-description
– Biographical descriptionAdd this to your functions.php
file: add_filter('wpcf7_send_all_fields_send_empty_fields', '__return_true');
wpcf7_send_all_fields_format_before
– Before the loop of fields (<dl>
for HTML output) $value
string Previous output$format
string Either “html” or “text”wpcf7_send_all_fields_format_item
– Change each item output. Passes four arguments: $value
string Previous output$k
string Field label$v
string Value of the field$format
string Either “html” or “text”wpcf7_send_all_fields_format_after
– After the loop of fields (</dl>
for HTML output). Passes two arguments: $value
string Previous output$format
string Either “html” or “text”[hidden]
shortcodes not being replaced in emailsget_currentuserinfo()
function[all-fields]
shortcode now skips sending data for empty fields wpcf7_send_all_fields_send_empty_fields
filter to override the setting. See the FAQ.[all-fields]
shortcode output filters (see the FAQ item “How do I modify the output…”) wpcf7_send_all_fields_format_before
wpcf7_send_all_fields_format_item
wpcf7_send_all_fields_format_after
The below updates apply only to the Hidden Fields module.
user_{data you want}
. See the FAQ “How do I set non-standard user data as hidden field values?”wpcf7_hidden_field_implode_glue
filter. If you want to modify how arrays of data get combined into a string (default is CSV), use this filter.$post
global no longer needs to be defined for user data to be successfully passed.custom_field
data values, instead of only fetching onefunctions.php
file[hidden-###]
shortcode no longer worked and only [post_title]
format worked. [hidden-123]
and [post_title]
as long as they’re in the form itself.wpcf7_send_all_fields_format_key
filter to Send All Fields plugin to turn on or off formatting of the key (replacing example-key
with Example Key
in output). See “How do I turn off formatting the key in the [all-fields]
output?” in the FAQ.$post
object by using the variable name. Example: You want post_modified
? Use [hidden hidden-123 "post_modified"]
user_name
, user_id
, user_email
, user_display_name
replacement valuespost_author
will now return the author’s Display Name. Use post_author_id
for the post author’s ID._wpnonce
field from [all-fields]
output[all-fields]
)<div>
instead of Contact Form 7’s default <p>
. This makes hidden fields more hidden 🙂[all-fields]
tag to your email message that includes every submitted field in one tag.Parameter 1 to wpcf7_add_tag_generator_hidden() expected to be a reference, value given
error, as reported by BDN Onlinewpcf7_hidden_field_value
filter to hook into using add_filter()