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.

Edit the last entry made by Current User in specific Channel.

April 11, 2012 4:28pm

Subscribe [0]
  • #1 / Apr 11, 2012 4:28pm

    oliverhood

    17 posts

    I need a member on my site to be able to do the following…

    Click on a link that will take them to a Safecracker form that edits the last entry they made in a specific channel.

    I am currently using the following code:

    {exp:channel:entries limit="1" author_id="CURRENT_USER"}<a href="/temps/edit/{entry_id}">Edit</a>{/exp:channel:entries}

    I have double-checked and the Safecracker form is looking at the correct segment (3).

    This seems to work for my Super Admin account (it grabs the last entry I made), but not for one or two of my other testing accounts, they seem to attempt to load the most recent entry regardless of the logged in member.

    Note: The /temps/ part could also be /employers/ depending on the logged in user’s member group. I’ve only tested with /temps/ so far.

    Any pointers on this? PHP or Query stuff is fine to use for this if required.

  • #2 / Apr 11, 2012 4:37pm

    glenndavisgroup

    436 posts

    Hi oliverhood,

    What version of EE are you using?

    Can you post your EE code for the edit screen please?

    Thank you,

    Mike

  • #3 / Apr 11, 2012 5:00pm

    oliverhood

    17 posts

    EE 2.4.0, the code for the edit page is as follows…

    {exp:safecracker channel="temps" return="/temps/" author_only="yes" entry_id="{segment_3}"}
    <ul>
      <li>
        <label>Profile Name</label>
        <div class="field-1">
          <input type="text" name="title" id="title" value="{screen_name}" size="50" maxlength="100">
        </div>
        <div class="field-2">
          <input type="hidden" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50">
        </div>
      </li>
      <li>
        <label>Name and Surname(s) *</label>
        <div class="field-1">{field:fname}</div>
        <div class="field-2">{field:surname}</div>
        <div class="field-instructions">{instructions:fname}</div>
      </li>
      <li>
        <label for="address">Address</label>
        {field:address}</li>
      <li>
        <label for="county">Town and County</label>
        <div class="field-1">{field:town}</div>
        <div class="field-2">{field:county}</div>
      </li>
      <li>
        <label for="postcode">Postcode and Country</label>
        <div class="field-1">{field:postcode}</div>
        <div class="field-2">{field:country}</div>
      </li>
      <li>
        <label for="photo">Photo</label>
        {field:photo}
        <div class="field-instructions">{instructions:photo}</div>
      </li>
      <li>
        <label for="youtube_link">YouTube</label>
        {field:youtube_link}
        <div class="field-instructions">{instructions:youtube_link}</div>
      </li>
      <li>
        <label for="headline">Headline</label>
        <div class="field-single">{field:headline}</div>
        <div class="field-instructions">{instructions:headline}</div>
      </li>
      <li>
        <label for="experience">Experience</label>
        {field:experience}
        <div class="field-instructions">{instructions:experience}</div>
      </li>
    <li id="profile-edit-employment">
    <label for="employment_history">Employment History</label>{field:employment_history}
    <div class="field-instructions">{instructions:employment_history}</div>
    </li>
      <li>
        <label for="skills_and_expertise">Skills and Expertise</label>
        {field:skills_and_expertise}
        <div class="field-instructions">{instructions:skills_and_expertise}</div>
      </li>
      <li>
        <label for="">Qualifications</label>
        {field:degree_or_qualification}
        <div class="field-instructions">{instructions:degree_or_qualification}</div>
      </li>
      <li>
        <label for="cv">CV</label>
        {field:cv}
        <div class="field-instructions">{instructions:cv}</div>
      </li>
      <li>
        <label for="salary">Salary / Hourly Rate</label>
        {field:salary}
        <div class="field-instructions">{instructions:salary}</div>
      </li>
      <li>
        <label for="travel_distance">Travel Distance</label>
        {field:travel_distance}
        <div class="field-instructions">{instructions:travel_distance}</div>
      </li>
      <li>
        <label for="looking_for">I am looking for:</label>
        <div class="checkboxes">{field:looking_for}</div>
      </li>
      <li>
        <label for="looking_for">Contact Me for:</label>
        <div class="checkboxes">{field:contact_me_for}</div>
      </li>
      <li>
        <label for="additional_information">Additional Information</label>
        {field:additional_information}
        <div class="field-instructions">{instructions:additional_information}</div>
      </li>
      <li>
        <label for="categories">Your Industry or Sector</label>
        <select name="category[]" id="categories" size="1">{categories}
          <option value="{category_id}"{selected}>{category_name}</option>{/categories}
        </select></li>
    <li><label for="currently_employed">Are you currently employed?</label> {field:currently_employed}</li>
      <li>
        <input type="submit" id="form-submit" name="submit" value="Save Edits">
      </li>
    </ul>{/exp:safecracker}
  • #4 / Apr 12, 2012 1:00pm

    Dan Decker

    7338 posts

    Hi Oliver,

    I see a couple of things that might help get the results you are after.

    1) In your {channel:entries} link, you are not specifying a channel, but in your SafeCracker you are, if the entry ID doesn’t match the channel, it could be why you are getting inconsistent results with your regular accounts. For contrast, Super Admins can always do anything, that’s why they are Super! 😊

    Try this:

    {exp:channel:entries cahnnel="temps" orderby="date" limit="1" author_id="CURRENT_USER"}<a href="/temps/edit/{entry_id}">Edit</a>{/exp:channel:entries}

    That will pull the latest entry by the CURRENT_USER from the “temps” channel and supply your Edit link with the entry ID

    2) With SafeCracker, you can forego the channel parameter since you are supplying the entry_id. But the changes to your first channel entries tag should get you the results you are after.

    I look forward to your reply!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases