drago-ex / form
Helper classes for Nette forms with extended inputs and shortcuts.
Requires
- php: >=8.3 <9
- latte/latte: ^3.0
- nette/application: ^3.2
- nette/forms: ^3.2
Requires (Dev)
- nette/tester: ^2.5
- phpstan/phpstan-nette: ^2.0
- tracy/tracy: ^2.10
Suggests
- drago-ex/translator: Translates the labels and messages of the forms through the translator of the form.
Provides
None
Conflicts
None
Replaces
None
README
Nette forms with typed inputs and fluent attributes (autocomplete, placeholder, read-only), and ready-made email and password fields.
Requirements
- PHP >= 8.3, < 9
- Nette Framework
- Composer
Installation
composer require drago-ex/form
Forms
$form = new Drago\Form\Forms(); $form->addTextInput('username', 'Username') ->setAutocomplete(Drago\Form\Autocomplete::Username) ->setPlaceholder('Enter your username'); $form->addIntegerInput('age', 'Age') ->setMin(0) ->setMax(120);
Inputs
Drago\Form\Forms adds addTextInput(), addEmailInput(), addPasswordInput(), addIntegerInput(),
addSlugInput() and addTextAreaInput(); their inputs have the fluent setters setAutocomplete() (values of the
Autocomplete enum), setPlaceholder() and setReadOnly(). Standard Nette controls keep working.
addSlugInput() is a text input with the Forms::SlugPattern rule (lowercase letters, numbers, single hyphens) and at most 255 characters, the length of the slug columns; the constant also fits route masks.
IntegerInput is validated as an integer on the server, like Nette's addInteger(): an empty value is null
and a valid value is converted to int. setMin() and setMax() add server-side rules and render the
min and max attributes.
setReadOnly() only renders the HTML readonly attribute; the browser still submits the value and a user can
change it. For values that must not be changed, use setOmitted() and keep the value on the server, or
setDisabled().
ExtraForms
ExtraForms extends Forms with commonly used preconfigured fields:
addPasswordField()- password input namedpassword.addPasswordConfirmationField()- password confirmation namedverify, validated againstpassword.addEmailField()- email input namedemailwith autocomplete and email validation.