2017 © Pedro Peláez
 

contao-bundle contao-form-helper

Library for supporting customized Contao form rendering

image

netzmacht/contao-form-helper

Library for supporting customized Contao form rendering

  • Wednesday, November 2, 2016
  • by netzmacht
  • Repository
  • 1 Watchers
  • 2 Stars
  • 8,084 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 29 Versions
  • 1 % Grown

The README.md

Contao Form Helper - Extended form rendering

Build Status Version License Downloads Contao Community Alliance coding standard, (*1)

This library provides extended form widget rendering for Contao frontend form widgets. By default the rendering of Contao forms widgets are not very customizable because of inline html rendering. Adjust output can be quite difficult., (*2)

Contao Form Helper provides an event driven form rendering which is fully backward compatible. This means that it supports the html output usually provided by Contao. Also every widgets from extension will work without any customizing., (*3)

Contao Form Helper renders the form in two steps. First it creates objects representing the HTML elements before passing them to the templates. Using the event driven interface it is possible to simply change attributes, provide extra features and so on., (*4)

Installation

To install the extension simply install netzmacht/contao-form-helper using the Composer repository., (*5)

Changelog

Changes between 0.x version and 1.x * Change namespace of Netzmacht\FormHelper to Netzmacht\Contao\FormHelper * Using a view object which is created instead of return an array of elements * Simplify events (no select message event anymore) * Introduce an attributes object for * Drop supporting form messages handling, (*6)

How it works

By default this extension enables the extended form rendering for every form widget which is shipped with Contao. They are activated by customized form templates., (*7)

The helper creates a view object for each widget. The view contains: * Attributes which can be used for a wrapper <div> * The form label * Container including the element and by default the extra submit button * Error messages * Using a layout which is used to render, (*8)

<?php

// form_widget.html5

// shortcut
Netzmacht\Contao\FormHelper\Helper::generate($this);

// what actually happens
$helper = Netzmacht\Contao\FormHelper\Helper::getInstance();

/** @var Netzmacht\Contao\FromHelper\View */
$view   = $helper->createView($view);

echo $view->render();

Events

Events are dispatched by the (Contao Event dispatcher)[https://github.com/contao-community-alliance/event-dispatcher]. Each event names are stored in Netzmacht\Contao\FormHelper\Event\Events: * Events::CREATE_VIEW is triggered first to create the view instance. The element is not available at this moment * Events::CREATE_ELEMENT is fired when creating the html element of the given widget * Events::PRE_GENERATE_VIEW is fired after creating the element * Events::GENERATE_VIEW is fired for generating the, (*9)

Customizing widgets

There are two ways for manipulating the output. The proposed way is writing your custom events, (*10)

<?php
// config.php

$GLOBALS['TL_EVENTS'][Netzmacht\Contao\FormHelper\Event\Events::GENERATE_VIEW][] = function(Netzmacht\Contao\FormHelper\Event\ViewEvent $event) {
    // access Contao widget and form
    $form   = $event->getFormModel();
    $widget = $event->getWidget();

    // adjust element
    $container = $event->getContainer();
    $element   = $container->getElement();

    // adjust rows
    if($form->id == 9 && $widget->type == 'textarea') {
        $element->setAttribute('rows', 50);
    }
}

You can also adjust the rendering using the templates:, (*11)

```php <?php // form_widget.html5 $helper = Netzmacht\Contao\FormHelper\Helper::getInstance();, (*12)

/** @var Netzmacht\Contao\FromHelper\View */ $view = $helper->createView($view); $errors = $view->getErrors();, (*13)

// display all errors which belongs to an element $errors->setTemplateName('formhelper_error_all');, (*14)

// wrapping element can be a string with %s placeholder or an Netzmacht\Html\Node object $wrapper = ', (*15)

%s

';, (*16)

$container = $view->getContainer(); $container->add('wrapper', $wrapper, $container::POSITION_WRAPPER);, (*17)

echo $view->render();, (*18)

The Versions

02/11 2016

dev-contao4

dev-contao4

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

The Development Requires

form helper contao

16/02 2015

0.3.5

0.3.5.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

21/11 2014

0.3.4

0.3.4.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

10/10 2014

0.3.3

0.3.3.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

24/09 2014

0.3.2

0.3.2.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

29/07 2014

0.3.1

0.3.1.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

28/07 2014

0.3.0

0.3.0.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

21/07 2014

0.2.1

0.2.1.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

23/06 2014

0.2.0

0.2.0.0

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

16/06 2014

0.1.0-rc

0.1.0.0-RC

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

09/05 2014

0.1.0-beta3

0.1.0.0-beta3

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

07/03 2014

0.1.0-beta2

0.1.0.0-beta2

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao

06/03 2014

0.1.0-beta1

0.1.0.0-beta1

Library for supporting customized Contao form rendering

  Sources   Download

LGPL-3.0+

The Requires

 

form helper contao