Skip to content

Commit

Permalink
fix: missing submit messages for Form
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Aug 16, 2023
1 parent ccae01a commit 7dc8e53
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
20 changes: 16 additions & 4 deletions inc/integrations/api/form-response-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
16 changes: 9 additions & 7 deletions inc/server/class-form-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/blocks/form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,10 @@ const Edit = ({
<Fragment>
<div>
<div className='o-form-server-response o-success' style={{ color: attributes.submitMessageColor }}>
{ formOptions.submitMessage || __( 'Success', 'otter-blocks' ) }
{ formOptions.submitMessage ?? __( 'Success', 'otter-blocks' ) }
</div>
<div className='o-form-server-response o-error' style={{ color: attributes.submitMessageErrorColor, margin: '0px' }}>
{ __( 'Error. Please try again.', 'otter-blocks' ) }
{ formOptions.errorMessage ?? __( 'Error. Please try again.', 'otter-blocks' ) }
</div>
</div>
{
Expand Down

0 comments on commit 7dc8e53

Please sign in to comment.