2

I have a strange issue I can't find reference to anywhere on Google!

The following code allows me to display a Safecracker form to edit an entry. When I click save I get the error below.

{exp:safecracker
    channel="member_news"
    return="members/profile#tab3"
    author_only="yes"
    form_class="uniform"
    error_handling="inline"
    entry_id="{segment_4}"
}

    <p>
        <label for="title">Title</label>
        <input name="title" type="text" value="{title}">
    <p>

    <p>
        <label for="title">Summary</label>
        {field:member_news_summary}
    <p>

    <p>
        <label for="title">Content</label>
        {field:member_news_content}
    <p>

    <input type="submit" value="Submit">

{/exp:safecracker}

This is the error:

The form you submitted contained the following errors

safecracker_author_only

I find this strange because I am the author of the entry, it wont even show the edit form to other entries I am not the author of, so author_only="yes" seems to be working with that respect. But clicking save its as if it then thinks I am not the author.

Removing author_only="yes" will allow me to edit AND save, any form, which is obviously bad.

So I am not sure what the issue is. Using v 2.6.1

1

Your code looks right. Trust me, author_only does work. First rule out the obvious: In your safecracker form, output {author_id} and {member_id} and make sure they match. Second, suggest checking member group settings that you can edit entry

4
  • {author_id} and {member_id} are the same, and the group IS allowed to Post and Edit channel entries for this channel. Thats the weird thing, it allows me on the edit screen (which it would not if any of the above are not true), its only after Save does is then show this error. – Laurence Cope Aug 19 '13 at 13:22
  • Ive just again looked at my code - same params except i dont use inline errors. In source code, search for 'safecracker_author_only'. Youll find two refs only, both in safecracker_lib.php. You are failing one of these conditions. Comment out some of these conditionals until you get a pointer on where the problem is. – Lloyd Hill Aug 19 '13 at 23:54
  • This is the problematic conditional: $this->entry('author_id') != ee()->session->userdata('member_id') But $this->entry is empty – Laurence Cope Aug 20 '13 at 12:09
  • Looks like fetch_entry() requires the URL title passed, but $this->_meta['url_title'] is empty. – Laurence Cope Aug 20 '13 at 12:30
0

Ok, I've been able to replicate the same issue in my setup up and solved it with a plugin as follows:

{exp:yak_bus:grant_access url_title = "{segment_3}"}{if response == "no"}{redirect="access/not_authorised"}{/if}{/exp:yak_bus:grant_access}

public function grant_access ()
{
    $url_title = (ee()->TMPL->fetch_param('url_title') != '') ? ee()->db->escape_str(ee()->TMPL->fetch_param('url_title')) : FALSE;

    if ( ! $url_title) return;

    $query = ee()->db->query("SELECT url_title, author_id 
        FROM exp_channel_titles 
        WHERE url_title = '" .$url_title . "'");

    if ($query->num_rows == 0 )
    {
        // not a valid url - so could be another page within mybusiness, thats ok
        return;
    }

    if ($query->row('author_id') != ee()->session->userdata('member_id'))
    {
        $vars = array('response' => 'no');
        return $this->return_data = ee()->TMPL->parse_variables_row(ee()->TMPL->tagdata, $vars);
    }

    return;
}

And if you need a start with a plugin pkg,io

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.