1

I have a simple page that is displaying entries and statuses from the database. I would like to be able to click a link (i.e. remove entry) and have that onClick event set the entry status to removed.

<h4>{entry:title}</h4>
<p class="meta">
    Entry Status: 
    {if entry:status == "open"}
        <span class="green">Paid</span>
    {if:else}
        <span class="red">{entry:status}</span>
    {/if}

    <a>{NEED ON CLICK ACTION/SYNTAX HERE}Remove Entry</a>
</p>                            

1 Answer 1

0

The simplest way that I can think of is to use a standard channel form. You would pass the entry_id to the form and the form would have a status field with the value that you wish to use to set the entry status.

I have done this on several of my sites and in some cases I completely hide the form and then set a status and trigger the form send via jquery. for example:

<button id="sendmyform">Set the status</button>

{exp:channel:entries channel="yourchannel" ...params }
    {exp:channel:form channel="yourchannel" entry_id="{entry_id}" return="templatename" id="statusform"}
        <input type="hidden" id="myformstatus" name="status" value="mystatus" />
    {/exp:channel:form}
{/exp:channel:entries}

and then jquery:

$('#sendmyform').on('click',function(){
    $('#statusform').submit();
});

which would send your hidden form on clicking the button or link. If you need to set the status at the same time as the button is clicked, just set the field status value prior to sending.

$('#sendmyform').on('click',function(){
    $('#myformstatus').val('mystatus');    
    $('#statusform').submit();
});

The above method works great for single entry pages, but you'll run into complications if you are trying to use this on a page where you have multiple entries and are outputting the form for each entry as well.

If you are working with multiple entries on the page, you'll probably need to append a {count} or an {entry_id} for each form/field/button to determine which button was clicked and it would be better to use class instead of id to set the selectors. It also may be useful to use a data attribute on the button so that you can easily parse which form to submit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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