Page 1 of 1
form helpers
Posted: Sun Feb 13, 2011 7:55 pm
by s.dot
What is your opinion on form helpers/generators?
They're not really any 'easier' than making a form in the view with HTML, and it seems it would complicate the process if a designer was only working on a template and needed to add a class or id to a form element.
I'm diving into ZF and I don't see any reason to use it. I'll want to learn how it works later on so I can do it if a job specifies it, but for now it seems pretty pointless.
Re: form helpers
Posted: Mon Feb 14, 2011 7:44 am
by alex.barylski
Like most solutions, both have their pros and cons.
Form API's are nice for consistency. As the underlying template(s) will dictate whether you have a <span> or <label> wrapping your caption/helper text. It also makes changing the form programmatically a little easier. You might plugin a captcha module that applies itself to all your forms without having to manually modify the FORM HTML, Drupal and WordPress have extensions like this.
On the other hand, you could build the template by hand and before display to the end user, load the markup in a DOM and add or remove elements as you would with the Form API - but it's not as easy, IMO.
Lastly, when you handcraft forms you obviously have much more control over the placement of elements. It can become very hackish using a forms API to build exactly as you wish. Helper icons beside fields, making <label> render in a distinct column (not simply preceede the field textbox). When a form is initially conceived by a designer that likes to go buck wild, this is often the case.
If you use form API, make sure you step in during the design process to minimize their 'creativeness' - in all honesty a form really only needs to be practical not pretty. Using a form API you can get POSTBACK persistence for free, as well as error warnings and other neat features which are often 'tacked' on after the fact.
Zend is probably the best thought out solution, when compared to others out there (HTML_QuickForm I used years ago liked it...hated it...never used it again).
Cheers,
Alex
Re: form helpers
Posted: Wed Feb 16, 2011 1:02 am
by Zyxist
Form helpers are an object-oriented approach to build HTML forms. If they focus only on the certain field tags, such as INPUT or SELECT, they are OK, because we can easily manage the form and field internal logic. However, when they become used to generate the entire field layout, with labels, DIV-s, displaying errors, such approach is getting more and more complex. The result is very hard to customize, and as alex.barylski said, it is very hard to put things in the right place unless we follow the path the component authors implemented.
For the field layout, plain templates are much better, mostly because they are natural. You write a normal HTML code, you do not have to implement complex classes just to replace DIV with SPAN or something like that. However, in order to be usable too, we need a good template engine here, and unfortunately most of the existing ones (including the PHP-based ones) fail here and offer no help.
Re: form helpers
Posted: Wed Feb 16, 2011 4:05 am
by Weirdan
Depends on what you mean by form helpers. If those are just simple view helpers (basically, just functions building a piece of html and returning it) - I'm all for it, as they could make your life easier
without sacrificing much of the control:
Code: Select all
<form ... >
<?=$this->dateRangeSelect($from = "2 months ago", $to = "now + 2 months")?>
<!-- other fields here -->
<input type="submit"/>
</form>
Form builders, like Zend_Form - oh, don't get me started on form builders...
Re: form helpers
Posted: Wed Feb 16, 2011 7:48 am
by alex.barylski
Depends on what you mean by form helpers.
i was wondering this myself but it sounds like he's after a form API not view helpers like are common in some frameworks.
Cheers,
Alex