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

Add global setting for form submission message #1615

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3218,6 +3218,7 @@ public static function localize_script( $location ) {
'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
'focus_first_error' => self::should_focus_first_error(),
'include_alert_role' => self::should_include_alert_role_on_field_errors(),
'submit_speak_msg' => ( new FrmSettings() )->submit_speak_msg,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing tilde character.

- 3221~
+ 3221

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
'submit_speak_msg' => ( new FrmSettings() )->submit_speak_msg,
'submit_speak_msg' => ( new FrmSettings() )->submit_speak_msg,

);

$data = $wp_scripts->get_data( 'formidable', 'data' );
Expand Down
9 changes: 8 additions & 1 deletion classes/models/FrmSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ class FrmSettings {
*/
public $custom_css;

/**
* @since x.x
* @var string
*/
public $submit_speak_msg;

public function __construct( $args = array() ) {
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
Expand Down Expand Up @@ -167,6 +173,7 @@ public function default_options() {
// Normally custom CSS is a string. A false value is used when nothing has been set.
// When it is false, we try to use the old custom_key value from the default style's post_content array.
'custom_css' => false,
'submit_speak_msg' => __( 'Form submitted. Please wait for the request to process.', 'formidable' ),
);
}

Expand Down Expand Up @@ -215,7 +222,7 @@ public function fill_with_defaults( $params = array() ) {
$filter_html = ! FrmAppHelper::allow_unfiltered_html();

if ( $filter_html ) {
$filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
$filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu', 'submit_speak_msg' );
if ( ! empty( $params['additional_filter_keys'] ) ) {
$filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
}
Expand Down
11 changes: 11 additions & 0 deletions classes/views/frm-settings/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,14 @@ class="frm_with_left_label"
id="frm_submit_value" name="frm_submit_value"
class="frm_with_left_label"/>
</p>

<p>
<label for="frm_submit_speak_msg" class="frm_left_label"><?php esc_html_e( 'Submit Speak Text', 'formidable' ); ?>
<span class="frm_help frm_icon_font frm_tooltip_icon"
title="<?php esc_attr_e( 'The text announced by screen reader when a form is submitted.', 'formidable' ); ?>"></span>
</label>
<input type="text"
value="<?php echo esc_attr( $frm_settings->submit_speak_msg ); ?>"
id="frm_submit_speak_msg" name="frm_submit_speak_msg"
class="frm_with_left_label"/>
</p>
25 changes: 23 additions & 2 deletions js/formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ function frmFrontFormJS() {
maybeAddPolyfills();

jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.handleSubmit );

jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
if ( jQuery( this ).val() === '' ) {
Expand Down Expand Up @@ -1649,8 +1649,29 @@ function frmFrontFormJS() {
frmFrontForm.submitFormNow( object );
},

handleSubmit: function( e ) {
AbdiTolesa marked this conversation as resolved.
Show resolved Hide resolved
frmFrontForm.submitForm( e );
frmFrontForm.speak( frm_js.submit_speak_msg );
},

speak: function( message ) {
var element = document.createElement( 'div' );
element.id = 'speak_formidable_form_submitted';
element.setAttribute( 'aria-live', 'assertive' );
element.className = 'frm_screen_reader frm_hidden';
element.textContent = message;
document.body.appendChild( element );

setTimeout(
function() {
document.body.removeChild( element );
},
1000
);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the speak method to manage the temporary element more robustly, possibly by checking if the element still exists before attempting to remove it.


submitForm: function( e ) {
frmFrontForm.submitFormManual( e, this );
frmFrontForm.submitFormManual( e, e.target );
},

submitFormManual: function( e, object ) {
Expand Down
Loading