1: <?php
2: /**
3: * TbForm class file.
4: * @author Christoffer Niska <[email protected]>
5: * @copyright Copyright © Christoffer Niska 2013-
6: * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7: * @package bootstrap.form
8: */
9:
10: /**
11: * Bootstrap form object that contains form input specifications.
12: */
13: class TbForm extends CForm
14: {
15: /**
16: * @var string the name of the class for representing a form input element.
17: */
18: public $inputElementClass = 'TbFormInputElement';
19:
20: /**
21: * @var string the name of the class for representing a form button element.
22: */
23: public $buttonElementClass = 'TbButtonElement';
24:
25: /**
26: * @var array the configuration used to create the active form widget.
27: */
28: public $activeForm = 'TbActiveForm';
29:
30: /**
31: * Renders a single element which could be an input element, a sub-form, a string, or a button.
32: * @param mixed $element the form element to be rendered.
33: * @return string the rendering result
34: */
35: public function renderElement($element)
36: {
37: if (is_string($element)) {
38: if (($e = $this[$element]) === null && ($e = $this->getButtons()->itemAt($element)) === null) {
39: return $element;
40: } else {
41: $element = $e;
42: }
43: }
44: if ($element->getVisible()) {
45: if ($element instanceof CFormInputElement) {
46: if ($element->type === 'hidden') {
47: return TbHtml::tag('div', array('class' => 'hidden'), $element->render());
48: }
49: }
50: return $element->render();
51: }
52: return '';
53: }
54:
55: /**
56: * Renders the buttons in this form.
57: * @return string the rendering result.
58: */
59: public function renderButtons()
60: {
61: $buttons = array();
62: foreach ($this->getButtons() as $button) {
63: $buttons[] = $this->rendeRelement($button);
64: }
65: return !empty($buttons) ? TbHtml::tag('div', array('class' => 'form-actions'), implode("\n", $buttons)) : '';
66: }
67: }