80 self::TYPE_VERTICAL =>
'',
81 self::TYPE_INLINE =>
'-inline',
82 self::TYPE_HORIZONTAL =>
'-horizontal',
146 $this->errorMessageCssClass =
'help-block error';
148 $this->clientOptions[
'errorCssClass'] =
'has-error';
149 $this->clientOptions[
'successCssClass'] =
'has-success';
150 $this->clientOptions[
'inputContainer'] =
'div.form-group';
167 public function errorSummary($models, $header = null, $footer = null, $htmlOptions = array()) {
169 if (!isset($htmlOptions[
'class'])) {
170 $htmlOptions[
'class'] =
'alert alert-block alert-danger';
194 $widgetOptions = $options[
'widgetOptions'];
196 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
198 $fieldData = array(array($this,
'urlField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
221 $widgetOptions = $options[
'widgetOptions'];
223 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
225 $fieldData = array(array($this,
'emailField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
248 $widgetOptions = $options[
'widgetOptions'];
250 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
252 $fieldData = array(array($this,
'numberField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
275 $widgetOptions = $options[
'widgetOptions'];
277 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
279 $fieldData = array(array($this,
'rangeField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
302 $widgetOptions = $options[
'widgetOptions'];
304 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
306 $fieldData = array(array($this,
'dateField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
329 $widgetOptions = $options[
'widgetOptions'];
331 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
333 $fieldData = array(array($this,
'timeField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
356 $widgetOptions = $options[
'widgetOptions'];
358 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
360 $fieldData = array(array($this,
'telField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
383 $widgetOptions = $options[
'widgetOptions'];
385 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
387 $fieldData = array(array($this,
'textField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
409 $widgetOptions = $options[
'widgetOptions'];
411 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
413 $fieldData = array(array($this,
'searchField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
436 $this->
addCssClass($options[
'widgetOptions'][
'htmlOptions'],
'form-control');
438 $fieldData = array(array($this,
'passwordField'), array($model, $attribute, $options[
'widgetOptions'][
'htmlOptions']));
461 $this->
addCssClass($options[
'widgetOptions'][
'htmlOptions'],
'form-control');
463 $fieldData = array(array($this,
'textArea'), array($model, $attribute, $options[
'widgetOptions'][
'htmlOptions']));
486 $widgetOptions = $options[
'widgetOptions'];
488 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
490 $fieldData = array(array($this,
'fileField'), array($model, $attribute, $widgetOptions[
'htmlOptions']));
513 $widgetOptions = $options[
'widgetOptions'][
'htmlOptions'];
516 if( $this->type == self::TYPE_INLINE || (isset($options[
'inline']) && $options[
'inline']) )
519 $field = $this->radioButton($model, $attribute, $widgetOptions);
520 if ((!array_key_exists(
'uncheckValue', $widgetOptions) || isset($widgetOptions[
'uncheckValue']))
521 && preg_match(
'/<input.*?type="hidden".*?>/', $field, $matches)
523 $hiddenField = $matches[0];
524 $field = str_replace($hiddenField,
'', $field);
527 $realAttribute = $attribute;
528 CHtml::resolveName($model, $realAttribute);
531 if (isset($hiddenField)) echo $hiddenField;
532 echo CHtml::tag(
'label', $options[
'labelOptions'],
false,
false);
534 if (isset($options[
'label'])) {
535 if ($options[
'label'])
536 echo $options[
'label'];
538 echo $model->getAttributeLabel($realAttribute);
539 echo CHtml::closeTag(
'label');
540 $fieldData = ob_get_clean();
542 $widgetOptions[
'label'] =
'';
566 if ($this->type == self::TYPE_INLINE)
569 $field = $this->checkbox($model, $attribute, $options[
'widgetOptions'][
'htmlOptions']);
570 if ((!array_key_exists(
'uncheckValue', $options[
'widgetOptions']) || isset($options[
'widgetOptions'][
'uncheckValue']))
571 && preg_match(
'/<input.*?type="hidden".*?>/', $field, $matches)
573 $hiddenField = $matches[0];
574 $field = str_replace($hiddenField,
'', $field);
577 $realAttribute = $attribute;
578 CHtml::resolveName($model, $realAttribute);
581 echo
'<div class="checkbox">';
582 if (isset($hiddenField)) echo $hiddenField;
583 echo CHtml::tag(
'label', $options[
'labelOptions'],
false,
false);
585 if (isset($options[
'label'])) {
586 if ($options[
'label'])
587 echo $options[
'label'];
589 echo
' '.$model->getAttributeLabel($realAttribute);
590 echo CHtml::closeTag(
'label');
592 $fieldData = ob_get_clean();
594 $options[
'label'] =
'';
618 $widgetOptions = $options[
'widgetOptions'];
623 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
625 $fieldData = array(array($this,
'dropDownList'), array($model, $attribute, $widgetOptions[
'data'], $widgetOptions[
'htmlOptions']));
649 $widgetOptions = $options[
'widgetOptions'];
654 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
656 $fieldData = array(array($this,
'listBox'), array($model, $attribute, $widgetOptions[
'data'], $widgetOptions[
'htmlOptions']));
681 $widgetOptions = $options[
'widgetOptions'][
'htmlOptions'];
686 if (!isset($widgetOptions[
'labelOptions'][
'class']))
687 $widgetOptions[
'labelOptions'][
'class'] =
'checkbox';
689 if(isset($options[
'inline']) && $options[
'inline'])
690 $widgetOptions[
'labelOptions'][
'class'] =
'checkbox-inline';
692 if (!isset($widgetOptions[
'template']))
693 $widgetOptions[
'template'] =
'{beginLabel}{input}{labelTitle}{endLabel}';
695 if (!isset($widgetOptions[
'separator']))
696 $widgetOptions[
'separator'] =
"\n";
698 $data = $options[
'widgetOptions'][
'data'];
700 $fieldData = array(array($this,
'checkboxList'), array($model, $attribute,
$data, $widgetOptions));
725 $widgetOptions = $options[
'widgetOptions'][
'htmlOptions'];
730 if (!isset($widgetOptions[
'labelOptions'][
'class']))
731 $widgetOptions[
'labelOptions'][
'class'] =
'radio';
733 if(isset($options[
'inline']) && $options[
'inline'])
734 $widgetOptions[
'labelOptions'][
'class'] =
'checkbox-inline';
736 if (!isset($widgetOptions[
'template']))
737 $widgetOptions[
'template'] =
'{beginLabel}{input}{labelTitle}{endLabel}';
739 if (!isset($widgetOptions[
'separator']))
740 $widgetOptions[
'separator'] =
"\n";
742 $data = $options[
'widgetOptions'][
'data'];
744 $fieldData = array(array($this,
'radioButtonList'), array($model, $attribute,
$data, $widgetOptions));
764 public function switchGroup($model, $attribute, $options = array()) {
766 return $this->
widgetGroupInternal(
'booster.widgets.TbSwitch', $model, $attribute, $options);
786 return $this->
widgetGroupInternal(
'booster.widgets.TbDatePicker', $model, $attribute, $options);
806 return $this->
widgetGroupInternal(
'booster.widgets.TbDateRangePicker', $model, $attribute, $options);
826 return $this->
widgetGroupInternal(
'booster.widgets.TbTimePicker', $model, $attribute, $options);
846 return $this->
widgetGroupInternal(
'booster.widgets.TbDateTimePicker', $model, $attribute, $options);
866 return $this->
widgetGroupInternal(
'booster.widgets.TbSelect2', $model, $attribute, $options);
886 return $this->
widgetGroupInternal(
'booster.widgets.TbRedactorJs', $model, $attribute, $options);
906 return $this->
widgetGroupInternal(
'booster.widgets.TbHtml5Editor', $model, $attribute, $options);
926 return $this->
widgetGroupInternal(
'booster.widgets.TbMarkdownEditor', $model, $attribute, $options);
946 return $this->
widgetGroupInternal(
'booster.widgets.TbCKEditor', $model, $attribute, $options);
966 return $this->
widgetGroupInternal(
'booster.widgets.TbTypeahead', $model, $attribute, $options);
1006 return $this->
widgetGroupInternal(
'booster.widgets.TbColorPicker', $model, $attribute, $options);
1027 public function captchaGroup($model, $attribute, $htmlOptions = array(), $options = array()) {
1030 $widgetOptions = $options[
'widgetOptions'];
1032 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
1034 $fieldData = $this->textField($model, $attribute, $widgetOptions[
'htmlOptions']);
1035 unset($widgetOptions[
'htmlOptions']);
1036 $fieldData .=
'<div class="captcha">' . $this->owner->widget(
'CCaptcha', $widgetOptions,
true) .
'</div>';
1058 return $this->
widgetGroupInternal(
'booster.widgets.TbPassfield', $model, $attribute, $options);
1095 public function widgetGroup($className, $model, $attribute, $options = array()) {
1098 $widgetOptions = isset($options[
'widgetOptions']) ? $options[
'widgetOptions'] : null;
1100 $fieldData = array(array($this->owner,
'widget'), array($className, $widgetOptions,
true));
1118 $widgetOptions = $options[
'widgetOptions'];
1119 $widgetOptions[
'model'] = $model;
1120 $widgetOptions[
'attribute'] = $attribute;
1122 $this->
addCssClass($widgetOptions[
'htmlOptions'],
'form-control');
1124 $fieldData = array(array($this->owner,
'widget'), array($className, $widgetOptions,
true));
1146 switch ($this->type) {
1147 case self::TYPE_HORIZONTAL:
1151 case self::TYPE_VERTICAL:
1152 $this->
verticalGroup($fieldData, $model, $attribute, $options);
1155 case self::TYPE_INLINE:
1156 $this->
inlineGroup($fieldData, $model, $attribute, $options);
1160 throw new CException(
'Invalid form type');
1163 return ob_get_clean();
1173 if(!is_array($fieldData)
1174 || empty($fieldData[0][1])
1175 || !is_array($fieldData[1])
1179 $model = $fieldData[1][0];
1180 if(!$model instanceof CModel)
1183 $attribute = $fieldData[1][1];
1184 if(!empty($fieldData[1][3]) && is_array($fieldData[1][3])) {
1186 $htmlOptions = &$fieldData[1][3];
1189 $htmlOptions = &$fieldData[1][2];
1191 if (!isset($htmlOptions[
'placeholder'])) {
1192 $htmlOptions[
'placeholder'] = $model->getAttributeLabel($attribute);
1207 $groupOptions = isset($options[
'groupOptions']) ? $options[
'groupOptions']: array();
1210 if ($model->hasErrors($attribute))
1211 self::addCssClass($groupOptions,
'has-error');
1213 echo CHtml::openTag(
'div', $groupOptions);
1216 if (isset($options[
'label'])) {
1217 if (!empty($options[
'label'])) {
1218 echo CHtml::label($options[
'label'], CHtml::activeId($model, $attribute), $options[
'labelOptions']);
1220 echo
'<span class="col-sm-3"></span>';
1223 echo $this->labelEx($model, $attribute, $options[
'labelOptions']);
1227 if(isset($options[
'wrapperHtmlOptions']) && !empty($options[
'wrapperHtmlOptions']))
1228 $wrapperHtmlOptions = $options[
'wrapperHtmlOptions'];
1230 $wrapperHtmlOptions = $options[
'wrapperHtmlOptions'] = array();
1231 $this->
addCssClass($wrapperHtmlOptions,
'col-sm-9');
1232 echo CHtml::openTag(
'div', $wrapperHtmlOptions);
1234 if (!empty($options[
'prepend']) || !empty($options[
'append'])) {
1235 $this->
renderAddOnBegin($options[
'prepend'], $options[
'append'], $options[
'prependOptions']);
1238 if (is_array($fieldData)) {
1239 echo call_user_func_array($fieldData[0], $fieldData[1]);
1244 if (!empty($options[
'prepend']) || !empty($options[
'append'])) {
1245 $this->
renderAddOnEnd($options[
'append'], $options[
'appendOptions']);
1248 if ($this->showErrors && $options[
'errorOptions'] !==
false) {
1249 echo $this->error($model, $attribute, $options[
'errorOptions'], $options[
'enableAjaxValidation'], $options[
'enableClientValidation']);
1252 if (isset($options[
'hint'])) {
1254 echo CHtml::tag($this->hintTag, $options[
'hintOptions'], $options[
'hint']);
1257 echo
'</div></div>';
1269 protected function verticalGroup(&$fieldData, &$model, &$attribute, &$options) {
1271 $groupOptions = isset($options[
'groupOptions']) ? $options[
'groupOptions']: array();
1274 if ($model->hasErrors($attribute))
1275 self::addCssClass($groupOptions,
'has-error');
1277 echo CHtml::openTag(
'div', $groupOptions);
1280 if (isset($options[
'label'])) {
1281 if (!empty($options[
'label'])) {
1282 echo CHtml::label($options[
'label'], CHtml::activeId($model, $attribute), $options[
'labelOptions']);
1285 echo $this->labelEx($model, $attribute, $options[
'labelOptions']);
1288 if (!empty($options[
'prepend']) || !empty($options[
'append'])) {
1289 $this->
renderAddOnBegin($options[
'prepend'], $options[
'append'], $options[
'prependOptions']);
1292 if (is_array($fieldData)) {
1293 echo call_user_func_array($fieldData[0], $fieldData[1]);
1298 if (!empty($options[
'prepend']) || !empty($options[
'append'])) {
1299 $this->
renderAddOnEnd($options[
'append'], $options[
'appendOptions']);
1302 if ($this->showErrors && $options[
'errorOptions'] !==
false) {
1303 echo $this->error($model, $attribute, $options[
'errorOptions'], $options[
'enableAjaxValidation'], $options[
'enableClientValidation']);
1306 if (isset($options[
'hint'])) {
1308 echo CHtml::tag($this->hintTag, $options[
'hintOptions'], $options[
'hint']);
1322 protected function inlineGroup(&$fieldData, &$model, &$attribute, &$options) {
1324 echo
'<div class="form-group">';
1326 if (!empty($options[
'prepend']) || !empty($options[
'append']))
1327 $this->
renderAddOnBegin($options[
'prepend'], $options[
'append'], $options[
'prependOptions']);
1329 if (is_array($fieldData)) {
1330 echo call_user_func_array($fieldData[0], $fieldData[1]);
1335 if (!empty($options[
'prepend']) || !empty($options[
'append']))
1336 $this->
renderAddOnEnd($options[
'append'], $options[
'appendOptions']);
1338 if ($this->showErrors && $options[
'errorOptions'] !==
false) {
1339 echo $this->error($model, $attribute, $options[
'errorOptions'], $options[
'enableAjaxValidation'], $options[
'enableClientValidation']);
1354 $wrapperCssClass = array();
1355 if (!empty($prependText))
1357 if (!empty($appendText))
1360 echo CHtml::tag($this->addOnWrapperTag, array(
'class' => implode(
' ', $wrapperCssClass)),
false,
false);
1361 if (!empty($prependText)) {
1362 if (isset($prependOptions[
'isRaw']) && $prependOptions[
'isRaw']) {
1366 echo CHtml::tag($this->addOnTag, $prependOptions, $prependText);
1379 if (!empty($appendText)) {
1380 if (isset($appendOptions[
'isRaw']) && $appendOptions[
'isRaw']) {
1384 echo CHtml::tag($this->addOnTag, $appendOptions, $appendText);
1388 echo CHtml::closeTag($this->addOnWrapperTag);
1396 if (!isset($options[
'groupOptions']))
1397 $options[
'groupOptions'] = array();
1399 if (!isset($options[
'labelOptions']))
1400 $options[
'labelOptions'] = array();
1402 if (!isset($options[
'widgetOptions']))
1403 $options[
'widgetOptions'] = array();
1405 if (!isset($options[
'widgetOptions'][
'htmlOptions']))
1406 $options[
'widgetOptions'][
'htmlOptions'] = array();
1408 if($initData && !isset($options[
'widgetOptions'][
'data']))
1409 $options[
'widgetOptions'][
'data'] = array();
1411 if (!isset($options[
'errorOptions']))
1412 $options[
'errorOptions'] = array();
1414 if (!isset($options[
'prependOptions']))
1415 $options[
'prependOptions'] = array();
1417 if (!isset($options[
'prepend']))
1418 $options[
'prepend'] = null;
1420 if (!isset($options[
'appendOptions']))
1421 $options[
'appendOptions'] = array();
1423 if (!isset($options[
'append']))
1424 $options[
'append'] = null;
1426 if(!isset($options[
'enableAjaxValidation']))
1427 $options[
'enableAjaxValidation'] =
true;
1429 if(!isset($options[
'enableClientValidation']))
1430 $options[
'enableClientValidation'] =
true;
1445 if (isset($htmlOptions[
'class'])) {
1446 $htmlOptions[
'class'] .=
' ' .
$class;
1448 $htmlOptions[
'class'] =
$class;