phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlForm.php
Go to the documentation of this file.
1<?php
2
3namespace Ajax\bootstrap\html;
4
7
10
13 protected $futureElements;
14 protected $formGroups;
15
16 public function __construct($identifier) {
17 parent::__construct($identifier, "form");
18 $this->_template='<form id="%identifier%" name="%identifier%" %properties%>%content%</form>';
19 $this->futureElements=array ();
20 $this->formGroups=array ();
21 }
22
23 /*
24 * (non-PHPdoc)
25 * @see \Ajax\bootstrap\html\base\BaseHtml::compile()
26 */
27 public function compile(JsUtils $js=NULL, &$view=NULL) {
28 if (isset($js)) {
29 $this->formElementsPrefix=$js->config()->getVar("formElementsPrefix");
30 foreach ( $this->futureElements as $futureElement ) {
31 $futureElementValue=$this->getPrefix($futureElement);
32 $futureElementValues=explode("_", $futureElementValue);
33 switch($futureElementValues [0]) {
34 case "input":
35 $control=new HtmlInput($futureElement);
36 $control->setClass("form-control");
37 $control->setLabel($this->getPart($futureElement));
38 break;
39 case "checkbox":
40 $control=new HtmlInputCheckbox($futureElement);
41 $control->setLabel($this->getPart($futureElement), false);
42 break;
43 case "radio":
44 $name=$this->getPart($futureElement);
45 $label=$this->getPart($futureElement, 2);
46 $control=new HtmlInputRadio($futureElement);
47 $control->setProperty("name", strtolower($name));
48 $control->setLabel($label, false);
49 break;
50 case "select":
51 $control=new HtmlSelect($futureElement,"");
52 $control->setProperty("size", $futureElementValues [1]);
53 $control->setClass("form-control");
54 break;
55 default:
56 $control=new HtmlInput($futureElement);
57 $control->setClass("form-control");
58 $control->setLabel($this->getPart($futureElement));
59 break;
60 }
61 $this->addElement($control);
62 }
63 }
64 foreach ( $this->formGroups as $group ) {
65 $this->addContent($group);
66 }
67 return parent::compile($js, $view);
68 }
69
70 private function getPart($str, $part=1) {
71 $result=preg_split('/(?=[A-Z])/', $str);
72 if (sizeof($result)>$part) {
73 $result=$result [$part];
74 } else {
75 $result=$str;
76 }
77 return $result;
78 }
79
80 protected function getId($str) {
81 $result=preg_split('/(?=[A-Z])/', $str);
82 if (sizeof($result)>2) {
83 $result=$result [2];
84 } else {
85 $result=$str;
86 }
87 return $result;
88 }
89
90 protected function getPrefix($element) {
91 $result="input_text";
92 foreach ( $this->formElementsPrefix as $k => $v ) {
93 if (JString::startswith($element, $k)) {
94 $result=$v;
95 break;
96 }
97 }
98 return $result;
99 }
100
101 public function addGroup($identifier="") {
102 if ($identifier==="")
103 $identifier="form-".$this->identifier;
105 $group->setTagName("div");
106 $group->setClass("form-group");
107 $this->formGroups []=$group;
108 return $group;
109 }
110
111 public function addElement($element) {
112 if (sizeof($this->formGroups)===0) {
113 $this->addGroup();
114 }
115 $group=$this->formGroups [sizeof($this->formGroups)-1];
116 $group->addContent($element);
117 return $group;
118 }
119
120 public function getElement($name) {
121 $element=null;
122 foreach ( $this->formGroups as $group ) {
123 }
124 return $element;
125 }
126
127 /*
128 * (non-PHPdoc)
129 * @see \Ajax\bootstrap\html\base\HtmlSingleElement::fromArray()
130 */
131 public function fromArray($array) {
132 foreach ( $array as $value ) {
133 if (is_string($value)) {
134 $this->futureElements []=$value;
135 }
136 }
137 }
138}
JQuery PHP library.
Definition JsUtils.php:23
compile(JsUtils $js=NULL, &$view=NULL)
Definition HtmlForm.php:27
Twitter Bootstrap HTML Input checkbox component.
Twitter Bootstrap simple Input component.
Definition HtmlInput.php:13
Twitter Bootstrap HTML Input radio component.
addContent($content, $before=false)