Create a bootstrap form (horizontal form by default).
<?php echo
$this->BsForm->create('Post', array('action' => 'add'));
?>
<form action="/bbcorg/posts/add" role="form" class="form-horizontal" id="PostAddForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST"/>
</div>
[mixed] model
-The model name for which the form is being defined. (default = null)[array] options
- An array of html attributes and options. (default = array())Create a bootstrap input.
<?php echo
$this->BsForm->input('User.name', array('label' => 'Full Name', 'state' => 'success', 'help' => 'Type your full name here'));
?>
<div class="form-group has-success">
<label for="UserName" class="control-label col-md-3">Full Name</label>
<div class="col-md-9">
<input name="data[User][name]" class="form-control" type="text" id="UserName"/>
<span class="help-block">Type your full name here</span>
</div>
</div>
[string] fieldName
- This should be "Modelname.fieldname"[array] options
- Each type of input takes different options. (default = array())
There are options by default and new options added :
Create a bootstrap input group.
<?php echo
$this->BsForm->inputGroup('User.email', array('content' => '@', 'class' => 'addon-mail'), array('label' => 'E-mail'));
?>
<div class="form-group">
<label for="UserEmail" class="control-label col-md-3">E-mail</label>
<div class="col-md-9">
<div class="input-group">
<span class="addon-mail input-group-addon">@</span>
<input name="data[User][email]" class="form-control" type="email" id="UserEmail"/>
</div>
</div>
</div>
[string] fieldName
- This should be "Modelname.fieldname"[array] addonOptions
- Options for the addon. (default = array())
[array] options
- Some options of the BsFormHelper::input() . (default = array())Create a bootstrap select field. It can be used to generate multiples checkbox too.
<?php echo
$this->BsForm->checkbox('User.notifications', array('label' => 'Do you want notifications ?', 'checked' => 'checked'));
?>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<div class="checkbox">
<label for="UserNotifications">
<input type="hidden" name="data[User][notifications]" id="UserNotifications_" value="0"/>
<input type="checkbox" name="data[User][notifications]" checked="checked" value="1" id="UserNotifications"/> Do you want notifications ?
</label>
</div>
</div>
</div>
[string] fieldName
- This should be "Modelname.fieldname"[array] options
- Differents options for the input. (default = array())
There are options by default and new options added :
Create a bootstrap checkbox field. Only for a single checkbox. For multiples checkbox, we recommend to use BsFormHelper::select().
<?php
$animals = array(
'dog' => 'Dog',
'cat' => 'Cat',
'rabbit' => 'Rabbit'
);
echo $this->BsForm->select('User.animal', $animals, array('label' => "What's your favorite animal ?", 'help' => 'Only one can be chosen'));
?>
<div class="form-group">
<label class="control-label col-md-3">What's your favorite animal ?</label>
<div class="col-md-9">
<select name="data[User][animal]" class="form-control" id="UserAnimal">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="rabbit">Rabbit</option>
</select>
<span class="help-block">Only one can be chosen</span>
</div>
</div>
<?php
$animals = array(
'dog' => 'Dog',
'cat' => 'Cat',
'rabbit' => 'Rabbit'
);
echo $this->BsForm->select('User.animal', $animals, array('label' => "What's your favorite animal ?", 'multiple' => 'checkbox'))
?>
<div class="form-group">
<label class="control-label col-md-3">What's your favorite animal ?</label>
<div class="col-md-9">
<input type="hidden" name="data[User][animal]" value="" id="UserAnimal"/>
<div class="checkbox">
<label for="UserAnimalDog">
<input type="checkbox" name="data[User][animal][]" value="dog" id="UserAnimalDog" />
Dog
</label>
</div>
<div class="checkbox">
<label for="UserAnimalCat">
<input type="checkbox" name="data[User][animal][]" value="cat" id="UserAnimalCat" />
Cat
</label>
</div>
<div class="checkbox">
<label for="UserAnimalRabbit">
<input type="checkbox" name="data[User][animal][]" value="rabbit" id="UserAnimalRabbit" />
Rabbit
</label>
</div>
</div>
</div>
[string] fieldName
- This should be "Modelname.fieldname"[array] options
- Options in the field.[array] attributes
- Differents attributes for the input. (default = array())
There are options added :
Create a select with Chosen plugin attached.
<?php
$tab2 =
array(
'group 1' => array(
'1' => 'Choice 1',
'2' => 'Choice 2'
),
'group 2' => array(
'3' => 'Choice 3',
'4' => 'Choice 4'
)
);
echo
$this->BsForm->chosen(
'Tag.Tag',
$tab2,
array(
'label' => 'Chosen 1',
'data-placeholder' => 'Cliquez pour selectionner les valeurs recherchées',
'default' => array('2', '4'),
'disabled' => array('1'),
'multiple' => true,
)
);
?>
<div class="form-group">
<label for="TagTag" class="control-label col-md-3">Chosen 1</label>
<div class="col-md-9">
<input type="hidden" name="data[Tag][Tag]" value="" id="TagTag_"/>
<select name="data[Tag][Tag][]" class="checkbox chosen-Tag_Tag" data-placeholder="Cliquez pour selectionner les valeurs recherchées" multiple="multiple" id="TagTag">
<optgroup label="group 1">
<option value="1" disabled="disabled">Choice 1</option>
<option value="2" selected="selected">Choice 2</option>
</optgroup>
<optgroup label="group 2">
<option value="3">Choice 3</option>
<option value="4" selected="selected">Choice 4</option>
</optgroup>
</select>
</div>
</div>
[string] fieldName
- This should be "Modelname.fieldname"[array] Select content
- Item of the select (default = array())
[array] Select option
- Options of the select HTML tag
[array] Chosen option
-
Some options for chosen JS
Create a bootstrap radio field.
<?php
$statut = array(
0 => 'No',
1 => 'Yes'
);
echo $this->BsForm->radio('User.married', $state, array('label' => 'Are you married ?'));
?>
<div class="form-group">
<label class="control-label col-md-3">Are you married ?</label>
<div class="col-md-9">
<div class="radio">
<label>
<input type="hidden" name="data[User][married]" id="UserMarried_" value=""/>
<input type="radio" name="data[User][married]" id="UserMarried0" value="0" />
<label for="UserMarried0">No</label>
</label></div><div class="radio">
<label>
<input type="radio" name="data[User][married]" id="UserMarried1" value="1" />
<label for="UserMarried1">Yes</label>
</label>
</div>
</div>
</div>
[string] fieldName
- This should be "Modelname.fieldname"[array] options
- Options in the field.[array] attributes
- Differents attributes for the input. (default = array())
There are options by default and new options added :
Create a bootstrap datepicker. Needs to have the variable dpLoad of BsHelper to true and before reporting functions BsHelper::css() and BsHelper::js().
<?php
// There need these functions in the layout before
// $this->Bs->dpLoad = true;
// echo $this->Bs->css();
// echo $this->Bs->js();
echo $this->BsForm->datepicker('User.anniversary', array('orientation' => 'top right'), array('label' => 'Your date of birth'));
?>
<div class="dp-container">
<div class="form-group">
<label for="UserAnniversary" class="control-label col-md-3">Your date of birth</label>
<div class="col-md-9">
<input name="data[User][anniversary]" class="form-control" type="text" id="UserAnniversary"/>
</div>
</div>
<input type="hidden" name="data[User][anniversary]" id="alt_dp" class="form-control"/>
</div>
<script>
$('.dp-container input').datepicker({orientation : "top right",format : "dd/mm/yyyy",language : "fr",}).on('changeDate', function() {
var date = $('#UserAnniversary').datepicker('getDate');
date.setHours(0, -date.getTimezoneOffset(), 0, 0);
date = date.toISOString().slice(0,19).replace('T', " ");
$('#alt_dp').attr('value', date);
});
</script>
[string] fieldName
- This should be "Modelname.fieldname"[array] optionsDP
- Options of the datepicker (default = array()). The full documentation is available here : Full Documentation[array] options
- Differents options for the input, same as BsForm::input(). (default = array())Create a bootstrap button to submit the form.
<?php echo
$this->BsForm->submit('Finish');
?>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<input class="btn btn-success" type="submit" value="Finish"/>
</div>
</div>
[string] caption
- The label appearing on the button.[array] options
- Different options of the input. (default = array())
There are options by default :
Closes an HTML form, cleans up values set by BsForm::create(), and writes hidden input fields where appropriate.
<?php echo
$this->BsForm->end();
?>
</form>
[array] options
- A string will use $options as the value of button. (default = null)[array] secureAttributes
- Will be passed as html attributes into the hidden input elements generated for the Security Component. (default = array())Return the width of the left column of the form. (default : 3)
<?php echo
$this->BsForm->getLeft();
?>
Return the width of the right column of the form. (default : 9)
<?php echo
$this->BsForm->getRight();
?>
Edit the width of the left column of the form.
<?php echo
$this->BsForm->setLeft(5);
?>
[int] val
- Width of the column. (bootstrap size)Edit the width of the right column of the form.
<?php echo
$this->BsForm->setRight(7);
?>
[int] val
- Width of the column. (bootstrap size)Edit the type of the form.
<?php echo
$this->BsForm->setFormType('inline');
?>
[string] val
- Type of the form. (inline, horizontal)