PHPackages                             jozefizso/bootstrap-form-renderer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. jozefizso/bootstrap-form-renderer

ActiveLibrary[Templating &amp; Views](/categories/templating)

jozefizso/bootstrap-form-renderer
=================================

Nette forms renderer with bootstrap

v2.3.0(3mo ago)130[9 issues](https://github.com/jozefizso/BootstrapFormRenderer/issues)BSD-3-ClausePHPPHP &gt;=5.6CI passing

Since Aug 25Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jozefizso/BootstrapFormRenderer)[ Packagist](https://packagist.org/packages/jozefizso/bootstrap-form-renderer)[ Docs](https://github.com/jozefizso/BootstrapFormRenderer)[ RSS](/packages/jozefizso-bootstrap-form-renderer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (13)Versions (35)Used By (0)

BootstrapFormRenderer
=====================

[](#bootstrapformrenderer)

[![Tests](https://github.com/jozefizso/BootstrapFormRenderer/actions/workflows/test.yml/badge.svg)](https://github.com/jozefizso/BootstrapFormRenderer/actions/workflows/test.yml)[![Downloads this Month](https://camo.githubusercontent.com/804eabd1ea7b4b95c108fdd2d4b2fe9b296e1e70092ab7c672608ded5cb9294b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a6f7a6566697a736f2f626f6f7473747261702d666f726d2d72656e64657265722e737667)](https://packagist.org/packages/jozefizso/bootstrap-form-renderer)[![Latest stable](https://camo.githubusercontent.com/b402eca53e296a70bbbf06ef2ad1b19836ebbd567b014d177e3ed9a644948d85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7a6566697a736f2f626f6f7473747261702d666f726d2d72656e64657265722e737667)](https://packagist.org/packages/jozefizso/bootstrap-form-renderer)

> **BootstrapFormRenderer** is a PHP library that automatically styles Nette Framework forms to look great with Bootstrap CSS. Instead of manually adding Bootstrap classes to each form field, this library handles all the styling for you.

When you build web forms using the Nette Framework, they normally render as plain HTML. This library acts as a renderer that wraps your form fields in the proper Bootstrap markup - adding the right CSS classes, error styling, field grouping, and layout structure that Bootstrap requires.

Key features
------------

[](#key-features)

- **Automatic Bootstrap styling** - Transforms standard Nette forms into Bootstrap-styled forms without manual HTML markup
- **Form validation styling** - Automatically applies Bootstrap error states and displays validation messages
- **Flexible layouts** - Supports horizontal and other Bootstrap form layouts
- **Smart field handling** - Properly handles different input types (text fields, checkboxes, radio buttons, buttons)
- **Input add-ons** - Supports prepend/append icons or text to form fields (like the @ symbol for email fields)
- **Translator support** - Works with Nette's translation system for multilingual forms
- **Group support** - Handles form field grouping with proper Bootstrap styling

Requirements
------------

[](#requirements)

- PHP 5.6, 7.0 or 7.1
- [Nette Framework](https://github.com/nette/nette) 2.3

Getting Started
---------------

[](#getting-started)

Use [composer](http://getcomposer.org/doc/00-intro.md) to install the library:

```
composer require jozefizso/bootstrap-form-renderer
```

### Compatibility with Nette Framework

[](#compatibility-with-nette-framework)

VersionBranchPHPcompatibleNette series`^3.0.0``main``>= 7.1``8.0`Nette 3.0`^2.4.0``nette-2.4``>= 5.6``8.0`Nette 2.4`^2.3.0``nette-2.3``>= 5.6``7.1`Nette 2.3`^2.2.0``nette-2.2``>= 5.6``7.0`Nette 2.2`^2.1.0``nette-2.1``>= 5.6``7.0`Nette 2.1`^2.0.0``nette-2.0``>= 5.2``5.6`Nette 2.0***Note:** Compatibility always applies to the latest patch release within each minor version series.*

Usage
-----

[](#usage)

### Step 1: Register the Renderer Extension

[](#step-1-register-the-renderer-extension)

The easiest way to set up BootstrapFormRenderer is to register the extension in your `config.neon` configuration file:

```
extensions:
    twBootstrapRenderer: Kdyby\BootstrapFormRenderer\DI\RendererExtension
```

The extension will register the `Bootstrap2FormFactory` to create Bootstrap styled forms and the Latte macro extensions like `{form body}`, `{pair}`, `{group}` and `{container}`.

#### Alternative: Register Latte macros via Nette config

[](#alternative-register-latte-macros-via-nette-config)

Use configuration files to register only the Latte macros extensions:

```
nette:
    latte:
        macros:
            - Kdyby\BootstrapFormRenderer\Latte\FormMacros
```

#### Alternative: programmatic bootstrap

[](#alternative-programmatic-bootstrap)

If you prefer to register the extension programmatically in `app/bootstrap.php`:

```
Kdyby\BootstrapFormRenderer\DI\RendererExtension::register($configurator);
```

### Step 2: Create Bootstrap-Styled Forms

[](#step-2-create-bootstrap-styled-forms)

There are three ways to create forms with Bootstrap styling:

#### Option A: Using Bootstrap2FormFactory (Recommended)

[](#option-a-using-bootstrap2formfactory-recommended)

The recommended approach is to use the factory that's automatically registered when you enable the extension:

```
use Kdyby\BootstrapFormRenderer\Bootstrap2FormFactory;

class RegistrationPresenter extends Nette\Application\UI\Presenter
{
    /** @var Bootstrap2FormFactory @inject */
    public $bootstrap2FormFactory;

    protected function createComponentContactForm()
    {
        // Factory creates Bootstrap2Form instances
        $form = $this->bootstrap2FormFactory->create();

        // Add your form fields as usual
        $form->addText('name', 'Name');
        $form->addText('email', 'E-mail')->setType('email');
        $form->addSubmit('register', 'Register');

        return $form;
    }
}
```

#### Option B: Using Bootstrap2Form Class

[](#option-b-using-bootstrap2form-class)

For simple cases or rapid prototyping, you can directly instantiate the `Bootstrap2Form` class:

```
use Kdyby\BootstrapFormRenderer\Bootstrap2Form;

class RegistrationPresenter extends Nette\Application\UI\Presenter
{
    protected function createComponentContactForm()
    {
        // Bootstrap2Form has BootstrapRenderer already configured
        $form = new Bootstrap2Form;

        // Add your form fields as usual
        $form->addText('name', 'Name');
        $form->addText('email', 'E-mail')->setType('email');
        $form->addSubmit('register', 'Register');

        return $form;
    }
}
```

#### Option C: Manual Renderer Setup

[](#option-c-manual-renderer-setup)

If you need maximum control or are working with existing code, you can apply the `BootstrapRenderer` directly:

```
use Kdyby\BootstrapFormRenderer\BootstrapRenderer;

// In your presenter or form factory method
protected function createComponentContactForm()
{
    $form = new Nette\Application\UI\Form;

    // Apply Bootstrap styling
    $form->setRenderer(new BootstrapRenderer);

    // Add your form fields as usual
    $form->addText('name', 'Name');
    $form->addText('email', 'E-mail')->setType('email');
    $form->addSubmit('send', 'Send');

    return $form;
}
```

### Step 3: Render Your Form in Templates

[](#step-3-render-your-form-in-templates)

Now you can use the special macros in your Latte templates to render the form. See the examples below for various rendering options.

Form Rendering Examples
-----------------------

[](#form-rendering-examples)

### Complete Form Rendering

[](#complete-form-rendering)

The simplest way to render a complete form with all Bootstrap styling:

```
{control contactForm}
```

### Partial Form Rendering

[](#partial-form-rendering)

For more control over the form layout, you can render individual parts:

#### Opening and Closing Tags Only

[](#opening-and-closing-tags-only)

To render just the form's opening `` and closing `` tags (without any form body), use the self-closing syntax:

```
{form contactForm /}
```

This is equivalent to:

```
{form contactForm}{/form}
```

Both render only the begin and end tags, following standard Latte 2.2 semantics. Use this when you want to manually render form content or integrate with other components.

#### Opening Tag with Custom Content

[](#opening-tag-with-custom-content)

```
{form contactForm}
    {* Your custom content here *}
{/form}
```

#### Form Errors

[](#form-errors)

Renders validation errors that aren't associated with specific fields (like form-level errors):

```
{form errors}
```

#### Form Body

[](#form-body)

Renders all form controls and groups that haven't been rendered yet:

```
{form body}
```

#### Controls Only

[](#controls-only)

Renders all input controls (excluding buttons):

```
{form controls}
```

#### Buttons Only

[](#buttons-only)

Renders all submit and button controls:

```
{form buttons}
```

#### Complete Custom Layout Example

[](#complete-custom-layout-example)

```
{form contactForm}
    {form errors}

            {pair name}
            {pair email}

            {pair message}

    {form buttons}
{/form}
```

### Rendering Individual Form Components

[](#rendering-individual-form-components)

#### Single Control

[](#single-control)

Renders a complete control with its label, input field, and validation messages:

```
{pair name}
```

Or using the verbose syntax:

```
{$form->render($form['name'])}
```

#### Container

[](#container)

Renders all controls within a container:

```
{container personalInfo}
```

#### Group

[](#group)

Renders a form group with its fieldset, legend, and all controls:

```
{group "Personal Information"}
```

Validation Errors Rendering
---------------------------

[](#validation-errors-rendering)

The renderer provides control over how validation errors are displayed through the `$errorsAtInputs` property:

### Default Behavior (errorsAtInputs = TRUE)

[](#default-behavior-errorsatinputs--true)

By default, the renderer distinguishes between form-level and control-level errors:

- **Form-level errors** (added with `$form->addError()`) appear in Bootstrap alert boxes at the top of the form
- **Control errors** (added with `$control->addError()`) appear inline next to their inputs with the `help-inline` class

```
$form->setRenderer(new BootstrapRenderer());
// errorsAtInputs = TRUE by default
```

This prevents duplicate error messages and provides better UX by showing each error in the most appropriate location.

### Show All Errors in Alerts (errorsAtInputs = FALSE)

[](#show-all-errors-in-alerts-errorsatinputs--false)

If you prefer to display all errors (both form-level and control errors) in alert boxes without inline errors:

```
$renderer = new BootstrapRenderer();
$renderer->errorsAtInputs = FALSE;
$form->setRenderer($renderer);
```

With this setting:

- All errors appear in Bootstrap alert boxes at the top
- No inline error messages are displayed next to inputs
- The control groups still receive the `error` CSS class for styling

Translation Behavior
--------------------

[](#translation-behavior)

BootstrapFormRenderer works seamlessly with Nette 2.2's built-in translation system. When you set a translator on your form using `$form->setTranslator($translator)`, almost everything is automatically translated—you don't need to manually translate individual elements.

### What Gets Translated Automatically

[](#what-gets-translated-automatically)

**Nette 2.2 automatically translates:**

- Control labels and captions
- Placeholders on text inputs and textareas
- Validation rule messages (both default and custom)
- Select options, radio button labels, and checkbox labels

**BootstrapFormRenderer translates:**

- Form group labels and descriptions
- Control descriptions (the `description` option)

### Important Guidelines

[](#important-guidelines)

1. **Manual errors** - If you add errors manually using `$form->addError()` or `$control->addError()` with plain strings, translate them yourself before calling `addError()`. Rule-generated errors are translated automatically.
2. **Pre-rendered HTML** - Use `Nette\Utils\Html` for content that shouldn't be translated:

    ```
    $htmlError = Html::el('strong')->setText('Already exists');
    $form['username']->addError($htmlError); // Not translated
    ```

Latte Variable Conventions
--------------------------

[](#latte-variable-conventions)

BootstrapFormRenderer aligns with Latte 2.2 standard runtime variable conventions:

- **`$_control`** - The current component/presenter context (required for form lookup)
- **`$_form`** - The current form inside `{form}...{/form}` blocks

These variables are automatically provided by Nette 2.2 presenter templates.

### Template Requirements

[](#template-requirements)

When rendering forms in your templates:

- Ensure templates are rendered within a Nette presenter context
- The `$_control` variable must be available for the `{form name}` macro to resolve forms
- Inside `{form}...{/form}` blocks, `$_form` provides access to the current form

This is automatically handled in standard Nette 2.2 presenter templates and requires no additional configuration.

License
-------

[](#license)

You may use BootstrapFormRenderer library under the terms of either the New BSD License or the GNU General Public License (GPL) version 2 or 3.

Read [LICENSE](license.md) for more information.

*Forked from the original [Kdyby/BootstrapFormRenderer](https://github.com/kdyby/BootstrapFormRenderer) by Filip Procházka.*

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance66

Regular maintenance activity

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 52.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~306 days

Recently: every ~2 days

Total

17

Last Release

101d ago

Major Versions

v0.9.4 → v1.0.02012-10-10

v1.1.0 → v2.0.02013-01-20

PHP version history (2 changes)v0.9.0PHP &gt;=5.3.2

v2.1.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2fcdfcec05e2eba0599c4fa0763d88b0e8a7db87b0512948c00a016f066c3ff?d=identicon)[jozefizso](/maintainers/jozefizso)

---

Top Contributors

[![jozefizso](https://avatars.githubusercontent.com/u/287778?v=4)](https://github.com/jozefizso "jozefizso (145 commits)")[![fprochazka](https://avatars.githubusercontent.com/u/158625?v=4)](https://github.com/fprochazka "fprochazka (126 commits)")[![matej21](https://avatars.githubusercontent.com/u/1276059?v=4)](https://github.com/matej21 "matej21 (2 commits)")[![mishak87](https://avatars.githubusercontent.com/u/276500?v=4)](https://github.com/mishak87 "mishak87 (2 commits)")[![enumag](https://avatars.githubusercontent.com/u/539462?v=4)](https://github.com/enumag "enumag (1 commits)")[![brabijan](https://avatars.githubusercontent.com/u/2448709?v=4)](https://github.com/brabijan "brabijan (1 commits)")[![stekycz](https://avatars.githubusercontent.com/u/865447?v=4)](https://github.com/stekycz "stekycz (1 commits)")

---

Tags

nettebootstrapFormskdyby

### Embed Badge

![Health badge](/badges/jozefizso-bootstrap-form-renderer/health.svg)

```
[![Health](https://phpackages.com/badges/jozefizso-bootstrap-form-renderer/health.svg)](https://phpackages.com/packages/jozefizso-bootstrap-form-renderer)
```

###  Alternatives

[contributte/forms-bootstrap

Nette extension for Bootstrap forms

211.1M4](/packages/contributte-forms-bootstrap)[nepada/form-renderer

Latte template based form renderer for Nette forms with full support for Bootstrap 3, 4 &amp; 5.

11251.0k](/packages/nepada-form-renderer)[tomaj/nette-bootstrap-form

Nette bootstrap form renderer

28440.4k6](/packages/tomaj-nette-bootstrap-form)[nextras/forms-rendering

Rendering helpers for Nette Framework Forms.

1698.4k2](/packages/nextras-forms-rendering)[kdyby/forms-replicator

Nette forms container replicator aka addDynamic

32997.7k6](/packages/kdyby-forms-replicator)[nasext/dependent-select-box

Dependent Select Box for Nette Framework.

21262.8k2](/packages/nasext-dependent-select-box)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
