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 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
1 change: 1 addition & 0 deletions classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3286,6 +3286,7 @@ public static function localize_script( $location ) {
'focus_first_error' => self::should_focus_first_error(),
'include_alert_role' => self::should_include_alert_role_on_field_errors(),
'include_resend_email' => self::should_include_resend_email_code(),
'submit_speak_msg' => FrmFormsHelper::get_submit_speak_message(),
);

$data = $wp_scripts->get_data( 'formidable', 'data' );
Expand Down
17 changes: 17 additions & 0 deletions classes/helpers/FrmFormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ public static function get_invalid_error_message( $args ) {
return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args );
}

/**
* Returns the message announced when a form is submitted.
*
* @since x.x
*
* @return string
*/
public static function get_submit_speak_message() {
/**
* Allows updating a message announced when a form is submitted.
*
* @since x.x
* @param string $submit_speak_message
*/
return apply_filters( 'frm_submit_speak_message', __( 'Form submitted', 'formidable' ) );
}
Comment on lines +263 to +278
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the @since tag in the get_submit_speak_message method is updated to reflect the actual version being released.

- * @since x.x
+ * @since 4.05  // Example version, replace with the actual version being released
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Returns the message announced when a form is submitted.
*
* @since x.x
*
* @return string
*/
public static function get_submit_speak_message() {
/**
* Allows updating a message announced when a form is submitted.
*
* @since x.x
* @param string $submit_speak_message
*/
return apply_filters( 'frm_submit_speak_message', __( 'Form submitted', 'formidable' ) );
}
/**
* Returns the message announced when a form is submitted.
*
* @since 4.05 // Example version, replace with the actual version being released
*
* @return string
*/
public static function get_submit_speak_message() {
/**
* Allows updating a message announced when a form is submitted.
*
* @since x.x
* @param string $submit_speak_message
*/
return apply_filters( 'frm_submit_speak_message', __( 'Form submitted', 'formidable' ) );
}


/**
* @param array $atts {
* The success message details.
Expand Down
18 changes: 17 additions & 1 deletion js/formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,24 @@ function frmFrontFormJS() {
frmFrontForm.submitFormNow( object );
},

speak: function( message ) {
var element = document.createElement( 'div' );
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 );
},
0
);
},

submitForm: function( e ) {
frmFrontForm.submitFormManual( e, this );
frmFrontForm.submitFormManual( e, e.target );
frmFrontForm.speak( frm_js.submit_speak_msg ); // eslint-disable-line camelcase
},

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