Delete an entry after after form is loaded

By: Henry King | Asked: 10/19/2022
ForumsCategory: Code HelpDelete an entry after after form is loaded
Henry King asked 2 years ago
Hi After Form A is submitted, the user will be redirected to Form B. Form B will take certain values from Form A but after the entry created by Form A but once Form B is loaded, the entry created by Form A can be deleted. I would like to delete an entry created by Form A after submission and successful redirection to Form B. How can this be done with PHP or Javascript?  I understand "FrmEntry::destroy( $_SESSION['entry_id'])" can be used to delete an entry but this is PHP and I don't know of a hook that can runs after a form is successfully loaded. Thanks.   Henry
1 Answers
Victor Font answered 2 years ago
Wouldn't it be easier to not save Form A entries and pass the Form A values to Form B via a query string?
Henry King replied 2 years ago

Hi, that's possible but there are about 50 fields so the query string might be too long.

Victor Font replied 2 years ago

A query string of 50 fields would be too long.

FrmEntry::destroy() does indeed delete an entry and then clears Formidable's db caches of any remnants.

There are no PHP hooks that can detect when a form is successfully loaded into a browser window. That's a Document Object Model (DOM) event that can be detected by jQuery. I think what you need to do is pass the Form A entry id to Form B and save it in a hidden field. This way you can trigger an Ajax call to delete the Form A entry on the server when document.ready() triggers.

If you're not familiar with Ajax, the jQuery sends a request to the server to execute a custom PHP function. The reason you save the Form A entry id in Form B is to pass it as the Ajax parameter to your custom function.

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