Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Generic FormBuilder class #3768

Closed
Toflar opened this issue Jan 5, 2012 · 25 comments
Closed

Generic FormBuilder class #3768

Toflar opened this issue Jan 5, 2012 · 25 comments

Comments

@Toflar
Copy link
Member

Toflar commented Jan 5, 2012

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

@psi-4ward
Copy link
Contributor

+1, what else? ;)

@kikmedia
Copy link

kikmedia commented Jan 5, 2012

+1 (and, of course, swedish chocolate)

@dominikzogg
Copy link
Contributor

@Serhii-DV
Copy link
Contributor

+1

1 similar comment
@christian-kolb
Copy link

+1

@lindesbs
Copy link

lindesbs commented Jan 5, 2012

definitly ++

@leo-unglaub
Copy link

Hi guys,
i am having a strong fever today, so i am sorry if my english sucks today. First of all Toflar is right, forms suck as hell in the frontend. But that's not exactly contao's fault. Forms suck because there are not realy compat with the http protocol. An example:

  • Render the form
  • User inserts data
  • Send the data to the server
  • revalidate the data and in an error case render the form again and insert all right data
  • redo it until the data is right.

Every step of that is a new page reload. And every page relaod is a complete seperate http session. So while designing the web and http no one thought about this. Later on they realized that they should need forms to, so they implemented it but never realy fixed the way how forms work.

The way Toflar ans Psi developed there is a good workaround for "normal" forms in a website. But sadly 90% of the forms on a website are more special that a simple form in one page. You have dynamic formular elements and forms over multiple sites. So even with this solution in the core you have the exact same problem, just out of the box.

If we realy want to fix this and do it the right way we have to improve the way forms are handled in the web. I have the following idea:

We use the normal dca to define the formular elements, but we extend the dca a little bit and also put the field dependency's right in the dca. Also we define in with step of a form a field sould be displayed. If we have that we render the formular fields empty in the frontend and instead of doing it with a simple submit button we validate every field right when the user puts the data in it and store the values with ajax in a data store (database, session, csv, ... ).

So we never have to regenerate the forms with the user data in it or have token problems or somethink like that. In my opinion it's the only right way to handle form elements better. Sienece we are on github, there is already somethink like that. If you create a repo and disable the wiki or the issues in the admin panel, all of those checkboxes and forms are ajax triggert and saved.

Every company is trying to make the web more like a native app, so this would be the next logical step. Because desktop applications simply save data directly on input.

What do you think about this? I have to get some sleep now, because duning this post i throw up once.
Sorry for all the spelling errors.

@blairwinans
Copy link

+1... And LeoU, hope you feel better! Don't you think your idea could be implemented just as easily with an extension if we had a base FormBuilder class to extend? I like your thoughts, but we have to start somewhere!

@qrczak
Copy link

qrczak commented Jan 6, 2012

+1

@qzminski
Copy link
Member

qzminski commented Jan 6, 2012

@FlxPeters
Copy link

+1

I often use the Formular-Class. Don't know the Class by qzminski, but its even the same Idea. Like it.

@qzminski
Copy link
Member

Such class would be very useful as we're in framework, though I can't find a direct use of it in Contao as CMS. But still, it should be implemented.
+1

@Toflar
Copy link
Member Author

Toflar commented Mar 9, 2012

I have extended Kamil's HasteForm class and added a documentation. Pretty much what I am looking for in the core now ;)

@psi-4ward
Copy link
Contributor

Seems there are some implementations, perhapts we sould work a specification out?

@danielritter
Copy link

Da bin ich auch dafür! :-)

@rogerramjet
Copy link

Could it also be html5-ed by adding new form inputTypes (email,tel etc)

Ideally
'inputType' => 'email' or 'inputType' => 'tel'
would revert to text .... to become
'inputType' => 'text, if the outputFormat was 'xhtml'

@FlxPeters
Copy link

Schafft das noch den angepeilten Sprung in die Version 3?

@qzminski
Copy link
Member

qzminski commented Jun 2, 2012

Will we see this in version 3?

@psi-4ward
Copy link
Contributor

Es wäre mehr als eine Freude wenn wir so etwas in die 3 einbauen könnten.

@danielritter
Copy link

Sehr schade, wird das nicht in die 3.0.0 mitaufgenommen. :-(

@psi-4ward
Copy link
Contributor

Das ganze ist ein sehr komplexes Thema und zieht auch andere Widgets und viele DataContainer Anpassungen mit sich ... von demher ist das nicht mal eben umzusetzen

@danielritter
Copy link

Ich würde es begrüssen, dies in der nächsten Contao-Version 3.3 zu sehen. :-)

@aschempp
Copy link
Member

Just found this old issue. I think Haste\Form does solve this requirement?
https://github.com/codefog/contao-haste/blob/master/docs/Form/Form.md

@leofeyer leofeyer modified the milestones: 3.5.0, 3.x.x Nov 17, 2014
@leofeyer
Copy link
Member

I'll happily add something like this if we manage to agree on a solution (and someone prepares a pull request?).

@leofeyer
Copy link
Member

leofeyer commented Dec 4, 2014

As discussed on Mumble, we won't merge the Haste functionality. If you need the feature, simply use Haste :)

https://github.com/codefog/contao-haste/blob/master/docs/Form/Form.md

@leofeyer leofeyer closed this as completed Dec 4, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests