I have this form

    <form method="post" enctype="multipart/form-data">
        {{ csrfInput() }}
        <input type="hidden" name="action" value="entries/save-entry">
        <input type="hidden" name="entryId" value="{{ entry.id }}">

        <div class="form-group">
          <label>Listing Title</label>
          <input type="text" name="title" class="form-control" value="{{ entry.title }}">

Is it possible to add a delete button to this form or will it have to be within another form targeting a different end point for entries?

up vote 2 down vote accepted

I have a single form with a Save button and a Delete button.

The action value is set to entries/save-entry by default. However, when the user clicks the Delete button, the action value is changed to entries/delete-entry via JavaScript.

I'm using Vue.js to accomplish this as follows:

<input type="hidden" name="action" id="action" v-bind:value="'entries/' + actionVal">

Delete button:

<button type="submit" value="delete" v-on:click="actionVal = 'delete-entry'">Delete</button>

In my Vue instance:

new Vue({
    el: '#app',
    delimiters: ['${', '}'],
    data: {
        actionVal: 'save-entry'
  • Thanks for the answer Andrea, is there anyway you can add normal JS/Jquery to this answer? – JMKelley Nov 30 at 16:39
  • I'm actually not very skilled at JavaScript, so perhaps someone else could chime in and I'll update my answer accordingly. Vue.js actually made it easier for me. – Andrea DeMers Nov 30 at 17:04

According to the corresponding controller method, there is no way to delete the entry on save. You'd have to call entries/delete-entry for that.

Of course, if this is really something you want and you're comfortable writing some PHP code, you could programmatically delete the entry before or after save, using a plugin or module.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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