Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#49039 closed enhancement (duplicate)

JavaScript/jQuery validation for comment form

Reported by: guddu1315's profile guddu1315 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3.1
Component: Comments Keywords:
Focuses: ui Cc:

Description

Hello,

When a user tries to submit the comment form with blank values. He/She is redirected to domain.com/wp-comments-post.php which is quite bad in terms of UI/UX.
As the user is redirected to another page and then he comes back to the same page.
So basically we redirect the user to another page just to show the error messages.

It would be great if we can manage validations using JavaScript or jQuery.
So the user gets the error messages on the same page he doesn't have to go anywhere.

Thank you.

Attachments (2)

comment-form.png (44.3 KB) - added by guddu1315 5 years ago.
comment-form-error.png (6.6 KB) - added by guddu1315 5 years ago.

Download all attachments as: .zip

Change History (6)

#1 follow-ups: @subrataemfluence
5 years ago

Rather than adding JavaScript validation, what if we go with required attributes for mandatory fields.

#2 in reply to: ↑ 1 ; follow-up: @guddu1315
5 years ago

  • Summary changed from jQuery validation for comment form to JavaScript/jQuery validation for comment form

Replying to subrataemfluence:

Rather than adding JavaScript validation, what if we go with required attributes for mandatory fields.

Hi @subrataemfluence

But considering the old browsers compatibility (https://caniuse.com/#feat=mdn-api_htmlinputelement_required), JavaScript validation would be a better option.

According to https://caniuse.com/#feat=mdn-api_htmlinputelement_required
the browser that don't support required attribute and still in usage is around 27%

27% is a very high number. So that is definitely not an option.

Thanks

Last edited 5 years ago by guddu1315 (previous) (diff)

#3 in reply to: ↑ 1 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, thanks for the ticket! Just noting this was previously raised in #47728.

Replying to subrataemfluence:

Rather than adding JavaScript validation, what if we go with required attributes for mandatory fields.

The comment form does have required attribute for the <input> fields, however it also has the novalidate attribute on the form, which prevents client-side validation from being performed due to concerns about browsers implementing validation in very different ways, per discussion in #15080.

We're now re-evaluating that decision in #47595, let's continue the discussion there.

#4 in reply to: ↑ 2 @subrataemfluence
5 years ago

Since @SergeyBiryukov has said that further discussion should be made in #47595, I would just like to share my thoughts:

  1. The attribute required is now been used in most websites these days since HTML5 is now has become the most used one if not the only. So I don't find any negative in using this attribute over JavaScript validation.
  1. If required is the solution, it will only be implemented in the upcoming release and won't be incorporated in older versions of WordPress. Sites developed in 5.3.x will always use HTML5. Bootstrap uses HTML5. Modern sites are being developed targeting modern browsers only.
  1. We also need to remember that a lot of CSS rules we are using these days were not previously supported by older browsers. If we take such older browsers into consideration, we have to go back to the old CSS writing styles as well.

I apologize for replying in this ticket.

Replying to guddu1315:

Replying to subrataemfluence:

Rather than adding JavaScript validation, what if we go with required attributes for mandatory fields.

Hi @subrataemfluence

But considering the old browsers compatibility (https://caniuse.com/#feat=mdn-api_htmlinputelement_required), JavaScript validation would be a better option.

According to https://caniuse.com/#feat=mdn-api_htmlinputelement_required
the browser that don't support required attribute and still in usage is around 27%

27% is a very high number. So that is definitely not an option.

Thanks

Note: See TracTickets for help on using tickets.