What's New in Nette 2.1: Forms

by Jan Smitka 4 years ago in Tutorials

Forms have always been a key part of the framework. Ever since the first version, forms have allowed developers to easily define input elements, render them, and process user submitted data. Nette 2.1 brings several new features and addresses number of issues and restrictions from previous versions.

This article covers most significant form improvements:

  • new low-level access to form data,
  • improved rendering using n: attributes, and
  • new features in the form validation.

Low-Level Access

In previous versions of Nette, all form fields had to be defined during form initialization. This is a great feature for strictly defined forms, e.g. a registration dialog, but it has been rather limiting when creating dynamic forms. The developer had to build the entire form when it was created, or create a custom control that handled the dynamic data.

For example, if we want to create a table with a selection checkbox on each row, the most straightforward approach is to iterate the table rows twice: once in your form definition, and once when you were rendering the form.

In the new version, however, it is no longer necessary to iterate twice. You can simply render any HTML input you like and access its value through the new Form::getHttpData() method.

…more