Lennaert Ekelmans - LennieZ 4 months, 1 week, 4 days to my birthday!

Lennaert Ekelmans



Lennaert Ekelmans

I'm Lennaert Ekelmans, The Netherlands, 22 years old, serial entrepreneur, web developer, CakePHP'er, hobby-photographer and trance-addict.

Since April I've a blog, read here why.

CakePHP: No markup with formhelper input

2009-04-10 11:30:00

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 on 10/4/09
Or you can just use $form->text("title"), since that's what that's for.
Lennaert Lennaert on 11/4/09
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 3 weeks, 3 days ago
Thanks for the post Lennaert, saved me some time!

Write a comment

I won't publish your e-mail address, website is optional