开发者

What is the purpose of HTML form generator?

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?


  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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜