Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML concept: forms

HTML forms connect controls to an owner, validate constraints, and construct an ordered data set for submission; those three stages have distinct rules.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

form owner → constraint validation → entry list

A control is normally owned by its nearest form element, but the form attribute can associate a listed control with a form by ID even outside its subtree. Nested forms are nonconforming, and parser repair can produce a different owner than the source text suggests.

Constraints such as required and min affect checkValidity() and interactive reportValidity(). The novalidate attribute can bypass interactive validation during submission, but client validation never replaces server-side validation and authorization.

FormData constructs an entry list from successful controls in tree order. A control without name, with disabled, an unchecked choice requiring checked, or an unsuccessful button contributes no ordinary entry; encoding and the submitter can further affect the final request.

The example associates an external control through form, observes failing and passing checkValidity(), and then constructs FormData. Its result includes the external control but excludes the disabled and unnamed fields, without making a network request.

Examples

<!doctype html>
<meta charset="utf-8">
<form id="order">
  <input name="sku" value="A" required>
  <input id="qty" name="qty" type="number" min="1" value="0">
  <input name="ignored" value="x" disabled>
  <input value="no-name">
</form>
<input id="outside" form="order" name="outside" value="yes">
<output id="result"></output>
<script>
const order = document.querySelector("#order");
const qty = document.querySelector("#qty");
const outside = document.querySelector("#outside");
const before = order.checkValidity();
qty.value = "2";
const after = order.checkValidity();
const data = new URLSearchParams(new FormData(order)).toString();
result.textContent = `owner=${outside.form.id}; before=${before}; after=${after}; data=${data}; ignored=${new FormData(order).has("ignored")}`;
</script>

Result

owner=order; before=false; after=true; data=sku=A&qty=2&outside=yes; ignored=false

The executed example verifies ownership, validation, and entry-list construction; it does not simulate button activation, request encoding, or a server response.

Sources