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.
Hm. I can definitely replicate this. I’ll investigate and let you know what I find out.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.