Recent Posts
Archive
- [ 3 posts ] January 2010
- [ 2 posts ] September 2009
- [ 3 posts ] June 2009
- [ 3 posts ] May 2009
- [ 3 posts ] April 2009
- [ 6 posts ] March 2009
- [ 1 post ] February 2009
- [ 1 post ] January 2009
- [ 8 posts ] November 2008
- [ 7 posts ] October 2008
CakePHP fieldsets to keep your forms organized
Friday, 20 March 2009
Tagged: Website, General
This one is pretty simple, but useful for keeping things organised and easy to understand for your users when going through longer form sets.
The fieldset element isn't used as much as it should be. Its great for grouping content, and allowing a mental breakup for the user to make forms easier to comprehend. Guess what, CakePHP makes it super easy to implement!
I see a lot of new bakers using $form->input('my_field'), which is not a problem, but you can really reduce your development time if you push all the input fancyness to CSS, and use the bulk input output (yes, it outputs inputs) mechanism on the FormHelper.
One of the configurable options is 'legend', which will label a fieldset for the inputs you are displaying, like so:
<php echo $form->inputs(array( 'legend' => 'Personal information', 'name', 'nickname', 'age', 'email')); echo $form->inputs(array( 'legend' => 'Employment information', 'company', 'started_work', 'description')); ?>
Give this a go, and get on to some good CSS templates / designs for getting your fieldsets all organised and pretty.
3 Comments
Jean-Philippe Sirois
Monday, 29 June 2009
Thanks for the advice, putting all the inputs in the same array is also a good way to avoid having tons of echo and repeat useless code like "echo $form->input". Just a little thing I would like to warn you about. The PHP opening tag of your exemple didn't have the "?".
Thanks again for the great tips

Dan
Wednesday, 15 April 2009
Thanks!
You can also add options after each field declaration ie... " => array('maxLength' => '3')"