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 with the data that was entered in the form before it is changed and the form is updated.
Usage
add_filter( 'frm_pre_update_entry', 'check_if_value_changed', 10, 2 ); function check_if_value_changed( $values, $entry_id )
Parameters
- $values (array)
- $entry_id (integer)
Examples
Check If Value Has Changed
You can use the following example to check to see if a value has changed. In this specific example, if the value has not changed, an email notification will not be sent.
add_filter( 'frm_pre_update_entry', 'check_if_value_changed', 10, 2 );
function check_if_value_changed( $values, $entry_id ) {
$field_id = 125; // change 125 to the id of the field to check
$previous_value = FrmEntryMeta::get_entry_meta_by_field($entry_id, $field_id);
if ( isset( $values['item_meta'][ $field_id ] ) && $values['item_meta'][ $field_id ] == $previous_value ) {
// do something if the value did not change
add_action( 'frm_trigger_email_action', 'frm_stop_email', 1 );
}
return $values;
}
function frm_stop_email(){
remove_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10 );
}
Replace less than operator reference
Use this code snippet to convert every <; to a < on create and update for a target field. Replace 7173 with your target field ID.
add_filter( 'frm_pre_create_entry', 'convert_encoded_lt_back' );
add_filter( 'frm_pre_update_entry', 'convert_encoded_lt_back' );
function convert_encoded_lt_back( $values ) {
$target_field_id = 7173; //Change 7173 to the ID of your target field.
if ( ! empty( $values['item_meta'][ $target_field_id ] ) ) {
$values['item_meta'][ $target_field_id ] = str_replace(
'<;',
'<',
$values['item_meta'][ $target_field_id ]
);
$_POST['item_meta'][ $target_field_id ] = $values['item_meta'][ $target_field_id ];
}
return $values;
}