Docs & Support

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

frm_before_entry_meta_change

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 third-party development.

Use the frm_before_entry_meta_change action to run code right before Formidable adds, updates, or deletes a single field value of an entry. It runs before the database write, while the old value is still saved.

After the write, Formidable runs frm_after_entry_meta_change, or frm_entry_meta_write_failed if the write failed. Use these hooks together to keep your own data in sync with entry values.

Requirements

  • Formidable Forms 7.0 or later. The hook is part of Formidable Forms Lite.

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

When it fires

The action runs once per field value, before each of these writes:

  • Add: a field value is saved for the first time, such as when a new entry is submitted.
  • Update: an existing field value is changed, such as when an entry is edited.
  • Delete: a single field value is removed, including a value that was cleared when an entry was edited.

Blank values are never saved. Adding an empty value doesn't fire the hook. Formidable Forms Pro uses this hook to keep its own index of entry values in sync.

Usage

add_action( 'frm_before_entry_meta_change', 'my_function_name', 10, 2 );

Parameters

  • $entry_id (int): The ID of the entry the value belongs to.
  • $field_id (int): The ID of the field whose value is about to change.

Examples

Learn where to put the code when adding a custom PHP function to your site.

Log the old and new value of a field

This example saves the current value of a field before it changes. After the write, it logs the old and new values to the PHP error log. Replace 25 with the ID of your field.

function my_frm_get_saved_value( $entry_id, $field_id ) {
	global $wpdb;
	return $wpdb->get_var(
		$wpdb->prepare(
			"SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE item_id = %d AND field_id = %d",
			$entry_id,
			$field_id
		)
	);
}

add_action( 'frm_before_entry_meta_change', 'my_frm_remember_old_value', 10, 2 );
function my_frm_remember_old_value( $entry_id, $field_id ) {
	global $my_frm_old_values;
	if ( 25 !== (int) $field_id ) { // Change 25 to the ID of your field.
		return;
	}
	$my_frm_old_values[ $entry_id . '_' . $field_id ] = my_frm_get_saved_value( $entry_id, $field_id );
}

add_action( 'frm_after_entry_meta_change', 'my_frm_log_value_change', 10, 2 );
function my_frm_log_value_change( $entry_id, $field_id ) {
	global $my_frm_old_values;
	$key = $entry_id . '_' . $field_id;
	if ( ! is_array( $my_frm_old_values ) || ! array_key_exists( $key, $my_frm_old_values ) ) {
		return;
	}
	$old_value = $my_frm_old_values[ $key ];
	$new_value = my_frm_get_saved_value( $entry_id, $field_id );
	unset( $my_frm_old_values[ $key ] );

	if ( $old_value !== $new_value ) {
		error_log( sprintf( 'Entry %d, field %d changed from "%s" to "%s".', $entry_id, $field_id, $old_value, $new_value ) );
	}
}

The example reads both values straight from the database. Formidable caches the entry values it reads. A cached read can return the value from before the change.

Limitations

  • The hook runs only for values saved through Formidable's entry value functions. Deleting a whole entry, deleting a field, or deleting all entries of a form removes the values without firing it. To run code when a whole entry is deleted, use frm_before_destroy_entry.
  • To change a value before it's saved, use the frm_add_entry_meta or frm_update_entry_meta filter instead. This action runs your code but leaves the value unchanged.
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 © 2026 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Don't forget your purchase!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms