1
votes

I am using cakePHP. I used the cakePHP built-in Form Helper to generate an input text box:

echo $form->input('quote', array('label'=>'Post Number', 'class'=>''));

But when I looked at the HTML source code, I found out these:

<div class="input text">
<label for="ReplyQuote">Post Number</label>
<input name="data[Reply][quote]" type="text" class="" maxlength="12" value="1" id="ReplyQuote" />
</div>  

It's really more than enough. I mean the code generated by the Cake built-in Form Helper.
Those DIV tags with class named in a strange naming convention way are not helpful,
because there is space in between the Class name like:

 <div class="input text">

Does CakePHP have any options for users to omit those DIV Tags?

2
You're aware you can assign multiple classes to a single HTML element, right? This can be very handy for, say, assigning standard styles to all types of input fields, but also having specific style rules for text inputs.Daniel Wright

2 Answers

5
votes

Yes.

Check out the options array that you can pass to the FormHelper::input() method. Book reference is at http://book.cakephp.org/view/189/Automagic-Form-Elements

In short, the form helper is adding two distinct classes to the div -- input, and text. If you don't want a div, just do:

echo $form->input( 'quote', array( 'label' => 'Post Number', 'div' => false ) );

Setting the options['class'] value only affects the class selector assigned to the actual input itself (see in your HTML code how the input tag has class=""?)

1
votes

you can also use $form->text() for input box.