« Back to blog

Blog: CakePHP fieldsets to keep your forms organized

Graham Weldon

20 March, 2009

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.

Comments