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
4
11use Ajax\JsUtils;
17
28 protected $_fields;
29
34
36
37 public function __construct($identifier, $elements=array()) {
38 parent::__construct($identifier, "form", "ui form");
39 $this->_states=[ State::ERROR,State::SUCCESS,State::WARNING,State::DISABLED ];
40 $this->setProperty("name", $this->identifier);
41 $this->_fields=array ();
42 $this->addItems($elements);
43 $this->_validationParams=[];
44 $this->_extraFieldRules=[];
45 }
46
47 protected function getForm(){
48 return $this;
49 }
50
57 public function addHeader($title, $niveau=1, $dividing=true) {
58 $header=new HtmlHeader("", $niveau, $title);
59 if ($dividing)
60 $header->setDividing();
61 return $this->addItem($header);
62 }
63
69 public function addDivider($caption=NULL){
70 return $this->addContent(new HtmlDivider("",$caption));
71 }
72
79 public function addFields($fields=NULL, $label=NULL) {
80 if (isset($fields)) {
81 if (!$fields instanceof HtmlFormFields) {
82 if (!\is_array($fields)) {
83 $fields=\func_get_args();
84 $end=\end($fields);
85 if (\is_string($end)) {
86 $label=$end;
87 \array_pop($fields);
88 } else
89 $label=NULL;
90 }
91 $this->_fields=\array_merge($this->_fields, $fields);
92 $fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count(), $fields);
93 }
94 if (isset($label)){
95 $fields->wrap("<div class='field'><label>{$label}</label>","</div>");
96 }
97 } else {
98 $fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count());
99 }
100 $this->addItem($fields);
101 return $fields;
102 }
103
104 public function addItem($item) {
105 $item=parent::addItem($item);
106 if (\is_subclass_of($item, HtmlFormField::class) === true) {
107 $this->_fields[]=$item;
108 }
109 return $item;
110 }
111
116 public function getField($index) {
117 if (\is_string($index)) {
118 $field=$this->getElementById($index, $this->_fields);
119 } else {
120 $field=$this->_fields[$index];
121 }
122 return $field;
123 }
124
129 public function setEqualWidth() {
130 return $this->addToProperty("class", "equal width");
131 }
132
138 public function addField($field) {
139 return $this->addItem($field);
140 }
141
151 public function addMessage($identifier, $content, $header=NULL, $icon=NULL, $type=NULL) {
152 $message=new HtmlMessage($identifier, $content);
153 if (isset($header))
154 $message->addHeader($header);
155 if (isset($icon))
156 $message->setIcon($icon);
157 if (isset($type))
158 $message->setStyle($type);
159 return $this->addItem($message);
160 }
161
162
163
164 public function compile(JsUtils $js=NULL,&$view=NULL){
165 if(\sizeof($this->_validationParams)>0)
166 $this->setProperty("novalidate", "");
167 return parent::compile($js,$view);
168 }
169
170 public function run(JsUtils $js) {
171 if(isset($js)){
172 $compo=$js->semantic()->form("#".$this->identifier);
173 }else{
174 $compo=new Form();
175 $compo->attach("#".$this->identifier);
176 }
177 foreach ($this->_fields as $field){
178 if($field instanceof HtmlFormField){
179 $this->addCompoValidation($compo, $field);
180 }
181 }
182 foreach ($this->content as $field){
183 if($field instanceof HtmlFormFields){
184 $items=$field->getItems();
185 foreach ($items as $_field){
186 if($_field instanceof HtmlFormField)
187 $this->addCompoValidation($compo, $_field);
188 }
189 }
190 }
191 foreach ($this->_extraFieldRules as $field=>$fieldValidation){
192 $this->addExtraCompoValidation($compo, $fieldValidation);
193 }
194 $this->_runValidationParams($compo,$js);
195 return $this->_bsComponent;
196 }
197
198 public function getExtraFieldValidation($fieldname){
199 if(!isset($this->_extraFieldRules[$fieldname])){
200 $this->_extraFieldRules[$fieldname]=new FieldValidation($fieldname);
201 }
202 return $this->_extraFieldRules[$fieldname];
203 }
204
205 public function addValidationParam($paramName,$paramValue,$before="",$after=""){
206 $this->addBehavior($this->_validationParams, $paramName, $paramValue,$before,$after);
207 return $this;
208 }
209
211 $this->_validationParams=$_validationParams;
212 return $this;
213 }
214
215 public function hasValidationParams(){
216 return sizeof($this->_validationParams)>0;
217 }
218
219 public function getValidationParams() {
221 }
222
223 public function removeValidationParam($param){
224 unset($this->_validationParams[$param]);
225 return $this;
226 }
227
228}
JQuery PHP library.
Definition JsUtils.php:23
semantic(Semantic $semantic=NULL)
getter or setter of the Semantic-UI variable
Definition JsUtils.php:158
BaseHtml for HTML components.
Definition BaseHtml.php:17
getElementById($identifier, $elements)
Definition BaseHtml.php:178
Base class for Semantic Html collections.
addBehavior(&$array, $key, $value, $before="", $after="")
addToProperty($name, $value, $separator=" ")
addContent($content, $before=false)
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\Bas...
Definition HtmlForm.php:170
addHeader($title, $niveau=1, $dividing=true)
Definition HtmlForm.php:57
addMessage($identifier, $content, $header=NULL, $icon=NULL, $type=NULL)
Definition HtmlForm.php:151
addField($field)
Adds a field (alias for addItem)
Definition HtmlForm.php:138
addValidationParam($paramName, $paramValue, $before="", $after="")
Definition HtmlForm.php:205
addItem($item)
adds and returns an item
Definition HtmlForm.php:104
compile(JsUtils $js=NULL, &$view=NULL)
Definition HtmlForm.php:164
setValidationParams(array $_validationParams)
Definition HtmlForm.php:210
setEqualWidth()
automatically divide fields to be equal width
Definition HtmlForm.php:129
addDivider($caption=NULL)
Adds a divider.
Definition HtmlForm.php:69
addFields($fields=NULL, $label=NULL)
Adds a group of fields.
Definition HtmlForm.php:79
__construct($identifier, $elements=array())
Definition HtmlForm.php:37
addExtraCompoValidation(Form $compo, FieldValidation $validation)
Definition FormTrait.php:34
_runValidationParams(Form &$compo, JsUtils $js=NULL)
Definition FormTrait.php:38
addCompoValidation(Form $compo, HtmlFormField $field)
Definition FormTrait.php:26
Semantic UI divider component.
Semantic Header component.