We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Set cookie within post variable

How Do I?

deswork's avatar
deswork
122 posts
3 years ago
deswork's avatar deswork

I’m using the code below to show content and set a cookie if the value of the form password field matched the entry password (presentation_password) that is set with creating the entry.

{exp:channel:entries channel="presentation" url_title={segment_3} limit="1"}
 {if "{exp:request:get_post name='p_password'}" == "{presentation_password}"}
  {exp:cookie:set name="recent_article" value="{entry_id}" expire="1209600"}
  Show content and set cookie 
   
 {if:else} 
  <form method="post" name="presentation-login" action="/{current_path}">
   <input type="hidden" name="csrf_token" value="{csrf_token}">
   <input type="password" name="p_password" class="form-control mb-4" />
   <input type="submit" value="Submit" class="btn btn-bca-blue" />
  </form>   
 {/if}
{/exp:channel:entries}

The conditional works in that the form is show when landing on the page and if the passwords don’t match when the form is submitted.

However the cookie is set when landing on the page regardless.

Not sure if I’m missing something simple.

Thanks

Wayne.

       
Andy McCormick's avatar
Andy McCormick
322 posts
3 years ago
Andy McCormick's avatar Andy McCormick

Hm. I can definitely replicate this. I’ll investigate and let you know what I find out.

? 1
       
Andy McCormick's avatar
Andy McCormick
322 posts
3 years ago
Andy McCormick's avatar Andy McCormick

Just an update here. I’m really at a loss right now. {exp:cookie:set} is only parsed when the opening conditional statement is {if "{exp:request:get_post name='p_password'}" == "{presentation_password}"} . If I use {if "foo" == "bar"} instead, {exp:cookie:set} is not parsed. Likewise if I just put {exp:request:get_post name='p_password'} elsewhere in the template and use {if "foo" == "bar"} in the conditional, the cookie is not set. Something about {if "{exp:request:get_post name='p_password'}" == "{presentation_password}"} is promoting {exp:cookie:set} in the parse order.

       
deswork's avatar
deswork
122 posts
3 years ago
deswork's avatar deswork

Does this need reporting as a bug?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.