I'm building a page containing a channel form to allow users to edit their posts, and I thought I'd add an {if}...{/if}
statement to prevent them editing other users' entries. The permissions on the channel are set correctly, but this was just to get around the error message on form submission. So I added this:
{exp:channel:form .... entry_id="{segment_3}"}
{if author_id <> member_id}
{redirect="home"}
{/if}
{/exp:channel:form}
The issue then, was that the code redirected even when author_id = member_id. This seemed bizarre, so as a test, I changed the above code to read:
{exp:channel:form .... entry_id="{segment_3}"}
{if author_id <> member_id}
Not Equals
{if:else}
Equals
{/if}
{/exp:channel:form}
and found that regardless of which entry I edit, the statement returned
Not Equals
Upon a bit more playing around, I found that if I add an {author_id}
tag above the {if}...{/if}
statement, it worked properly. It seems that unless I echo the {author_id}
before the comparison, {author_id}
is... blank?
Can someone explain this?