Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Forms Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Standalone vs. Integrated Use: Use Form directly for simple scripts; in Nette apps, leverage FormFactory + DI (FormsExtension) to declare forms as reusable services with initialize() hooks.
  • Control Grouping & Theming: Organize with 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.
  • Dynamic Forms & Conditional Logic: Use 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.
  • Data Hydration: Map validated input directly to DTOs/Entities via getValues(MyDto::class) (v3.1+). Use getUntrustedValues() when custom sanitization is needed before hydration.
  • Client Validation: Include 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.

Gotchas and Tips

  • Breaking Changes (v3.2+): Requires PHP 8.1+. 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.
  • Hidden Field Pitfall: Pre-v3.0.3, HiddenField cast values to strings — now types are preserved and setNullable() is supported. Ensure null defaults align with expectation.
  • Upload Control Quirks: Auto-adds MAX_FILE_SIZE and enforces PHP’s upload_max_filesize — silent failures occur if file exceeds server limits. Use setNullable() for optional uploads.
  • Validation Scope Missteps: 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).
  • Latte Integration: {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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport