views:

48

answers:

2

Hello,

What is the difference between using form helpers and plain html form? Why did the framework developers create form helpers? Just because they were idle? Why invent a whole new way of generating form and ask developers to learn new syntaxes when all of it you can do it in plain html?

Thanks in advance:)

+5  A: 
  1. Once you learn the form API it's faster to use the API then write out the html.
  2. You can attach validation when creating the form.
  3. They were bored
Galen
I think a big part of it is for validation.
Matt
yes.. the validation is easy with forms helper.
ariawan
+1  A: 

For the same reason they try to mimick MVC. Every other framework has a form helper, and it's perceived as 'advanced' to write an OOP wrapper to generate HTML.

However, it does consolidate data format validation. HTML5 has built-in support for generic types and client-side regex verification, but few browsers support it, and you have to assert it server-side anyway.

It's basically just that nobody has yet found a API that makes it actually simpler. I've been pondering to write a form() tool myself, something along the lines:

print form('
   <form method=POST action=>
   <input name=field type=url label=Homepage placeholder=http://&gt;
   <input name=user required regex=\w+>
');

Which would transform shorthand tags into valid html5 or x/html4 + jquery helpers. And by reusing the shorthand source could later also validate data. My suggestion being to just use standardized html5 syntax to have a single method to define forms and validation, and eschew a convoluted API.

mario