Skip to content

Forms

Each chapter adds one idea, and shows it for both Mezzio and laminas-mvc. The form classes and form templates are identical in both.

New to the front end? Styling forms shows the whole stylesheet, how to use it without any build tools, and how to change it.

You should already know the basics of whichever framework you use.

Conventions

  • A form is a class that adds its elements in init().
  • Fetch it from FormElementManager, so factories and init() run.
  • Filtering and validation rules live in getInputFilterSpecification().
  • Pass options to filters and validators as arrays. Their setter methods are deprecated.

Accessibility

The examples aim at WCAG 2.2 level AA:

  • every field has a visible label
  • personal details carry autocomplete tokens, so browsers can fill them in
  • hints and errors are tied to their field with aria-describedby, and invalid fields have aria-invalid
  • after a failed submission an error summary takes focus and links to each field, and the page title starts with "Error:"
  • error messages say how to fix the problem

Automated checks (axe) run against the empty, invalid and successful states. They catch only some problems, so test your own pages with a keyboard and a screen reader too.