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 can be used to manipulate a form's success message.
Usage
add_filter('frm_success_filter', 'change_my_confirmation_method', 10, 2);
Parameters
- $type (array | string): An array of Confirmation actions, supported since Formidable Forms v6.0. If an empty array is returned, the default success message will be used. Possible return values are: message, redirect, or page.
- $form (object)
- $action (string): Used to check if this filter is running when creating or updating an entry. Possible values are: create or update.
Examples
Force Success Message on Update
This example will always show the success message when an entry is updated, even if the setting tells the form to redirect.
add_filter('frm_success_filter', 'change_my_confirmation_method', 10, 2);
function change_my_confirmation_method( $type, $form ) {
if ( $form->id == 5 && isset( $_POST ) && isset( $_POST['frm_action'] ) && $_POST['frm_action'] == 'update' ) { //change 5 to the ID of your form
$type = 'message';
}
return $type;
}
Force Success Message and Change Message
The example below will force a success message and set the message to "The form has been received."
add_filter('frm_success_filter', 'force_change_success_message', 10, 2);
function force_change_success_message( $type, $form ) {
if ( $form->id == 5 && isset( $_POST ) && isset( $_POST['frm_action'] )) { //change 5 to the ID of your form
$type = 'message';
$form->options['success_msg'] = "The form has been received.";
}
return $type;
}
Prevent redirect action when updating entry
Use this code example to check if there is a redirect action. If there is any, remove the redirect action when updating an entry.
add_filter('frm_success_filter', 'prevent_redirect_action' , 10, 2);
function prevent_redirect_action( $type, $form, $action ) {
if ( $form->id != 5 || 'update' != $action ) {
return $type;
}
if ( 'redirect' == $type ) {
return 'message';
}
if ( is_array( $type ) ) {
foreach ( $type as $index => $conf_action ) {
if ( 'redirect' == FrmOnSubmitHelper::get_action_type( $conf_action ) ) {
unset( $type[ $index ] );
}
}
}
return $type;
}