The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Cookie Shortcode Not Working
The knowledgebase has an example of how to create a shortcode for storing cookie values in form fields. But I can't get it to work. I use the Code Snippet plugin and I added a snippet per the Formidable Knowledgebase:
Get a cookie value in a field#
This example creates a shortcode you can use on a page or inside of a form field. Example: [frm_referrer_cookie name="cookie_name_here"] or [frm_referrer_cookie name="frm_url_value"]
add_shortcode( 'frm_referrer_cookie', 'frm_referrer_cookie' ); function frm_referrer_cookie( $atts ) { $cookie_name = sanitize_text_field( $atts['name'] ); $value = ''; $cookie_name = $cookie_name . COOKIEHASH; if ( isset( $_COOKIE[ $cookie_name ] ) ) { $value = $_COOKIE[ $cookie_name ]; } return $value; }
I then have a hidden field with this value in the form:
[frm_referrer_cookie name="referrer"]
I have a cookie plugin for Chrome and can see the cookie 'referrer' is set with a value but when the form is submitted the value of the hidden field is not set.
Any ideas what I'm doing wrong?
October 23, 2018 at 10:09 pm
I figured it out. I didn't notice before a hash was being added to the cookie name and I'm not adding a hash to the name when I set the cookie.
Discussion closed.