nette / forms
📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.
Installs: 9 434 530
Dependents: 474
Suggesters: 5
Security: 0
Stars: 496
Watchers: 52
Forks: 147
Open Issues: 32
Requires
- php: 8.1 - 8.4
- nette/component-model: ^3.1
- nette/http: ^3.3
- nette/utils: ^4.0.4
Requires (Dev)
- latte/latte: ^2.10.2 || ^3.0.12
- nette/application: ^3.0
- nette/di: ^3.0
- nette/tester: ^2.5.2
- phpstan/phpstan-nette: ^1
- tracy/tracy: ^2.9
Suggests
- ext-intl: to use date/time controls
Conflicts
- latte/latte: >=3.0.0 <3.0.12 || >=3.1
- dev-master / 4.0.x-dev
- v3.2.x-dev
- v3.2.5
- v3.2.4
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.x-dev
- v3.1.15
- v3.1.14
- v3.1.12
- v3.1.11
- v3.1.10
- v3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.x-dev
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.4.x-dev
- v2.4.11
- v2.4.10
- v2.4.9
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.x-dev
- v2.3.12
- v2.3.11
- v2.3.10
- v2.3.9
- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- 2.2.x-dev
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
This package is auto-updated.
Last update: 2024-10-31 18:13:03 UTC
README
Introduction
Nette\Forms greatly facilitates creating and processing web forms. What it can really do?
- validate sent data both client-side (JavaScript) and server-side
- provide high level of security
- multiple render modes
- translations, i18n
Why should you bother setting up framework for a simple web form? You won't have to take care about routine tasks such as writing two validation scripts (client and server) and your code will be safe against security breaches.
Nette Framework puts a great effort to be safe and since forms are the most common user input, Nette forms are as good as impenetrable. All is maintained dynamically and transparently, nothing has to be set manually. Well known vulnerabilities such as Cross Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) are filtered, as well as special control characters. All inputs are checked for UTF-8 validity. Every multiple-choice, select box and similar are checked for forged values upon validating. Sounds good? Let's try it out.
Documentation can be found on the website.
Support Me
Do you like Nette Forms? Are you looking forward to the new features?
Thank you!
Installation
The recommended way to install is via Composer:
composer require nette/forms
It requires PHP version 8.1 and supports PHP up to 8.4.
Client-side support can be installed with npm or yarn:
npm install nette-forms
Usage
Let's create a simple registration form:
use Nette\Forms\Form; $form = new Form; $form->addText('name', 'Name:'); $form->addPassword('password', 'Password:'); $form->addSubmit('send', 'Register'); echo $form; // renders the form
Though we mentioned validation, yet our form has none. Let's fix it. We require users to tell us their name, so we should call a setRequired()
method, which optional argument is an error message to show, if user does not fill his name in:
$form->addText('name', 'Name:') ->setRequired('Please fill your name.');
Try submitting a form without the name - you will keep seeing this message until you meet the validation rules. All that is left for us is setting up JavaScript rules. Luckily it's a piece of cake. We only have to link netteForms.js
, which is located at /client-side/forms
in the distribution package.
<script src="netteForms.js"></script>
Nette Framework adds required
class to all mandatory elements. Adding the following style will turn label of name input to red.
<style> .required label { color: maroon } </style>