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

Remove novalidate attribute from comment form to enable client-side validation #717

Closed
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
18 changes: 18 additions & 0 deletions pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,24 @@ function pwa_load_service_worker_integrations( WP_Service_Worker_Scripts $script
}
add_action( 'wp_default_service_workers', 'pwa_load_service_worker_integrations', -1 );

/**
* Remove `novalidate` attribute from the comment form tag.
*
* This is a fix for the `novalidate` attribute being added to the comment form by WordPress
* which disables HTML client-side validation for the form.
*/
function pwa_remove_novalidate_attribute_from_comments_form() {
?>
<script type="module">
const commentForm = document.getElementById( 'commentform' );
if ( commentForm ) {
commentForm.removeAttribute( 'novalidate' );
}
</script>
<?php
}
add_action( 'comment_form_after', 'pwa_remove_novalidate_attribute_from_comments_form', 10, 0 );

$wp_web_app_manifest = new WP_Web_App_Manifest();
$wp_web_app_manifest->init();

Expand Down