Using Gravity Forms ‘gform_before_delete_field’ PHP action

The gform_before_delete_field Gravity Forms action hook allows you to perform actions right before a field is deleted from a form.

Usage

add_action('gform_before_delete_field', 'do_cleanup', 10, 2);

Parameters

  • $form_id (integer) – ID of the current form.
  • $field_id (integer) – ID of the deleted field.

More information

See Gravity Forms Docs: gform_before_delete_field

Examples

Log Field Deletion

This example adds a log file entry when a field is deleted.

add_action('gform_before_delete_field', 'log_field_deleted', 10, 2);

function log_field_deleted($form_id, $field_id) {
    $log_file = ABSPATH . '/gf_deleted_fields.log';
    $f = fopen($log_file, 'a');
    $user = wp_get_current_user();
    $form = GFAPI::get_form($form_id);
    $field = RGFormsModel::get_field($form, $field_id);

    fwrite($f, date('c') . " - Field deleted by {$user->user_login}. Form ID: {$form_id}. Field: {$field["label"]} (ID: {$field_id})\n");
    fclose($f);
}