Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_before_destroy_entry

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

This hook allows you to do something before an entry is deleted.

Usage

add_action('frm_before_destroy_entry', 'my_custom_function');
function my_custom_function($entry_id)

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameters

  • $entry_id (integer)
  • $entry (object) The data of the entry to be deleted

Examples

Basic Example

add_action('frm_before_destroy_entry', 'my_custom_function');
function my_custom_function($entry_id) {
  $entry = FrmEntry::getOne($entry_id);
  if ( $entry->form_id == 5 ) { // change 5 to your form id
    // do something for entries deleted from this form
  }
}

Delete Uploads

As of v2.0.22, this is no longer needed. You can instead check the box in the field options for your file upload field. Use this code to automatically delete file uploads when an entry is deleted. No changes are necessary.

<script src="https://gist.github.com/fb60fc55adb212cb0dd8.js?file=frm_delete_files.php" type="text/javascript"></script>

Separate child entries

Use the code below to prevent entries from embedded forms and repeating sections from being deleted when the parent entry is deleted. This will automatically apply to all embedded forms and repeating sections in the form.

add_action( 'frm_before_destroy_entry', 'my_custom_function', 9 );
function my_custom_function( $entry_id ) {
	$entry = FrmEntry::getOne( $entry_id );
          if ( in_array( $entry->form_id, array( 5, 6, 7 ) ) ) { // change 5, 6, and 7 to your form ids
	  	global $wpdb;
	  	$table = $wpdb->prefix . 'frm_items';
	  	$wpdb->update( $table, array( 'parent_item_id' => 0 ), array( 'parent_item_id' => $entry_id ) );
	  }
}

Delete user

Use this code to delete a WordPress user from your site when their entry is deleted. Just replace 10 with your form ID and 25 with the ID of your userID field. Warning: This action cannot be undone.

add_action('frm_before_destroy_entry', 'delete_user_with_entry');
function delete_user_with_entry( $entry_id ) {
    $form_id = 10;// Replace 10 with the ID of your form
    $field_id = 25;//Replace 25 with the ID of your userID field
    $entry = FrmEntry::getOne( $entry_id, true );
    if ( $entry->form_id == $form_id ) {
        if ( isset( $entry->metas[ $field_id ] ) && $entry->metas[ $field_id ] ) {
            $user_id = $entry->metas[ $field_id ];
            $user = new WP_User( $user_id );
            if ( ! in_array( 'administrator', (array) $user->roles ) ) {
                wp_delete_user( $user_id, 7 );//change 7 to the user ID to whom the deleted user's post/pages will be assigned (this can be found in your wp_users table)
            }
        }
    }
}

If you would like to remove the user and their posts/pages, then use this line at the end instead:

wp_delete_user( $user->ID );

Access a row on a repeater

Repeating groups are child form entries, and when they are deleted, this hook is called for each repeating group row.

add_action( 'frm_before_destroy_entry', 'my_custom_function',9 );
function my_custom_function( $entry_id ) {
    $entry = FrmEntry::getOne( $entry_id, true );
    if ( $entry->parent_item_id !== '0' ) {
        // do something for repeating group entries from this form
    }
}
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms