PHP code example of netzmacht / contao-form-helper

1. Go to this page and download the library: Download netzmacht/contao-form-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

netzmacht / contao-form-helper example snippets




// 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();



// 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);
	}
}