diff --git a/inc/integrations/api/form-response-data.php b/inc/integrations/api/form-response-data.php index 85a8d3dd2..c2be56dae 100644 --- a/inc/integrations/api/form-response-data.php +++ b/inc/integrations/api/form-response-data.php @@ -83,10 +83,11 @@ class Form_Data_Response { * @since 2.0.0 */ public function __construct() { - $this->response['success'] = false; - $this->response['reasons'] = array(); - $this->response['code'] = self::SUCCESS_EMAIL_SEND; - $this->response['displayError'] = 'Error. Please try again.'; + $this->response['success'] = false; + $this->response['reasons'] = array(); + $this->response['code'] = self::SUCCESS_EMAIL_SEND; + $this->response['displayError'] = 'Error. Please try again.'; + $this->response['submitMessage'] = 'Success'; } /** @@ -148,6 +149,17 @@ public function set_reasons( $reasons ) { return $this; } + /** + * Set success message. + * + * @param string $message The message. + * @since 2.4 + */ + public function set_success_message( $message ) { + $this->response['submitMessage'] = $message; + return $this; + } + /** * Check if success. * diff --git a/inc/server/class-form-server.php b/inc/server/class-form-server.php index c586f4f51..a5f351685 100644 --- a/inc/server/class-form-server.php +++ b/inc/server/class-form-server.php @@ -278,20 +278,22 @@ public function frontend( $request ) { do_action( 'otter_form_after_submit', $form_data ); if ( ! ( $form_data instanceof Form_Data_Request ) ) { - $res->set_code( Form_Data_Response::ERROR_RUNTIME_ERROR ); - $res->add_reason( __( 'The form data class is not valid after performing provider actions! Some hook is corrupting the data.', 'otter-blocks' ) ); + $res->set_code( Form_Data_Response::ERROR_RUNTIME_ERROR ) + ->add_reason( __( 'The form data class is not valid after performing provider actions! Some hook is corrupting the data.', 'otter-blocks' ) ); } if ( $form_data->has_error() ) { - $res->set_code( $form_data->get_error_code() ); + $res->set_code( $form_data->get_error_code() ) + ->set_display_error( $form_options->get_error_message() ); } else { - $res->set_code( Form_Data_Response::SUCCESS_EMAIL_SEND ); - $res->mark_as_success(); + $res->set_code( Form_Data_Response::SUCCESS_EMAIL_SEND ) + ->set_success_message( $form_options->get_submit_message() ) + ->mark_as_success(); } } } catch ( Exception $e ) { - $res->set_code( Form_Data_Response::ERROR_RUNTIME_ERROR ); - $res->add_reason( $e->getMessage() ); + $res->set_code( Form_Data_Response::ERROR_RUNTIME_ERROR ) + ->add_reason( $e->getMessage() ); $form_data->set_error( Form_Data_Response::ERROR_RUNTIME_ERROR, $e->getMessage() ); $this->send_error_email( $form_data ); } finally { diff --git a/src/blocks/blocks/form/edit.js b/src/blocks/blocks/form/edit.js index 3a9029201..b9d029969 100644 --- a/src/blocks/blocks/form/edit.js +++ b/src/blocks/blocks/form/edit.js @@ -981,10 +981,10 @@ const Edit = ({
- { formOptions.submitMessage || __( 'Success', 'otter-blocks' ) } + { formOptions.submitMessage ?? __( 'Success', 'otter-blocks' ) }
- { __( 'Error. Please try again.', 'otter-blocks' ) } + { formOptions.errorMessage ?? __( 'Error. Please try again.', 'otter-blocks' ) }
{