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.
Pros:
netteForms.js), enabling progressive enhancement without tight coupling.FormFactory in v3.1.2).addEmail(), addInteger()) reduce Laravel’s need for manual validation logic (e.g., replacing Laravel’s Request::validate() for complex forms).netteForms.js provides real-time validation (e.g., data-nette-rules), reducing reliance on Laravel’s frontend frameworks (e.g., Livewire, Inertia) for form logic.Cons:
FormFactory in a Laravel service provider) to integrate seamlessly. The package assumes Nette’s Application context, which may need mocking or abstraction.DefaultFormRenderer) to replicate Latte macros ({formPrint}, {input}). The package’s Blueprint feature (v3.1.15) could mitigate this by generating Blade-compatible HTML.onValidate) differs from Laravel’s service container events. Bridging this (e.g., via Laravel’s Events facade) adds complexity.Laravel Compatibility:
Http and Utils may require version pinning (e.g., nette/http:^3.1).// Laravel Service Provider
public function register() {
$this->app->singleton('nette.form.factory', function () {
return new \Nette\Application\UI\FormFactory();
});
}
Validator and Nette’s Rules can coexist, but custom rules (e.g., addCallback()) may need Laravel-specific adapters.Key Integration Points:
| Nette Forms Feature | Laravel Equivalent | Integration Approach |
|---|---|---|
FormFactory |
Laravel’s FormRequest |
Wrap FormFactory in a Laravel service. |
Latte macros ({formPrint}) |
Blade directives | Create custom Blade components or use Blueprint. |
netteForms.js |
Laravel Mix/Vite + Alpine.js | Include JS bundle via Laravel’s asset pipeline. |
| CSRF protection | Laravel’s VerifyCsrfToken |
Disable one or create middleware to merge logic. |
Container::getValues() |
Laravel’s Validator::validate() |
Use for DTO hydration or pre-validate with Nette. |
High:
DefaultFormRenderer for Blade).onValidate events won’t integrate natively with Laravel’s Events facade, requiring manual bridging.addInteger() rejecting null by default).Medium:
Request/Validator.netteForms.js) adds complexity to Laravel’s test suite (e.g., testing both server and client rules).Low:
Template Strategy:
DefaultFormRenderer be extended to output Blade-compatible HTML?CSRF Management:
Validation Workflow:
Validator entirely, or will it handle only specific cases (e.g., complex forms)? How will validation errors be merged into Laravel’s Validator::errors()?Client-Side Integration:
netteForms.js be integrated with Laravel’s frontend stack (e.g., Alpine.js, Inertia)? Will it replace or complement existing client-side validation?Dependency Isolation:
FormsExtension::getCacheKey())?Enum/DTO Support:
Container::getValues(MyEnum::class) integrate with Laravel’s DTOs or Model binding? Will it replace or supplement Laravel’s Fillable traits?Migration Path:
Primary Use Cases:
Laravel-Specific Adaptations:
FormFactory as a Laravel singleton, with optional bindings for FormRenderer and Validator adapters.
// app/Providers/NetteFormsServiceProvider.php
public function register() {
$this->app->singleton(\Nette\Application\UI\FormFactory::class, function () {
$factory = new FormFactory();
$factory->setTranslator($this->app['translator']);
return $factory;
});
}
DefaultFormRenderer to output Blade syntax:
// app/View/Components/NetteFormComponent.php
class NetteFormComponent extends Component {
public function render(): string {
$form = resolve(FormFactory::class)->create();
// ... configure form
return view('components.nette-form', ['form' => $form]);
}
}
Rules to Laravel’s Validator:
// app/Services/NetteValidatorAdapter.php
class NetteValidatorAdapter {
public static function adapt(Nette\Forms\Rules $rules): array {
$laravelRules = [];
foreach ($rules as $rule) {
$laravelRules[] = match ($rule) {
'Email' => 'email',
'Required' => 'required',
// ...
How can I help you explore Laravel packages today?