Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing submit messages for Form #1817

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading