nette/forms
Nette Forms is a PHP form-building library for creating secure, reusable web forms with built-in validation, CSRF protection, rendering helpers, and easy component composition. Integrates smoothly with Nette Framework but works standalone in any PHP app.
Start by installing via Composer (composer require nette/forms) and importing core classes (Nette\Forms\Form, Nette\Forms\Controls\TextInput, etc.). Create a basic form in a controller: define fields like addText('name')->setRequired(), add validators (e.g., addRule(Form::EMAIL)), and bind a submit button. Handle submission by calling $form->isValid(); if true, use getValues() to retrieve sanitized data. For rendering, pair with Latte using {form $form} {input name} {/form}, or render manually with getControls() and DefaultFormRenderer. Check the examples/ directory in the repo for minimal working templates.
Form directly for simple scripts; in Nette apps, leverage FormFactory + DI (FormsExtension) to declare forms as reusable services with initialize() hooks.addGroup('Personal Info') and label via setOption('caption', '...'). Customize layout by extending DefaultFormRenderer or passing custom renderer to setRenderer(). Override defaults with setOption('class', 'form-control') on controls.addContainer() + addPrototype() for repeatable fieldsets; setDepends() enables client-side toggling based on other fields (e.g., show "company" field when "type = business"). Attach onValidate/onSuccess handlers for post-submission enrichment.getValues(MyDto::class) (v3.1+). Use getUntrustedValues() when custom sanitization is needed before hydration.netteForms.js (TS-powered in v3.2.4+); auto-syncs server rules to client. In Latte, wrap forms with {formContext} for per-form context, and use {inputError} macro for inline error display.getValues() now excludes out-of-scope controls (v3.1); removed getValues(true) use getUntrustedValues() instead. URL validation auto-appends https://; onValidate only receives values if the form is valid.HiddenField cast values to strings — now types are preserved and setNullable() is supported. Ensure null defaults align with expectation.MAX_FILE_SIZE and enforces PHP’s upload_max_filesize — silent failures occur if file exceeds server limits. Use setNullable() for optional uploads.getValues() returns only fields within the form’s current validation scope — verify with $form->getValidationScope() and adjust containers/rules accordingly. Empty CheckboxList/RadioList returns empty control instead of failing (v3.2.8).{formPrint} outputs form markup cleanly but requires {formContext} in v3.1+; {inputError} must be passed the control name explicitly. Avoid empty <label> tags by ensuring CheckboxList/RadioList items have non-empty keys.How can I help you explore Laravel packages today?