Apr
10
2009

CakePHP: No markup with formhelper input

Posted 3 comments | Webdevelopment, CakePHP

Just a short blog post about CakePHP, I see loads of people around me who don't want any markup like DIVS or LABELS around their form input elements. There are plenty reasons you don't want those markup, for example when you need your form in a table.

I see programmers using $form->select(); or $form->radio(); to avoid all the markup, but there's a simple trick to hide all the additional elements and still benefit from all the magic features of $form->input();

Just add two parameters in the input options:

input('title', array(
    'div' => false,
    'label' => false)
);

 

Nate Abele

Nate Abele

Posted

Or you can just use $form->text("title"), since that's what that's for.
Lennaert

Lennaert

Posted

Wiiiiiiiii Nate commented =)

Anyway, Nate, Of course I can use $form->text, but then I'm missing the magic features of $form->input.

For example a validate error message. I need to write extra lines of codes to get the error message, but when I use $form->input it's automatically showing under my element..

Also I don't want to think if it's a select, a text or a radio input, I want the magic of $form->input to think about that..

Am I right? =)
Chris

Chris

Posted

Thanks for the post Lennaert, saved me some time!

I would love a comment!