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)
);
6 Responses to CakePHP: No markup with formhelper input
Or you can just use $form->text("title"), since that's what that's for.
replyWiiiiiiiii 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? =)
replyThanks for the post Lennaert, saved me some time!
replyyou don’t have to write ‘div’=>false, ‘label’=>false everytime
replyjust modify your $form->create a bit
$form->create(‘User’, array(‘inputDefaults’=>array(‘div’=>false, ‘label’=>false)));
that’s all
Tables aren’t meant for forms. Tables are meant to format data.
The only reason you’d want to use tables, is for lay-out purposes. And that’s like building your house using paper in stead of bricks because you want it to be white.
Please use tables for data formatting and CSS for interface design.
Oh and btw, I think you’re interested to hear I started some CakePHP projects recently
replyis there some way to write a cotusm form validation rule ?like if i want that every valid-email shouldn’t belong to google.com (e.g shouldn’t be a valid email address).This is some sort of enhancements for valid-email rule.any comments ???
replyAdd a comment