tags:

views:

41

answers:

2

Hi all

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?

+3  A: 

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=""?)

Travis Leleu
Thank you for the quick help, Travis Leleu
It should be noted that disabling the `div` option also breaks the automatic error-messages and labels, meaning you'll have to invoke `FormHelper::label` and `FormHelper::error` yourself if you want to incorporate those elements.
Daniel Wright
+1  A: 

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

Harsha M V