What is the difference with hand-coding the <form>
HTML v.s. using library to generate the same? Why invent a whole new way of generating form and ask deve开发者_运维知识库lopers to learn new syntax when all of it can be done in plain HTML?
- Once you learn the form API it's faster to use the API then write out the html.
- You can attach validation when creating the form.
- They were bored
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://>
<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.
精彩评论