contao/core — Issue #3768: Generic FormBuilder class
Author: Toflar
Created: 2012-01-05 17:26:44+00:00
State: open

Hi Leo

One thing I already love about Contao 2.11 is that it has not only improved for users but for developers too! I guess it's way easier to develop in 2.11 than in 2.10 because we have received a bunch of new hooks and a few very cool and essential features we can work with.

One thing that still annoys me is when I have to work with forms in the front end. Don't tell me that you like working with the front end form fields and sticking it all together in a form. That's just so cumbersome - I can't even believe that I only write this ticket today. I should have done this when version 2.6 was the latest :D

I would love to see something like a FormBuilder class in the next version of Contao. It would make life 200 times easier for every developer.

Christoph has started something that tries exactly to deal with this problem but I just feel like this __must__ be part of the core.
Have a look at the project: https://github.com/psi-4ward/Formular

Isn't this wonderful? :D

Example (slightly adjusted to my personal taste)

```
$dca = array
(
'email' => array
(
'label'	=> 'E-Mail',
'inputType' => 'text',
'eval'	=> array('mandatory'=>true,'rgxp'=>'email')
),
'message' => array
(
'label'	=> 'Message',
'inputType' => 'textarea',
'eval'	=> array('rte'=>'tinyMCE')
),
'submit' => array
(
'label'	=> 'save',
'inputType' => 'submit'
)
);

$objForm = new FormBuilder('formId');
$objForm->setFields($dca);
$objForm->setConfig('tableless', true);
$objForm->setTemplate('myformtemplate');

if ($objForm->isSubmitted() && $objForm->validate())
{
var_dump($objForm->getData());
}
echo $objForm->parse();
```

Don't you think it would be way easier for developers to use the DCA knowledge they have from the back end also in the front end and just let the FormBuilder do the magic? We could also avoid tons of errors that way.

I'm sick of rewriting code like this

```
foreach ($arrWidgets as $name => $objWidget)
{
$objWidget->validate();

if ($objWidget->hasErrors())
{
$doNotSubmit = true;
}
}
```
over and over again.

Can I get this as a Contao Conference 2012 present? I'll bring some Swiss chocolate with me as compensation :D