Delete entry

By: danny kim | Asked: 01/06/2024
ForumsCategory: Code SnippetsDelete entry
danny kim asked 4 months ago

Hi,

I tried to delete an entry when I click custom button in HTML field, But it didnt work.
Anything wrong with this snippet?


In html, button name is "submit"
// php section
$entry_id = '100';
if (isset($_POST['submit'])) {
   FrmEntry::destroy($entry_id);
}
2 Answers
Rob LeVineRob LeVine answered 4 months ago
There's really not a whole lot of information to go on, however, I will point out that if you want to delete an entry you need to pass the entry id to the destroy method, not the form id.
danny kim replied 4 months ago

That is actually entry id. I just edit it. Thanks.

Victor Font answered 4 months ago

If you have that code in an HTML field on the form, it will never execute because it's PHP code. PHP code only executes on the server. If you want a custom button on a form to trigger a delete action, you have to use the button to instantiate an AJAX REQUEST to ask the server to run FrmEntry::destroy($entry_id). This means you have to build the jQuery and PHP callback function to make it all work.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right