ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Logged In Member ID returns wrong

October 14, 2011 12:44pm

Subscribe [3]
  • #1 / Oct 14, 2011 12:44pm

    matthewatkins

    12 posts

    I have a login form on a page that should log a member in to their account and return their member id in the url. I have the form set up like this:
    {exp:member:login_form return="user/files/{logged_in_member_id}/”}
    The problem is that the {logged_in_member_id} is only returning 0 in the url segment. Everything seems to be working except that.
    I’m using this member id to filter out entries by only that member on the page.

    Any ideas?

  • #2 / Oct 14, 2011 3:45pm

    Brad K Morse

    178 posts

    Are you using the exp:channel:entries tag to display their entries?

    Once they’re logged in, you should be able to get their member_id, it is a global variable, for more info http://ellislab.com/expressionengine/user-guide/templates/globals/single_variables.html#member-id

    You could pass the variable into the author_id parameter, like

    {exp:channel:entries author_id="{member_id}"}
  • #3 / Oct 14, 2011 3:49pm

    matthewatkins

    12 posts

    Yes. I am loading entries from the exp:channel:entries. That doesnt seem to be the problem though. I have another link set up to do the same thing (add the member_id to the url segment) and it gives me the correct id when clicked. Its just that when I try to pull the member_id into the url segment from a login, it gives me 0 as the id.

  • #4 / Oct 14, 2011 3:54pm

    Brad K Morse

    178 posts

    I imagine it parses member_id before your form completes and returns 0 since the user was not logged in at the time of member_id being parsed.

  • #5 / Oct 14, 2011 3:55pm

    matthewatkins

    12 posts

    Sure. Makes sense. I may just need to decide on a work around.

  • #6 / Oct 14, 2011 3:55pm

    matthewatkins

    12 posts

    Sure. Makes sense. I may just need to decide on a work around.

  • #7 / Oct 14, 2011 4:04pm

    Brad K Morse

    178 posts

    You could put in a redirect after the user submits the login form, something like:

    change the return to another page:

    {exp:member:login_form return=“user/thankyou/”}

    and in the user/thankyou template, have:

    {if logged_in} {redirect="user/files/{member_id}"} {/if}

    and in the user/files template, have:

    {exp:channel:entries author_id="{member_id}"}{title}{/exp:channel:entries}
    or
    {exp:channel:entries author_id="{segment_3}"}{title}{/exp:channel:entries}
  • #8 / Oct 14, 2011 4:22pm

    matthewatkins

    12 posts

    Unfortunately, that gives me this error: The URI you submitted has disallowed characters.
    It’s not allowing {member_id} within the redirect.

  • #9 / Oct 14, 2011 4:39pm

    Brad K Morse

    178 posts

    try this

    put this at the very top of the thankyou template

    {assign_variable:logged_in_id="{member_id}"}

    then in the redirect

    {redirect="user/files/{logged_in_id}"}

    why do need the currently logged in member’s member_id w/i the segment? it is a global variable and you can get it without being in the URL.

  • #10 / Oct 14, 2011 4:50pm

    matthewatkins

    12 posts

    You know what. It was a simple answer…always is right? I didn’t need to use that last fix you mentioned. Thanks so much for your help.

    The goal:
    I want a member to log in and it takes the directly to their account page. Easy enough. On their account page is a list of all of their entries, so I wanted it to only show their entries.

    Where I was using this code

    {exp:channel:entries author_id="{member_id}"}{title}{/exp:channel:entries}

    Instead of {member_id} I was trying to use {logged_in_member_id} and that wouldnt work. Changed that around and its just right now.

    Again, thanks for your help.

  • #11 / Oct 15, 2011 11:57am

    Sue Crocker

    26054 posts

    Thanks for the assist, bkmorse.

    Matthew - Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases