Textbox in CakePHP

Following are the methods through which we can create Textbox in CakePHP.
Example 1:

echo $this->Form->input(‘usrUsername’);

Above code will render following output in view:

<div class=”input text”>
<label for=”UserUsrUsername”>Usr Username</label><input name=”data[User][usrUsername]” type=”text” id=”UserUsrUsername”/>
</div>


Note : User is model name for users table. Div is generate automatically by input method, in last example we remove it.
Example 2:

echo $this->Form->input(‘usrPhone’, array(‘type’ => ‘text’,’name’=> ‘usrName’,’label’=>’Phone’,’maxlength’=>’10’));

Above code will render following output in view:

<div class=”input text”>
<label for=”UserUsrPhone”>Phone</label><input name=”usrName” maxlength=”10″ type=”text” id=”UserUsrPhone”/>
</div>

Example 3:

echo $this->Form->input(‘usrUsername’, array(‘type’ => ‘text’,’name’=> ‘usrName’,’label’=>’Name’,’class’=>’myStyle’,’div’=>false,’value’=>’Hello’,’style’=>’color:red’));

Above code will render following output in view:

<label for=”UserUsrUsername”>Name</label><input name=”usrName” class=”myStyle” value=”Hello” style=”color:red” type=”text” id=”UserUsrUsername”/>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.