Allow users to delete entries by adding a delete link to a page, post, form, or View. When a user clicks on the delete link, the specified entry will be deleted.
In order for the delete link to appear for a logged-in user, your form must allow editing.
Insert a delete link on any page, post, form, or View in order to allow users to delete entries. Before the delete link will work correctly, you must set up your form to allow editing.
In Views or forms
This shortcode automatically retrieves the appropriate entry ID from the View or form where it is inserted. To add this link to a form, go into "Settings" → "Customize HTML" and insert the shortcode in the Before Fields or After Fields section.
In pages or posts
[frm-entry-delete-link id=x page_id=y label="Delete"]
Replace x with the ID of the entry to be deleted. Replace y with the ID of the page where the form is published (see page_id in the parameter list below for more info).
The following parameters can be used with deletelink and the frm-entry-delete-link shortcode.
- id (optional for deletelink) - The ID of the entry to delete. An entry ID can be found by going into your form and clicking on “Entries". The furthest left column typically contains the entry ID.
- page_id (optional for deletelink) - The ID of the page where the form is published. You can find the ID of a page by going into edit the page and looking in the address bar. If the page_id is not specified, this defaults to the current page ID. The page_id parameter can also be used to redirect after deletion of the entry. Insert the page id of the desired destination to redirect the user after an entry or post has been deleted.
- label - Set the label for the delete link. If you do not include a label for the link, the HTML for the link will NOT be returned. Usage: [frm-entry-delete-link id=x label="Delete your entry"].
- confirm - Change the text in the pop-up message to confirm entry deletion. By default, this will say "Are you sure you want to delete this entry?". Usage: [frm-entry-delete-link id=x page_id=y confirm="Permanently delete your entry?"]
- title - Set the value shown when hovering over the delete link. If not specified, this will default to the same value as the label.
- class - A space-separated list of any HTML classes you would like to add to style the link. Usage: [frm-entry-delete-link id=x page_id=y class="my_class my_class_2"]
- prefix - If you would like to delete an entry with AJAX and fade out the entry after deletion is complete, use the prefix parameter. In order to use the prefix parameter, you must add a div around your content that will be faded out. If you would like to learn more, see the example below.
Delete with AJAX
You can delete an entry with AJAX so that it fades away without having to reload the page. In order to do this, you must use the prefix parameter. Next, you must wrap your content that you want to fade out in a div container. This div should have an id like <div id="frm_container_253"> where 253 is the entry ID. This may be how it would look in a View:
<div id="frm_container_[id]"> Insert content here [deletelink label="delete" prefix="frm_container_"] </div>
The text in red must match and the delete link must go inside of the container in order for prefix to work properly.
Create Delete Draft Link
You can use a [deletelink] shortcode to allow users to delete a draft once they have created it. Follow these steps to insert a Delete Draft link in your form.
- Make sure that your form allows users to save drafts when logged in. For more information on this, click here.
- Next, go to Form Settings → Customize HTML and go to the Submit Button field. By default, there is a line for conditionally showing the Save Draft link:
[if save_draft]<a href="#" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]
We are going to change this as shown below:
[if save_draft]<a href="#" class="frm_save_draft" [draft_hook]>[draft_label]</a> [deletelink label="Delete Draft"][/if save_draft]
- Lastly, you can update your form settings. This will cause a Delete Draft link to be shown once users have saved a draft, allowing them to delete their draft and start over if wanted.
- Additionally, you can style this delete link if needed by adding the class prefix to the above example, and then writing custom CSS for that class.
[if save_draft]<a href="#" class="frm_save_draft" [draft_hook]>[draft_label]</a> [deletelink label="Delete Draft" class="my_custom_class"][/if save_draft]
echo FrmProEntriesController::entry_delete_link( array('id' => x, 'label' => 'Delete') );