Welcome to the Cookbook

loading...

7.3.3.7 $options[‘div’]

Use this option to set attributes of the input's containing div. Using a string value will set the div's class name. An array will set the div's attributes to those specified by the array's keys/values. Alternatively, you can set this key to false to disable the output of the div.

Setting the class name:

    echo $form->input('User.name', array('div' => 'class_name'));
  1. echo $form->input('User.name', array('div' => 'class_name'));

Output:

<div class="class_name">
	<label for="UserName">Name</label>
	<input name="data[User][name]" type="text" value="" id="UserName" />
</div>

Setting multiple attributes:

    echo $form->input('User.name', array('div' => array('id' => 'mainDiv', 'title' => 'Div Title', 'style' => 'display:block')));
  1. echo $form->input('User.name', array('div' => array('id' => 'mainDiv', 'title' => 'Div Title', 'style' => 'display:block')));

Output:

<div class="input text" id="mainDiv" title="Div Title" style="display:block">
	<label for="UserName">Name</label>
	<input name="data[User][name]" type="text" value="" id="UserName" />
</div>

Disabling div output:

    <?php echo $form->input('User.name', array('div' => false));?>
  1. <?php echo $form->input('User.name', array('div' => false));?>

Output:

    <label for="UserName">Name</label>
    <input name="data[User][name]" type="text" value="" id="UserName" />