Componette

Componette

tomaj

tomaj / nette-bootstrap-form 2.1.1

Bootstrap renderers (horizontal, vertical, inline) for Nette Forms.

download-cloud-line composer require tomaj/nette-bootstrap-form

Nette Bootstrap Form

Bootstrap renderers (horizontal, vertical, inline) for Nette Forms

Documentation: https://tomaj.github.io/nette-bootstrap-form/

Getting started · Renderers · API reference · Changelog

Latest Stable Version CI Coverage Status PHPStan OpenSSF Scorecard Documentation License PHP Version

What is Nette Bootstrap Form?

Nette Bootstrap Form is a set of form renderers for Nette Forms that output Bootstrap 3 form markup. Set a renderer on a form and every control gets the Bootstrap classes and wrappers, with no template code:

  • BootstrapRenderer: horizontal form (form-horizontal, labels in col-sm-3, controls in col-sm-9)
  • BootstrapVerticalRenderer: the default Bootstrap layout, label above the control
  • BootstrapInlineRenderer: inline form (form-inline)

Text inputs, text areas and selects get form-control, the first button btn btn-primary and the others btn btn-default (buttons that already have a btn class are left alone), checkboxes and radio lists are wrapped for Bootstrap, and errors are shown in an alert alert-danger box.

Installation

This library requires PHP 8.4 or later and nette/forms 3.2 or later.

composer require tomaj/nette-bootstrap-form

Usage

use Nette\Forms\Form;
use Tomaj\Form\Renderer\BootstrapRenderer;

$form = new Form();
$form->addText('name', 'Name')->setRequired();
$form->addSubmit('send', 'Send');

$form->setRenderer(new BootstrapRenderer());

echo $form;

Use BootstrapVerticalRenderer or BootstrapInlineRenderer the same way. All three take an optional $novalidate argument (default true); pass false to keep the browser's HTML5 validation. Read the documentation for the rendered markup, button classes and customizing the wrappers.

Upgrading

See UPGRADE-3.0.md for upgrading from 2.x and CHANGELOG.md for all changes.

Contributing

See CONTRIBUTING.md. Everyone taking part follows the Code of Conduct.

Security

Report vulnerabilities in private, as described in SECURITY.md. Do not open a public issue.

License

nette-bootstrap-form is licensed under the GNU Lesser General Public License, version 2.0 or later (LGPL-2.0-or-later, as declared in composer.json).

  • 2.1.1 2.1.1

    Tagged on 2026-03-26.

    Fixed

    • PHP 8.4: render() declares ?string $mode = null explicitly, so the "Implicitly marking parameter as nullable is deprecated" notice is gone. (#19)

    Full Changelog: 2.1.0...2.1.1

  • 2.1.0 2.1.0

    Tagged on 2024-02-19.

    Support for nette/forms 3.2.

    Changed

    • BREAKING CHANGE: requires nette/forms ^3.2 (was ^3.0). Upgrade nette/forms together with this package. (#17)
    • BREAKING CHANGE: the $wrappers property of all three renderers is typed public array $wrappers, as in nette/forms 3.2 DefaultFormRenderer. A subclass that redeclares $wrappers must declare it as array too. (#17)

    Fixed

    • Using the renderers with nette/forms 3.2 no longer fails with "Type of $wrappers must be array". (#17)

    Full Changelog: 2.0.1...2.1.0

  • 2.0.1 2.0.1

    Tagged on 2022-01-11.

    Fixed

    • PHP 8.1: rendering a button without a CSS class no longer triggers the "Passing null to parameter of type string" deprecation in strpos(). (#15)

    Full Changelog: 2.0.0...2.0.1

  • 1.3.0 1.3.0

    Tagged on 2017-08-28.

    Added

    • All three renderers accept a $novalidate constructor argument (new BootstrapRenderer(false)) to keep the browser's HTML5 validation. The default stays true, so existing forms still get novalidate. (#13)

    Full Changelog: 1.2.0...1.3.0

  • 1.1.0 1.1.0

    Tagged on 2015-07-07.

    Changed

    • BootstrapRenderer: the controls container and the hidden-fields container are plain <div>s instead of <div class="col-sm-12">, so the horizontal form no longer wraps its rows in an extra full-width column.

    Full Changelog: 1.0.0...1.1.0

  • 1.0.0 1.0.0

    Tagged on 2015-07-06.

    Initial release.

    Bootstrap 3 renderers for Nette Forms 2.3 (PHP 5.3.7+):

    • Tomaj\Form\Renderer\BootstrapRenderer renders a horizontal form (form-horizontal, labels in col-sm-3, controls in col-sm-9).
    • Tomaj\Form\Renderer\BootstrapInlineRenderer renders an inline form (form-inline).
    • Text inputs, selects and multi-selects get form-control; the first button gets btn btn-primary, the others btn btn-default; checkboxes and radio lists are wrapped for Bootstrap; errors are shown in an alert alert-danger box; the form gets novalidate.
  • 2.0.0 2.0.0

    Updated min php version to 7.1
    Requires nette/form 3.0

  • 1.2.0 1.2.0

    Added Vertical bootstrap from (thanks to ales-zrak)

Componette Componette felix@nette.org