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.

Safecracker {member_id} inside of url_title?

February 15, 2012 5:49pm

Subscribe [4]
  • #1 / Feb 15, 2012 5:49pm

    AdamSmith

    22 posts

    I want to tie a user to an entry by creating/editing an entry with the title and url_title “user{member_id}”

    Here’s the code I’m using:

    {exp:safecracker
     channel="portfolios"
     url_title="user{member_id}"
     return="user/portfolio/user{member_id}"
     datepicker="no"
     author_only="yes"
     }
    
        <label for="title">Title</label>
        <input type="text" name="title" id="title" value="{title}" size="50" maxlength="100">
    
        <label for="url_title">URL Title</label>
        <input type="text" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50">
    
        <input type="submit" name="submit" value="Submit">
    {/exp:safecracker}

    This doesn’t seem to be working. It does work if I type in manually url_title=“user1”.

    Am I going about this the wrong way? Shouldn’t this work?

  • #2 / Feb 16, 2012 7:05am

    mark186282

    290 posts

    great question.  I know it’s not recommended in most cases, but a quick fix would be to use PHP in this case (allow php = yes, processing = input)

    Grab your member ID and output it in your template:

    <?PHP
    $this->EE =& get_instance();
    $loggedin_member_id = $this->EE->session->userdata('member_id');
    ?>
    
    {exp:safecracker
     channel="portfolios"
     url_title="user<?PHP echo $loggedin_member_id; ?>"
     return="user/portfolio/user<?PHP echo $loggedin_member_id; ?>"
     datepicker="no"
     author_only="yes"
     }
    
    ...


    would this accomplish what you are looking to do?

  • #3 / Feb 16, 2012 1:03pm

    AdamSmith

    22 posts

    Thanks Mark,

    That may do the trick, but I’d much prefer not having to enable PHP in my templates in order to get this to working.

  • #4 / Feb 16, 2012 4:17pm

    Dan Decker

    7338 posts

    Hi Adam,

    SafeCracker wants either the url_title= parameter, or the url_title field. Not both 😉

    Give this a try:

    {exp:safecracker
    channel="portfolios"
     return="user/portfolio/user{member_id}"
     datepicker="no"
     author_only="yes"
     }
    
        <label for="title">Title</label>
        <input type="text" name="title" id="title" value="{title}">
    
        <input type="hidden" name="url_title" id="url_title" value="user{member_id}">
    
        <input type="submit" name="submit" value="Submit">
    {/exp:safecracker}

    That should get you going.

    Cheers,

  • #5 / Feb 16, 2012 4:43pm

    AdamSmith

    22 posts

    Hi Dan,

    That code does show me a form, and allow me to submit entries—but it does not allow me to edit the entry i created when I go back to the url. It simply creates another entry, with url_titles of “user1, user11, user12, user13”... (1 is my member_id).

    I want to restrict the user to only being able to create and edit one entry (which has “user{member_id}” as its url_title).

    To put this another way,
    when a user goes to this template, I want them to be able to either:
    a) create a new entry with url_title “user{member_id}”, if the entry does not already exist
    b) edit the entry with url_title “user{member_id}”

    Does that make sense? Is this possible?

  • #6 / Feb 20, 2012 4:10pm

    Dan Decker

    7338 posts

    Hi Adam,

    Indeed, what you want is possible and your request makes sense! I was simply getting the SafeCracker form to a state that works, then we can add in complexities.

    I have these additional parameters in my SafeCracker template:

    {exp:safecracker
     channel="portfolios"
     return="user/portfolio/user{member_id}"
     datepicker="no"
     author_only="yes"
     entry_id="{segment_3}"
     url_title=""
    }

    With that, SafeCracker will be looking {segment_3} for an entry_id. If one is present, it will pull the entry and allow it to be edited. If no ID is found, it creates a new entry.

    If you want to use url_title, simple swap the parameters around:

    {exp:safecracker
     channel="portfolios"
     return="user/portfolio/user{member_id}"
     datepicker="no"
     author_only="yes"
     entry_id=""
     url_title="{segment_3}"
    }

    And SafeCracker will look to {segment_3} for a url_title instead.

    Add in those parameters and let me know what else I can do to help!

    Cheers,

  • #7 / Feb 21, 2012 12:07pm

    AdamSmith

    22 posts

    Dan, I was trying to avoid putting the url_title in the URL, but that was probably causing more complications than necessary.

    Since making this post I’ve switched methods from Safecracker Registration to Zoo Visitor (which is working perfectly).

    Thanks, i appreciate your help!

  • #8 / Feb 24, 2012 12:07pm

    Shane Eckert

    7174 posts

    Hello AdamSmith,

    I am happy to hear it’s working perfectly!

    Thank you for sharing that information about the plugin.

    Happy Friday!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases