This shortcode returns the values of a specified cookie. This shortcode requires a value for the key attribute where its value is the name of the cookie you want to retrieve the value for.
[CF7_get_cookie key="<insert cookie key>"]
This shortcode also includes an optional default attribute where you can specify the default value to be returned if the cookie is empty or does not exist.
[CF7_cookie key="<insert cookie key>" default="<insert default value>"]
Examples
If I wanted to get the value of the cookie named wordpress_test_cookie, the value of my dynamic field would use this:
CF7_get_cookie key='wordpress_test_cookie'
And then the dynamic text form tag would look like this:
[dynamictext cookie "CF7_get_cookie key='wordpress_test_cookie'"]
I could also choose to define a default value for the field should that cookie not exist or is empty by using the following dynamic form tag:
[dynamictext cookie "CF7_get_cookie key='wordpress_test_cookie' default='Please allow cookies!'"]
Cache Compatibility
If the HTML of your webpage is being cached, preventing the server from processing the shortcode before displaying the form, then you can enable cache compatibility mode for this form tag.
However, this built-in shortcode is unique in that it does not make an AJAX request. Instead, it simply uses JavaScript to pull the cookie’s value.
Demo
Check it out! I did exactly what I suggested in the last example plus showing off the cache compatibility mode. Below is a form with a two form fields that both get the wordpress_text_cookie and defaults to Please allow cookies! if it doesn’t exist or is empty. The first is just processed by the server while the second is pulled via JavaScript. Encoding isn’t an issue for hidden fields.
View Source Code
This shortcode was added to the Contact Form 7 – Dynamic Text Extension WordPress plugin in version 3.3.0. View the current source code for the server-side shortcode or for the client-side JavaScript function.