agentleFS
AnyOrgNameAnyOrgName/php-skills/skills/laminas/forms/SKILL.md

forms

Skill4 starsChanged 4 months agoMITView on GitHub

Build and validate input with laminas-form — Form and Fieldset composition, input filters, validators, and safe binding of untrusted request data. Use when the user wants to hydrate a form from an entity and bind validated data back onto the object; the user needs to build a laminas-form with elements, or compose reusable fieldsets, to render and capture user input; the user wants to validate and filter submitted request data against rules before using it, using an input filter. Keywords: laminas, forms, fieldset, input-filter, validation, input.

10 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use navigation.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • igorescodroSkill

    navigation

    Use when adding a new screen or modifying navigation in the Alkaa project — triggers on tasks like "add a new screen", "navigate to X", "add destination", "wire up navigation", or "create a navigation event". Also triggers when connecting UI actions to routes in NavGraph.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not reach for the full Form object when a JSON API only needs to validate a payload.

    line 64
  2. Very specific:

    Do not use this skill for Symfony Form, Laravel form requests, or client-side-only form markup.

    line 65

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- generated: do not edit — source: knowledge/atoms/laminas/forms/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->

Laminas Forms

When to use

  • The user wants to hydrate a form from an entity and bind validated data back onto the object.
  • The user needs to build a laminas-form with elements, or compose reusable fieldsets, to render and capture user input.
  • The user wants to validate and filter submitted request data against rules before using it, using an input filter.

When NOT to use

  • Do not reach for the full Form object when a JSON API only needs to validate a payload; a standalone input filter is lighter and sufficient.
  • Do not use this skill for Symfony Form, Laravel form requests, or client-side-only form markup; the Form/Fieldset/InputFilter API is Laminas specific.

Core guidance

  • Read getData only after isValid returns true — Call setData($request->getPost()) then isValid(), and only read getData() (filtered, validated values) once isValid() has returned true.
  • Keep validation in an input filter, not in the elements — Define validators and filters in an InputFilter (via getInputFilterSpecification() on the fieldset or a dedicated input-filter class), not ad hoc in the controller after submission.

Quick recipe

  1. Extend Laminas\Form\Form, add each element in init() with its name and type, and include a Csrf element for state-changing forms. (verify: The form renders every declared element plus the CSRF token)
  2. Implement getInputFilterSpecification() returning per-field required, filters, and validators entries so submitted data is filtered and checked. (verify: Invalid submissions fail isValid() with per-field messages)
  3. In the controller, bind the entity, call setData($request->getPost()), and on isValid() read getData(); on failure, re-render the form with its messages. (verify: Valid input updates the entity; invalid input re-renders with errors and no 500)

Best practices

  • Include a Csrf element on any form that mutates state so submission fails validation unless the request carries a valid, unexpired token
  • Model a cohesive group of fields (an address, a contact) as a Fieldset and compose it into forms, rather than repeating the same elements in each form
  • Set a hydrator on the fieldset and call $form->bind($entity) before validation so that, on success, filtered values are written straight onto the domain object

Anti-patterns

Anti-patternWhy it failsDo instead
Writing raw POST data straight onto the entityRaw request data is unfiltered and unvalidated, so this reintroduces injection and mass-assignment risks the form removes.Bind the entity to the form with a hydrator and let getData() write only validated values.
Echoing submitted values without view-helper escapingRe-rendering user input verbatim on validation failure opens a reflected XSS hole.Render fields through formElement/formRow view helpers (which escape), and escape any custom output with escapeHtml.
Hand-writing validation in the controllerDuplicated ad hoc validation drifts from the form's rules and misses the filtering the input filter would apply.Declare all rules in the form's input filter and rely on isValid() as the single validation gate.

See references/anti-patterns.md.

Common mistakes

  1. Csrf validation fails after the token TTL or a new session — A Csrf element rejects a submission when its token has expired (default short TTL) or the session was regenerated between render and submit. Fix: Tune the Csrf element timeout, re-render the form (with a fresh token) on failure, and preserve the session across the render-submit cycle.
  2. Reading getData before isValid runs the filter — Calling getData() before isValid() returns unfiltered, unvalidated values (or throws in strict mode). Fix: Always order the calls as setData -> isValid -> getData, and branch on the boolean result.
  3. Required-by-default inputs reject legitimately empty fields — An input is required by default, so an optional field with no value fails validation until you mark it required false with allow_empty true. Fix: In the input filter spec, set required to false and allow_empty to true for genuinely optional inputs.

Version notes

  • laminas-form 3 adds elements in init, not the constructor — In laminas-form 3, build form elements inside init() (called by the form element manager after construction) so factory-created forms have their dependencies ready, rather than adding elements in __construct().

Security

  • Treat form input as untrusted until isValid passes — Feed the raw request into the form with setData(), run isValid(), and consume only getData() afterwards; never trust $request->getPost() values directly, and attach a Csrf element plus escaping in the view layer.

Testing

  • Activation and decision behavior are verified in eval/scenarios/laminas/forms.yaml.

Additional resources

  • references/anti-patterns.md
  • references/core.md
  • references/examples.md
  • references/pitfalls.md
  • references/recipes.md
  • references/version-differences.md

Knowledge graph

Related: laminas/mvc, php/typed-properties

<!-- graph-fragment: graph/fragments/laminas/forms.yaml -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.