KodingKaro
HTML · Advanced · Advanced Forms and Validation

Custom feedback and server validation

A polished form explains errors clearly, preserves entered data where possible, and still checks every submission on the server.

✓ What you will learn in this topic

  • Explain the purpose of Custom feedback and server validation in a real HTML document.
  • Choose and apply the elements shown in both examples.
  • Recognize the specific mistake described in this lesson.

Concept explanation

Custom validation may coordinate several fields or explain a business rule that HTML cannot express. Show errors next to the relevant field and provide a summary for long forms. Set aria-invalid only while a value is invalid and associate the message with aria-describedby. After submission, the server must validate type, range, authorization, and business rules because requests can be forged or sent without the browser UI.

Syntax

Use visible text, an error summary, aria-describedby, and accurate aria-invalid state; repeat validation on the server.

Example 1: a small page

The message explains how to recover and is associated with the field.

<label for=\"confirm-email\">Confirm email</label>
<input id=\"confirm-email\" name=\"confirm_email\" type=\"email\" aria-invalid=\"true\" aria-describedby=\"confirm-error\">
<p id=\"confirm-error\">The addresses do not match. Check both fields.</p>

Expected result: The invalid state and correction instruction are available when focus reaches the field.

Example 2: a practical page

A short summary announces the issue and the field-level message gives a specific correction.

<form action=\"/applications\" method=\"post\">
  <p role=\"alert\">Correct the highlighted fields before continuing.</p>
  <label for=\"portfolio\">Portfolio URL</label>
  <input id=\"portfolio\" name=\"portfolio\" type=\"url\" aria-invalid=\"true\" aria-describedby=\"portfolio-error\">
  <p id=\"portfolio-error\">Enter a complete URL beginning with https://.</p>
  <button type=\"submit\">Save application</button>
</form>

Expected result: Visitors receive both an overall error notice and the correction needed for the portfolio field.

Common mistakes

Do not present client validation as proof that submitted information is valid or safe.

Best practices

Use browser constraints for immediate feedback, provide clear recovery instructions, and validate all untrusted values on the server.

Practice exercise

Design a multi-step application form that uses native constraints, custom error messaging, server revalidation, and a useful correction summary.

Lesson summary

  • Accessible custom feedback explains the problem and its remedy; the server rechecks submitted data.
  • Use browser constraints for immediate feedback, provide clear recovery instructions, and validate all untrusted values on the server.

Knowledge check

Where must validation happen for application security?

Show the explanation

On the server, because client-side rules and browser interfaces can be bypassed or changed.

Practical example

html
<label for=\"confirm-email\">Confirm email</label>
<input id=\"confirm-email\" name=\"confirm_email\" type=\"email\" aria-invalid=\"true\" aria-describedby=\"confirm-error\">
<p id=\"confirm-error\">The addresses do not match. Check both fields.</p>

Expected result:

The invalid state and correction instruction are available when focus reaches the field.

Hands-on practice task

Design a multi-step application form that uses native constraints, custom error messaging, server revalidation, and a useful correction summary.

In this section

Other lessons in Advanced Forms and Validation

Broaden your knowledge

Related learning topics