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.

Channel Entry Status Update From EE Template

February 15, 2012 3:28pm

Subscribe [2]
  • #1 / Feb 15, 2012 3:28pm

    Phil Ecker

    78 posts

    I’ve been searching for a way to update an entry status from one of my EE templates. But haven’t found anything like what I’m looking for. I want to be able to click a link to change an entry status from “open” to a custom status. That way administrators can sort content based on that status, I don’t need to display it on the front end, but just submit/change from my templates. Any help pointing me in the right direction would be appreciated. Thanks.

  • #2 / Feb 15, 2012 4:23pm

    Ian Young

    200 posts

    If you’re trying to do it from your front-end templates then you’d have to submit something to have it post back to the server to make the change. This would mean that you’d have to display it on the front-end in your templates and allow a form submission to make the change.

    A Safecracker form would be the way to go about this:

    {exp:safecracker channel="channel_name" return="channel_name/edit/ENTRY_ID" entry_id="{segment_3}"}
        ...
        {status_menu}
            <label for="status">Status</label>
            <select name="status" id="status">
                    {select_options}
            </select>
        {/status_menu}
        ...
        <input type="submit" name="submit" value="Submit">
    {/exp:safecracker}

    From the front-end or the back you have to make a submission to the server of some kind.

  • #3 / Feb 15, 2012 4:30pm

    Phil Ecker

    78 posts

    Not sure that is what I’m looking for, I only want people on the site to be able to submit 1 status, I don’t even want them to see the other statuses.

  • #4 / Feb 15, 2012 4:51pm

    Ian Young

    200 posts

    If you can provide a bit more context for what you’re trying to achieve then it will help in suggesting something.

    Generally if it’s from the front-end then they’ll need to submit something to change the value in the database and that will need to be related to an entry. It may be that you can just use a custom field rather than an actual status.

  • #5 / Feb 16, 2012 9:31am

    Phil Ecker

    78 posts

    I have a reference section (documents) I want the status of the material to be open by default, but want a user to be able to change a status to “outdated” if they feel material is out of date.  I still want these items to display in the front-end (EE Template) but with having the changed status will allow admins to sort by channel with a status of outdated. So Ideally all the user would have to do is click a link that said “Mark as Outdated” and then the status of that content would be changed to outdated in the CP. Thanks for trying to help with my issue.

  • #6 / Feb 16, 2012 10:17am

    Ian Young

    200 posts

    Hi Phil,

    That’s certainly possible but unfortunately it does still require a form submission to edit any details of an entry in the system. You could set Status items of “Current” and “Outdated” and set “Current” as the default. Then from the front-end you could provide a dropdown menu which allows a user to set it as “Outdated:. If the members are just guests then you’d have to open up permissions in the Member Group.

    If you wanted to make the process a bit more seamless you could add in some Javascript/AJAX to submit the form without needing to reload the page. I guess if you wanted to just provide a link or a button then you could do so and then use that as an event trigger and submit the form via AJAX. There’s definitely no way to do it automatically without a form submission of some kind however. Using AJAX will just help to mask the fact that it is a form under the hood and make it pretty seamless on the front-end. You’d still need to the processing under the hood however.

  • #7 / Feb 16, 2012 3:45pm

    Dan Decker

    7338 posts

    Hey Phil,

    Let’s see if we can get you a couple of ideas to work off of.

    Slippy is on the right track with SafeCracker. That is the only supported means to make changes to entries outside of the Control Panel.

    You can use SafeCracker in combination with Channel Entries tags to only allow certain aspects of the entry to be edited, in your case the status. The other content could be displayed as normal, an safely tucked away in hidden SafeCracker fields.

    Editing the status would require you to submit a form, but as Slippy points out, you can use AJAX to avoid a page refresh.

    Let me know what you think.

    Cheers,

  • #8 / Feb 27, 2012 4:37pm

    Phil Ecker

    78 posts

    Hi Dan,

    Thanks for the response, I get the general idea but having a tough time accomplishing that as I am very new to using AJAX. Would you have any resources that might visual show what needs to be done? Thanks.

    -Phil

  • #9 / Feb 28, 2012 4:18pm

    Dan Decker

    7338 posts

    Hey Phil,

    There is an example in the User Guide:

    <html>
            <head>
                    {exp:jquery:script_tag}
    
                    <!--using the jQuery Form plugin <a href="http://jquery.malsup.com/form/--&gt">http://jquery.malsup.com/form/--&gt</a>;
                    [removed][removed]
    
                    [removed]
                            $(document).ready(function(){
                                    $('#publishForm').ajaxForm({
                                            dataType: 'json',
                                            success: function(data) {
                                                    if (data.success) {
                                                            alert('You successfully added a new entry with entry_id '+data.entry_id)
                                                    } else {
                                                            alert('Failed with the following errors: '+data.errors.join(', '));
                                                    }
                                            }
                                    });
                            });
                    [removed]
            </head>
            <body>
                    {exp:safecracker channel="products" return="safecracker/ENTRY_ID" entry_id="{segment_2}" json="yes"}
                            <input type="checkbox" name="status" value="Custom Status">
                            <input type="hidden" name="title" id="title" value="{title}">
    
                            <input type="hidden" name="url_title" id="url_title" value="{url_title}">
    
                            <input type="hidden" name="entry_date" id="entry_date" value="{entry_date}">
    
                            <input type="submit" name="submit" value="Submit">
                    {/exp:safecracker}
            </body>
    </html>

    In this example, checking the box and clicking submit would change the status on this entry.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases