Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

frm_before_destroy_entry

Last Updated: July 8, 2022

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Entry Management → 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 destroyed.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

Usage

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

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
    }
}
  • Usage
  • Parameters
  • Examples
    • Basic Example
    • Delete Uploads
    • Separate child entries
    • Delete user
    • Access a row on a repeater
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form.

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.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews