@@ -9,43 +9,43 @@ |
||
| 9 | 9 | interface FormBuilderInterface |
| 10 | 10 | { |
| 11 | 11 | /* COMMON METHODS */ |
| 12 | - public function Create($attributes=[]); |
|
| 12 | + public function Create($attributes = []); |
|
| 13 | 13 | public function Close(); |
| 14 | - public function OpenFieldset($attributes=[]); |
|
| 14 | + public function OpenFieldset($attributes = []); |
|
| 15 | 15 | public function CloseFieldset(); |
| 16 | 16 | |
| 17 | 17 | /* INPUT TYPES */ |
| 18 | - public function addAudio($label,$attributes=[]); |
|
| 19 | - public function addButton($label,$attributes=[]); |
|
| 20 | - public function addCaptcha($label,$attributes=[]); |
|
| 21 | - public function addCheckbox($label,$options=[],$attributes=[]); |
|
| 22 | - public function addColor($label,$attributes=[]); |
|
| 23 | - public function addCountry($label,$attributes=[]); |
|
| 24 | - public function addDate($label,$attributes=[]); |
|
| 25 | - public function addDatetime($label,$attributes=[]); |
|
| 26 | - public function addDatetimeLocal($label,$attributes=[]); |
|
| 27 | - public function addEmail($label,$attributes=[]); |
|
| 28 | - public function addFile($label,$attributes=[]); |
|
| 29 | - public function addHidden($label,$attributes=[]); |
|
| 30 | - public function addImage($label,$attributes=[]); |
|
| 31 | - public function addMonth($label,$attributes=[]); |
|
| 32 | - public function addNumber($label,$attributes=[]); |
|
| 33 | - public function addPassword($label,$attributes=[]); |
|
| 34 | - public function addPhone($label,$attributes=[]); |
|
| 35 | - public function addRadio($label,$options=[],$attributes=[]); |
|
| 36 | - public function addRange($label,$attributes=[]); |
|
| 37 | - public function addReset($label,$attributes=[]); |
|
| 38 | - public function addSearch($label,$attributes=[]); |
|
| 39 | - public function addSelect($label,$options=[],$attributes=[]); |
|
| 40 | - public function addSubmit($label,$attributes=[]); |
|
| 41 | - public function addText($label,$attributes=[]); |
|
| 42 | - public function addTextarea($label,$attributes=[]); |
|
| 43 | - public function addTextEditor($label,$attributes=[]); |
|
| 44 | - public function addTime($label,$attributes=[]); |
|
| 45 | - public function addUrl($label,$attributes=[]); |
|
| 46 | - public function addVideo($label,$attributes=[]); |
|
| 47 | - public function addWeek($label,$attributes=[]); |
|
| 48 | - public function addYesNo($label,$attributes=[]); |
|
| 18 | + public function addAudio($label, $attributes = []); |
|
| 19 | + public function addButton($label, $attributes = []); |
|
| 20 | + public function addCaptcha($label, $attributes = []); |
|
| 21 | + public function addCheckbox($label, $options = [], $attributes = []); |
|
| 22 | + public function addColor($label, $attributes = []); |
|
| 23 | + public function addCountry($label, $attributes = []); |
|
| 24 | + public function addDate($label, $attributes = []); |
|
| 25 | + public function addDatetime($label, $attributes = []); |
|
| 26 | + public function addDatetimeLocal($label, $attributes = []); |
|
| 27 | + public function addEmail($label, $attributes = []); |
|
| 28 | + public function addFile($label, $attributes = []); |
|
| 29 | + public function addHidden($label, $attributes = []); |
|
| 30 | + public function addImage($label, $attributes = []); |
|
| 31 | + public function addMonth($label, $attributes = []); |
|
| 32 | + public function addNumber($label, $attributes = []); |
|
| 33 | + public function addPassword($label, $attributes = []); |
|
| 34 | + public function addPhone($label, $attributes = []); |
|
| 35 | + public function addRadio($label, $options = [], $attributes = []); |
|
| 36 | + public function addRange($label, $attributes = []); |
|
| 37 | + public function addReset($label, $attributes = []); |
|
| 38 | + public function addSearch($label, $attributes = []); |
|
| 39 | + public function addSelect($label, $options = [], $attributes = []); |
|
| 40 | + public function addSubmit($label, $attributes = []); |
|
| 41 | + public function addText($label, $attributes = []); |
|
| 42 | + public function addTextarea($label, $attributes = []); |
|
| 43 | + public function addTextEditor($label, $attributes = []); |
|
| 44 | + public function addTime($label, $attributes = []); |
|
| 45 | + public function addUrl($label, $attributes = []); |
|
| 46 | + public function addVideo($label, $attributes = []); |
|
| 47 | + public function addWeek($label, $attributes = []); |
|
| 48 | + public function addYesNo($label, $attributes = []); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public function addAudio($label,$attributes=[]) |
| 134 | 134 | { |
| 135 | - // $attributes['accept']='audio/*;capture=microphone'; |
|
| 135 | + // $attributes['accept']='audio/*;capture=microphone'; |
|
| 136 | 136 | $attributes['accept']='audio/*'; |
| 137 | 137 | return $this->addFile($label,$attributes); |
| 138 | 138 | } |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | */ |
| 354 | 354 | public function addImage($label,$attributes=[]){ |
| 355 | 355 | $attributes['accept']='image/*'; |
| 356 | - // $attributes['accept']='image/*;capture=camera'; |
|
| 356 | + // $attributes['accept']='image/*;capture=camera'; |
|
| 357 | 357 | return $this->addFile($label,$attributes); |
| 358 | 358 | } |
| 359 | 359 | |
@@ -13,25 +13,25 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class PhpFormBuilder implements FormBuilderInterface |
| 15 | 15 | { |
| 16 | - private $GlobalAttributes=['accesskey','class','contenteditable', 'contextmenu','dir','draggable','dropzone','hidden','id','lang','spellcheck','style','tabindex','title','translate']; |
|
| 17 | - private $AllowedEvents = ['onblur','onchange','oncontextmenu','onfocus','oninput','oninvalid','onreset','onsearch','onselect','onsubmit','onkeydown','onkeypress','onkeyup','onclick','ondblclick','ondrag','ondragend','ondragenter','ondragleave','ondragover','ondragstart','ondrop','onmousedown','onmousemove','onmouseout','onmouseover','onmouseup','onmousewheel','onscroll','onwheel']; |
|
| 18 | - private $AllowedAttributes= [ |
|
| 19 | - 'button'=>['autofocus','disabled','form','formaction','formenctype','formmethod','formnovalidate','formtarget','framename','name','type','value'], |
|
| 20 | - 'checkbox'=>['autofocus','checked','defaultChecked','defaultvalue','disabled','form','indeterminate','name','required','type','value'], |
|
| 21 | - 'color'=>['autocomplete','autofocus','defaultvalue','disabled','form','list','name','type','value'], |
|
| 22 | - 'date'=>['autocomplete','autofocus','defaultvalue','disabled','form','list','max','min','name','readonly','required','step','type','value'], |
|
| 23 | - 'fieldset'=>['disabled','form','name','legend','legend-attributes'], |
|
| 24 | - 'file'=>['accept','autofocus','defaultvalue','disabled','files','form','multiple','name','required','type','value'], |
|
| 25 | - 'form'=>['accept','accept-charset','action','autocomplete','enctype','method','name','novalidate','target'], |
|
| 26 | - 'hidden'=>['form','name','type','value'], |
|
| 27 | - 'image'=>['alt','autofocus','defaultvalue','disabled','form','formaction','formenctype','formmethod','formnovalidate','formtarget','height','name','src','type','value','width'], |
|
| 28 | - 'label'=>['for','form'], |
|
| 29 | - 'option'=>['disabled','label','value','selected'], |
|
| 30 | - 'range'=>['autocomplete','autofocus','defaultvalue','disabled','form','list','max','min','name','step','type','value'], |
|
| 31 | - 'reset'=>['autofocus','defaultvalue','disabled','form','name','type','value'], |
|
| 32 | - 'select'=>['autofocus','disabled','form','multiple','name','required','size','selected','optgroup-attributes','option-attributes','value'], |
|
| 33 | - 'text'=>['autocomplete','autofocus','defaultvalue','disabled','form','list','minlength','maxlength','name','pattern','placeholder','readonly','required','size','type','value'], |
|
| 34 | - 'textarea'=>['autofocus','cols','dirname','disabled','form','maxlength','name','placeholder','readonly','required','rows','wrap','value'] |
|
| 16 | + private $GlobalAttributes = ['accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', 'translate']; |
|
| 17 | + private $AllowedEvents = ['onblur', 'onchange', 'oncontextmenu', 'onfocus', 'oninput', 'oninvalid', 'onreset', 'onsearch', 'onselect', 'onsubmit', 'onkeydown', 'onkeypress', 'onkeyup', 'onclick', 'ondblclick', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onscroll', 'onwheel']; |
|
| 18 | + private $AllowedAttributes = [ |
|
| 19 | + 'button'=>['autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'framename', 'name', 'type', 'value'], |
|
| 20 | + 'checkbox'=>['autofocus', 'checked', 'defaultChecked', 'defaultvalue', 'disabled', 'form', 'indeterminate', 'name', 'required', 'type', 'value'], |
|
| 21 | + 'color'=>['autocomplete', 'autofocus', 'defaultvalue', 'disabled', 'form', 'list', 'name', 'type', 'value'], |
|
| 22 | + 'date'=>['autocomplete', 'autofocus', 'defaultvalue', 'disabled', 'form', 'list', 'max', 'min', 'name', 'readonly', 'required', 'step', 'type', 'value'], |
|
| 23 | + 'fieldset'=>['disabled', 'form', 'name', 'legend', 'legend-attributes'], |
|
| 24 | + 'file'=>['accept', 'autofocus', 'defaultvalue', 'disabled', 'files', 'form', 'multiple', 'name', 'required', 'type', 'value'], |
|
| 25 | + 'form'=>['accept', 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'target'], |
|
| 26 | + 'hidden'=>['form', 'name', 'type', 'value'], |
|
| 27 | + 'image'=>['alt', 'autofocus', 'defaultvalue', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', 'name', 'src', 'type', 'value', 'width'], |
|
| 28 | + 'label'=>['for', 'form'], |
|
| 29 | + 'option'=>['disabled', 'label', 'value', 'selected'], |
|
| 30 | + 'range'=>['autocomplete', 'autofocus', 'defaultvalue', 'disabled', 'form', 'list', 'max', 'min', 'name', 'step', 'type', 'value'], |
|
| 31 | + 'reset'=>['autofocus', 'defaultvalue', 'disabled', 'form', 'name', 'type', 'value'], |
|
| 32 | + 'select'=>['autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', 'selected', 'optgroup-attributes', 'option-attributes', 'value'], |
|
| 33 | + 'text'=>['autocomplete', 'autofocus', 'defaultvalue', 'disabled', 'form', 'list', 'minlength', 'maxlength', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'size', 'type', 'value'], |
|
| 34 | + 'textarea'=>['autofocus', 'cols', 'dirname', 'disabled', 'form', 'maxlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'wrap', 'value'] |
|
| 35 | 35 | ]; |
| 36 | 36 | public $ValidationErrors = []; |
| 37 | 37 | private $OptionResolver; |
@@ -41,16 +41,16 @@ discard block |
||
| 41 | 41 | * PhpFormBuilder constructor. |
| 42 | 42 | * @param string $method |
| 43 | 43 | */ |
| 44 | - public function __construct($method = 'post'){ |
|
| 45 | - try{ |
|
| 44 | + public function __construct($method = 'post') { |
|
| 45 | + try { |
|
| 46 | 46 | $method = strtolower(trim($method)); |
| 47 | - if(!in_array($method,['get','post'],true)) |
|
| 47 | + if (!in_array($method, ['get', 'post'], true)) |
|
| 48 | 48 | $method = $_SERVER['REQUEST_METHOD']; |
| 49 | 49 | $this->RequestMethod = $method; |
| 50 | - $this->OptionResolver= new PhpOptionsResolver(); |
|
| 50 | + $this->OptionResolver = new PhpOptionsResolver(); |
|
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | - catch(\Exception $e){echo $e->getMessage();} |
|
| 53 | + catch (\Exception $e) {echo $e->getMessage(); } |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | /* COMMON METHODS */ |
@@ -58,23 +58,23 @@ discard block |
||
| 58 | 58 | * @param array $attributes |
| 59 | 59 | * @return PhpFormBuilder |
| 60 | 60 | */ |
| 61 | - public function Create($attributes=[]){ |
|
| 62 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 61 | + public function Create($attributes = []) { |
|
| 62 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 63 | 63 | $this->OptionResolver->setDefaults([ |
| 64 | 64 | 'method'=>'post', |
| 65 | 65 | 'action'=>basename($_SERVER["SCRIPT_NAME"]), |
| 66 | 66 | 'enctype'=>'application/x-www-form-urlencoded', |
| 67 | 67 | 'name'=>md5($_SERVER['REQUEST_URI'].microtime(true)) |
| 68 | 68 | ]); |
| 69 | - $this->OptionResolver->addAllowedValues('method',['post','get']); |
|
| 70 | - $this->OptionResolver->addAllowedValues('enctype',[ |
|
| 69 | + $this->OptionResolver->addAllowedValues('method', ['post', 'get']); |
|
| 70 | + $this->OptionResolver->addAllowedValues('enctype', [ |
|
| 71 | 71 | 'application/x-www-form-urlencoded', |
| 72 | 72 | 'multipart/form-data', |
| 73 | 73 | 'text/plain']); |
| 74 | - $this->OptionResolver->addAllowedTypes('action','string'); |
|
| 75 | - $this->OptionResolver->addAllowedTypes('name','string'); |
|
| 76 | - $attributes=$this->OptionResolver->resolve($this->FilterAttributes($attributes,'form')); |
|
| 77 | - if(strcasecmp($attributes['method'],'get') == 0) unset($attributes['enctype']); |
|
| 74 | + $this->OptionResolver->addAllowedTypes('action', 'string'); |
|
| 75 | + $this->OptionResolver->addAllowedTypes('name', 'string'); |
|
| 76 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, 'form')); |
|
| 77 | + if (strcasecmp($attributes['method'], 'get') == 0) unset($attributes['enctype']); |
|
| 78 | 78 | $html = '<form'; |
| 79 | 79 | $html .= $this->BuildAttributes($attributes); |
| 80 | 80 | $html .= '>'; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * @return mixed |
| 86 | 86 | */ |
| 87 | - public function Close(){ |
|
| 87 | + public function Close() { |
|
| 88 | 88 | return $this->Save($html = '</form>'); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -92,22 +92,22 @@ discard block |
||
| 92 | 92 | * @param array $attributes |
| 93 | 93 | * @return PhpFormBuilder |
| 94 | 94 | */ |
| 95 | - public function OpenFieldset($attributes=[]){ |
|
| 96 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 95 | + public function OpenFieldset($attributes = []) { |
|
| 96 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 97 | 97 | $this->OptionResolver->setDefaults([ |
| 98 | 98 | 'legend'=>null, |
| 99 | 99 | 'name'=>md5($_SERVER['REQUEST_URI'].microtime(true)) |
| 100 | 100 | ]); |
| 101 | - $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'fieldset')); |
|
| 102 | - $html ='<fieldset'; |
|
| 103 | - if($attributes) |
|
| 104 | - $html.= $this->BuildAttributes($attributes,array('legend','label','id','legend-attributes')); |
|
| 101 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, 'fieldset')); |
|
| 102 | + $html = '<fieldset'; |
|
| 103 | + if ($attributes) |
|
| 104 | + $html .= $this->BuildAttributes($attributes, array('legend', 'label', 'id', 'legend-attributes')); |
|
| 105 | 105 | $html .= ' >'; |
| 106 | - if(isset($attributes['legend'])) |
|
| 106 | + if (isset($attributes['legend'])) |
|
| 107 | 107 | { |
| 108 | - $attributes['legend-attributes']?:[]; |
|
| 109 | - is_array($attributes['legend-attributes']) or $attributes['legend-attributes']=[$attributes['legend-attributes']]; |
|
| 110 | - $legendAttributes=$this->FilterAttributes($attributes['legend-attributes'],'legend'); |
|
| 108 | + $attributes['legend-attributes'] ?: []; |
|
| 109 | + is_array($attributes['legend-attributes']) or $attributes['legend-attributes'] = [$attributes['legend-attributes']]; |
|
| 110 | + $legendAttributes = $this->FilterAttributes($attributes['legend-attributes'], 'legend'); |
|
| 111 | 111 | $html .= '<legend'; |
| 112 | 112 | $html .= $this->BuildAttributes($legendAttributes); |
| 113 | 113 | $html .= '>'; |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | /** |
| 121 | 121 | * @return PhpFormBuilder |
| 122 | 122 | */ |
| 123 | - public function CloseFieldset(){ |
|
| 124 | - return $this->Save($html='</fieldset>'); |
|
| 123 | + public function CloseFieldset() { |
|
| 124 | + return $this->Save($html = '</fieldset>'); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /* INPUT TYPES */ |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | * @param array $attributes |
| 131 | 131 | * @return PhpFormBuilder |
| 132 | 132 | */ |
| 133 | - public function addAudio($label,$attributes=[]) |
|
| 133 | + public function addAudio($label, $attributes = []) |
|
| 134 | 134 | { |
| 135 | 135 | // $attributes['accept']='audio/*;capture=microphone'; |
| 136 | - $attributes['accept']='audio/*'; |
|
| 137 | - return $this->addFile($label,$attributes); |
|
| 136 | + $attributes['accept'] = 'audio/*'; |
|
| 137 | + return $this->addFile($label, $attributes); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * @param array $attributes |
| 143 | 143 | * @return PhpFormBuilder |
| 144 | 144 | */ |
| 145 | - public function addButton($label,$attributes=[]){ |
|
| 145 | + public function addButton($label, $attributes = []) { |
|
| 146 | 146 | $attributes['type'] = 'button'; |
| 147 | - $attributes['value'] = $attributes['value']?:$label; |
|
| 148 | - $html = $this->CreateInput($label,$attributes); |
|
| 147 | + $attributes['value'] = $attributes['value'] ?: $label; |
|
| 148 | + $html = $this->CreateInput($label, $attributes); |
|
| 149 | 149 | return $this->Save($html); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | * @param array $attributes |
| 155 | 155 | * @return PhpFormBuilder |
| 156 | 156 | */ |
| 157 | - public function addCaptcha($label,$attributes=[]){ |
|
| 158 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 157 | + public function addCaptcha($label, $attributes = []) { |
|
| 158 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 159 | 159 | $this->OptionResolver->setDefaults([ |
| 160 | 160 | 'value'=>null, |
| 161 | 161 | 'maxlength'=>2, |
@@ -164,36 +164,36 @@ discard block |
||
| 164 | 164 | 'id'=>'inputCaptcha', |
| 165 | 165 | 'name'=>'Captcha' |
| 166 | 166 | ]); |
| 167 | - $label=$label?:'Entrez le résultat de'; |
|
| 167 | + $label = $label ?: 'Entrez le résultat de'; |
|
| 168 | 168 | $attributes['name'] = $this->normalize($attributes['name']); |
| 169 | - $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'text')); |
|
| 170 | - $operators = array('+','-','x'); |
|
| 169 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, 'text')); |
|
| 170 | + $operators = array('+', '-', 'x'); |
|
| 171 | 171 | shuffle($operators); |
| 172 | 172 | $operator = $operators[0]; |
| 173 | - switch($operator): |
|
| 173 | + switch ($operator): |
|
| 174 | 174 | case 'x': |
| 175 | - do{ |
|
| 176 | - $num1 = rand(2,6); |
|
| 177 | - $num2 = rand(3,7); |
|
| 175 | + do { |
|
| 176 | + $num1 = rand(2, 6); |
|
| 177 | + $num2 = rand(3, 7); |
|
| 178 | 178 | $response = $num2 * $num1; |
| 179 | - } while($response > 35); |
|
| 179 | + } while ($response > 35); |
|
| 180 | 180 | break; |
| 181 | 181 | case '-': |
| 182 | - do{ |
|
| 183 | - $num1 = rand(1,8); |
|
| 184 | - $num2 = rand(6,11); |
|
| 182 | + do { |
|
| 183 | + $num1 = rand(1, 8); |
|
| 184 | + $num2 = rand(6, 11); |
|
| 185 | 185 | $response = $num2 - $num1; |
| 186 | - } while($response < 2); |
|
| 186 | + } while ($response < 2); |
|
| 187 | 187 | break; |
| 188 | 188 | default: |
| 189 | - $num1 = rand(1,7); |
|
| 190 | - $num2 = rand(3,8); |
|
| 189 | + $num1 = rand(1, 7); |
|
| 190 | + $num2 = rand(3, 8); |
|
| 191 | 191 | $response = $num1 + $num2; |
| 192 | 192 | break; |
| 193 | 193 | endswitch; |
| 194 | 194 | $label .= ": $num2 $operator $num1"; |
| 195 | 195 | $_SESSION[md5($attributes['name'])] = $response; |
| 196 | - $html = $this->CreateInput($label,$attributes); |
|
| 196 | + $html = $this->CreateInput($label, $attributes); |
|
| 197 | 197 | return $this->Save($html); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,12 +202,12 @@ discard block |
||
| 202 | 202 | * @param array $attributes |
| 203 | 203 | * @return PhpFormBuilder |
| 204 | 204 | */ |
| 205 | - public function addColor($label,$attributes=[]) |
|
| 205 | + public function addColor($label, $attributes = []) |
|
| 206 | 206 | { |
| 207 | 207 | $attributes['pattern'] = '#[a-g0-9]{6}'; |
| 208 | 208 | $attributes['title'] = '6-digit hexidecimal color (e.g. #000000)'; |
| 209 | 209 | $attributes['type'] = 'color'; |
| 210 | - $html = $this->CreateInput($label,$attributes); |
|
| 210 | + $html = $this->CreateInput($label, $attributes); |
|
| 211 | 211 | return $this->Save($html); |
| 212 | 212 | } |
| 213 | 213 | /** |
@@ -216,47 +216,47 @@ discard block |
||
| 216 | 216 | * @param array $attributes |
| 217 | 217 | * @return PhpFormBuilder |
| 218 | 218 | */ |
| 219 | - public function addCheckbox($label,$options=[],$attributes=[]){ |
|
| 220 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 219 | + public function addCheckbox($label, $options = [], $attributes = []) { |
|
| 220 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 221 | 221 | $this->OptionResolver->setDefaults([ |
| 222 | 222 | 'value'=>$this->getDefaultValue($label), |
| 223 | 223 | 'type'=>'checkbox', |
| 224 | 224 | 'id'=>'input'.$this->normalize($label), |
| 225 | 225 | 'name'=>$this->normalize($label) |
| 226 | 226 | ]); |
| 227 | - $this->OptionResolver->addAllowedValues('type',['radio','checkbox']); |
|
| 228 | - $type = $attributes['type']?:'checkbox'; |
|
| 229 | - $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,$type)); |
|
| 230 | - if(strpos($attributes['id'],'input')!==0) |
|
| 227 | + $this->OptionResolver->addAllowedValues('type', ['radio', 'checkbox']); |
|
| 228 | + $type = $attributes['type'] ?: 'checkbox'; |
|
| 229 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, $type)); |
|
| 230 | + if (strpos($attributes['id'], 'input') !== 0) |
|
| 231 | 231 | $attributes['id'] = $this->normalize($attributes['id']); |
| 232 | 232 | |
| 233 | - if(sizeof($options)<2) |
|
| 233 | + if (sizeof($options) < 2) |
|
| 234 | 234 | { |
| 235 | - empty($attributes['value']) or $attributes['checked'] ='checked'; |
|
| 235 | + empty($attributes['value']) or $attributes['checked'] = 'checked'; |
|
| 236 | 236 | $attributes['value'] = '1'; |
| 237 | 237 | $attributes['type'] = 'checkbox'; |
| 238 | - $this->addHidden($label,array('value'=>'0')); |
|
| 239 | - $html = $this->CreateInput($label,$attributes); |
|
| 238 | + $this->addHidden($label, array('value'=>'0')); |
|
| 239 | + $html = $this->CreateInput($label, $attributes); |
|
| 240 | 240 | } |
| 241 | 241 | else |
| 242 | 242 | { |
| 243 | - if(isset($attributes['value'])) |
|
| 243 | + if (isset($attributes['value'])) |
|
| 244 | 244 | { |
| 245 | - if(!is_array($attributes['value'])) $attributes['value'] = array($attributes['value']); |
|
| 245 | + if (!is_array($attributes['value'])) $attributes['value'] = array($attributes['value']); |
|
| 246 | 246 | } |
| 247 | 247 | else |
| 248 | 248 | $attributes['value'] = []; |
| 249 | - if(substr($attributes['name'], -2) !== '[]') |
|
| 249 | + if (substr($attributes['name'], -2) !== '[]') |
|
| 250 | 250 | $attributes['name'] .= '[]'; |
| 251 | 251 | $count = 0; |
| 252 | - $html = $this->InsertLabel($label,array('for'=>$attributes['id'])); |
|
| 253 | - foreach($options as $value => $text) |
|
| 252 | + $html = $this->InsertLabel($label, array('for'=>$attributes['id'])); |
|
| 253 | + foreach ($options as $value => $text) |
|
| 254 | 254 | { |
| 255 | 255 | $html .= '<label for="'.$attributes['id'].'-'.$count.'">'; |
| 256 | 256 | $html .= '<input id="'.$attributes['id'].'-'.$count.'"'; |
| 257 | 257 | $html .= ' value="'.$value.'"'; |
| 258 | - $html .= $this->BuildAttributes($attributes,array('id', 'value', 'checked', 'required')); |
|
| 259 | - if(in_array($value, $attributes['value'])) $html .= ' checked="checked"'; |
|
| 258 | + $html .= $this->BuildAttributes($attributes, array('id', 'value', 'checked', 'required')); |
|
| 259 | + if (in_array($value, $attributes['value'])) $html .= ' checked="checked"'; |
|
| 260 | 260 | $html .= ' >'.$text.'</label>'; |
| 261 | 261 | ++$count; |
| 262 | 262 | } |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | * @param array $attributes |
| 269 | 269 | * @return mixed |
| 270 | 270 | */ |
| 271 | - public function addCountry($label,$attributes=[]) |
|
| 271 | + public function addCountry($label, $attributes = []) |
|
| 272 | 272 | { |
| 273 | - $default = array('placeholder'=>'Choose a Country...','required'=>'required'); |
|
| 274 | - $attributes = array_merge($default,$attributes); |
|
| 273 | + $default = array('placeholder'=>'Choose a Country...', 'required'=>'required'); |
|
| 274 | + $attributes = array_merge($default, $attributes); |
|
| 275 | 275 | $Dataset = new WorldCountriesDatas(); |
| 276 | - return $this->addSelect($label,$Dataset->getAllCountriesCodeAndName(),$attributes); |
|
| 276 | + return $this->addSelect($label, $Dataset->getAllCountriesCodeAndName(), $attributes); |
|
| 277 | 277 | } |
| 278 | 278 | /** |
| 279 | 279 | * @param $label |
| 280 | 280 | * @param array $attributes |
| 281 | 281 | * @return PhpFormBuilder |
| 282 | 282 | */ |
| 283 | - public function addDate($label,$attributes=[]){ |
|
| 283 | + public function addDate($label, $attributes = []) { |
|
| 284 | 284 | // $attributes['pattern'] = '\d{4}-\d{2}-\d{2}'; |
| 285 | 285 | // $attributes['placeholder'] = 'YYYY-dd-MM (e.g. ' . date('Y-m-d') . ')'; |
| 286 | 286 | $attributes['type'] = 'date'; |
| 287 | 287 | $attributes['title'] = $attributes['placeholder']; |
| 288 | - $html = $this->CreateInput($label,$attributes); |
|
| 288 | + $html = $this->CreateInput($label, $attributes); |
|
| 289 | 289 | return $this->Save($html); |
| 290 | 290 | } |
| 291 | 291 | |
@@ -294,10 +294,10 @@ discard block |
||
| 294 | 294 | * @param array $attributes |
| 295 | 295 | * @return PhpFormBuilder |
| 296 | 296 | */ |
| 297 | - public function addDatetime($label,$attributes=[]){ |
|
| 297 | + public function addDatetime($label, $attributes = []) { |
|
| 298 | 298 | $attributes['type'] = 'datetime'; |
| 299 | - $attributes['placeholder'] = 'YYYY-dd-MM H:i:s(e.g. ' . date('Y-m-d H:i:s') . ')'; |
|
| 300 | - $html = $this->CreateInput($label,$attributes); |
|
| 299 | + $attributes['placeholder'] = 'YYYY-dd-MM H:i:s(e.g. '.date('Y-m-d H:i:s').')'; |
|
| 300 | + $html = $this->CreateInput($label, $attributes); |
|
| 301 | 301 | return $this->Save($html); |
| 302 | 302 | } |
| 303 | 303 | |
@@ -306,9 +306,9 @@ discard block |
||
| 306 | 306 | * @param array $attributes |
| 307 | 307 | * @return PhpFormBuilder |
| 308 | 308 | */ |
| 309 | - public function addDatetimeLocal($label,$attributes=[]){ |
|
| 309 | + public function addDatetimeLocal($label, $attributes = []) { |
|
| 310 | 310 | $attributes['type'] = 'datetime-local'; |
| 311 | - $html = $this->CreateInput($label,$attributes); |
|
| 311 | + $html = $this->CreateInput($label, $attributes); |
|
| 312 | 312 | return $this->Save($html); |
| 313 | 313 | } |
| 314 | 314 | |
@@ -317,10 +317,10 @@ discard block |
||
| 317 | 317 | * @param array $attributes |
| 318 | 318 | * @return PhpFormBuilder |
| 319 | 319 | */ |
| 320 | - public function addEmail($label,$attributes=[]){ |
|
| 320 | + public function addEmail($label, $attributes = []) { |
|
| 321 | 321 | $attributes['type'] = 'email'; |
| 322 | 322 | $attributes['required'] = 'required'; |
| 323 | - $html = $this->CreateInput($label,$attributes); |
|
| 323 | + $html = $this->CreateInput($label, $attributes); |
|
| 324 | 324 | return $this->Save($html); |
| 325 | 325 | } |
| 326 | 326 | |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * @param array $attributes |
| 330 | 330 | * @return PhpFormBuilder |
| 331 | 331 | */ |
| 332 | - public function addFile($label,$attributes=[]){ |
|
| 332 | + public function addFile($label, $attributes = []) { |
|
| 333 | 333 | $attributes['type'] = 'file'; |
| 334 | - $html = $this->CreateInput($label,$attributes); |
|
| 334 | + $html = $this->CreateInput($label, $attributes); |
|
| 335 | 335 | return $this->Save($html); |
| 336 | 336 | } |
| 337 | 337 | |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | * @param array $attributes |
| 341 | 341 | * @return PhpFormBuilder |
| 342 | 342 | */ |
| 343 | - public function addHidden($label,$attributes=[]){ |
|
| 343 | + public function addHidden($label, $attributes = []) { |
|
| 344 | 344 | $attributes['type'] = 'hidden'; |
| 345 | - $html = $this->CreateInput($label,$attributes); |
|
| 345 | + $html = $this->CreateInput($label, $attributes); |
|
| 346 | 346 | return $this->Save($html); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -351,10 +351,10 @@ discard block |
||
| 351 | 351 | * @param array $attributes |
| 352 | 352 | * @return PhpFormBuilder |
| 353 | 353 | */ |
| 354 | - public function addImage($label,$attributes=[]){ |
|
| 355 | - $attributes['accept']='image/*'; |
|
| 354 | + public function addImage($label, $attributes = []) { |
|
| 355 | + $attributes['accept'] = 'image/*'; |
|
| 356 | 356 | // $attributes['accept']='image/*;capture=camera'; |
| 357 | - return $this->addFile($label,$attributes); |
|
| 357 | + return $this->addFile($label, $attributes); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | * @param array $attributes |
| 363 | 363 | * @return PhpFormBuilder |
| 364 | 364 | */ |
| 365 | - public function addMonth($label,$attributes=[]){ |
|
| 365 | + public function addMonth($label, $attributes = []) { |
|
| 366 | 366 | $attributes['type'] = 'month'; |
| 367 | 367 | $attributes['pattern'] = '\d{4}-\d{2}'; |
| 368 | - $attributes['placeholder'] = 'YYYY-MM (e.g. ' . date('Y-m') . ')'; |
|
| 368 | + $attributes['placeholder'] = 'YYYY-MM (e.g. '.date('Y-m').')'; |
|
| 369 | 369 | $attributes['title'] = $attributes['placeholder']; |
| 370 | - $html = $this->CreateInput($label,$attributes); |
|
| 370 | + $html = $this->CreateInput($label, $attributes); |
|
| 371 | 371 | return $this->Save($html); |
| 372 | 372 | } |
| 373 | 373 | |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @param array $attributes |
| 377 | 377 | * @return PhpFormBuilder |
| 378 | 378 | */ |
| 379 | - public function addNumber($label,$attributes=[]){ |
|
| 380 | - $default = array('min'=>'0','max'=>'100','step'=>'1'); |
|
| 381 | - $attributes = array_merge($default,$attributes); |
|
| 379 | + public function addNumber($label, $attributes = []) { |
|
| 380 | + $default = array('min'=>'0', 'max'=>'100', 'step'=>'1'); |
|
| 381 | + $attributes = array_merge($default, $attributes); |
|
| 382 | 382 | $attributes['type'] = 'number'; |
| 383 | - $html = $this->CreateInput($label,$attributes); |
|
| 383 | + $html = $this->CreateInput($label, $attributes); |
|
| 384 | 384 | return $this->Save($html); |
| 385 | 385 | } |
| 386 | 386 | |
@@ -389,11 +389,11 @@ discard block |
||
| 389 | 389 | * @param array $attributes |
| 390 | 390 | * @return PhpFormBuilder |
| 391 | 391 | */ |
| 392 | - public function addPassword($label,$attributes=[]){ |
|
| 393 | - $default = array('placeholder'=>'**********','minlength'=>'6','maxlength'=>'25','required'=>'required'); |
|
| 394 | - $attributes = array_merge($default,$attributes); |
|
| 392 | + public function addPassword($label, $attributes = []) { |
|
| 393 | + $default = array('placeholder'=>'**********', 'minlength'=>'6', 'maxlength'=>'25', 'required'=>'required'); |
|
| 394 | + $attributes = array_merge($default, $attributes); |
|
| 395 | 395 | $attributes['type'] = 'password'; |
| 396 | - $html = $this->CreateInput($label,$attributes); |
|
| 396 | + $html = $this->CreateInput($label, $attributes); |
|
| 397 | 397 | return $this->Save($html); |
| 398 | 398 | } |
| 399 | 399 | |
@@ -402,9 +402,9 @@ discard block |
||
| 402 | 402 | * @param array $attributes |
| 403 | 403 | * @return PhpFormBuilder |
| 404 | 404 | */ |
| 405 | - public function addPhone($label,$attributes=[]){ |
|
| 405 | + public function addPhone($label, $attributes = []) { |
|
| 406 | 406 | $attributes['type'] = 'tel'; |
| 407 | - $html = $this->CreateInput($label,$attributes); |
|
| 407 | + $html = $this->CreateInput($label, $attributes); |
|
| 408 | 408 | return $this->Save($html); |
| 409 | 409 | } |
| 410 | 410 | |
@@ -414,9 +414,9 @@ discard block |
||
| 414 | 414 | * @param array $attributes |
| 415 | 415 | * @return PhpFormBuilder |
| 416 | 416 | */ |
| 417 | - public function addRadio($label,$options=[],$attributes=[]){ |
|
| 417 | + public function addRadio($label, $options = [], $attributes = []) { |
|
| 418 | 418 | $attributes['type'] = 'radio'; |
| 419 | - return $this->addCheckbox($label,$options,$attributes); |
|
| 419 | + return $this->addCheckbox($label, $options, $attributes); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -424,11 +424,11 @@ discard block |
||
| 424 | 424 | * @param array $attributes |
| 425 | 425 | * @return PhpFormBuilder |
| 426 | 426 | */ |
| 427 | - public function addRange($label,$attributes=[]){ |
|
| 428 | - $default = array('min'=>'0','max'=>'100','step'=>'1'); |
|
| 429 | - $attributes = array_merge($default,$attributes); |
|
| 427 | + public function addRange($label, $attributes = []) { |
|
| 428 | + $default = array('min'=>'0', 'max'=>'100', 'step'=>'1'); |
|
| 429 | + $attributes = array_merge($default, $attributes); |
|
| 430 | 430 | $attributes['type'] = 'range'; |
| 431 | - $html = $this->CreateInput($label,$attributes); |
|
| 431 | + $html = $this->CreateInput($label, $attributes); |
|
| 432 | 432 | return $this->Save($html); |
| 433 | 433 | } |
| 434 | 434 | |
@@ -437,10 +437,10 @@ discard block |
||
| 437 | 437 | * @param array $attributes |
| 438 | 438 | * @return PhpFormBuilder |
| 439 | 439 | */ |
| 440 | - public function addReset($label,$attributes=[]){ |
|
| 440 | + public function addReset($label, $attributes = []) { |
|
| 441 | 441 | $attributes['type'] = 'reset'; |
| 442 | - $attributes['value'] = $attributes['value']?:$label; |
|
| 443 | - $html = $this->CreateInput($label,$attributes); |
|
| 442 | + $attributes['value'] = $attributes['value'] ?: $label; |
|
| 443 | + $html = $this->CreateInput($label, $attributes); |
|
| 444 | 444 | return $this->Save($html); |
| 445 | 445 | } |
| 446 | 446 | |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | * @param array $attributes |
| 450 | 450 | * @return PhpFormBuilder |
| 451 | 451 | */ |
| 452 | - public function addSearch($label,$attributes=[]){ |
|
| 452 | + public function addSearch($label, $attributes = []) { |
|
| 453 | 453 | $attributes['type'] = 'search'; |
| 454 | 454 | $attributes['required'] = 'required'; |
| 455 | - $html = $this->CreateInput($label,$attributes); |
|
| 455 | + $html = $this->CreateInput($label, $attributes); |
|
| 456 | 456 | return $this->Save($html); |
| 457 | 457 | } |
| 458 | 458 | |
@@ -462,8 +462,8 @@ discard block |
||
| 462 | 462 | * @param array $attributes |
| 463 | 463 | * @return PhpFormBuilder |
| 464 | 464 | */ |
| 465 | - public function addSelect($label,$options=[],$attributes=[]){ |
|
| 466 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 465 | + public function addSelect($label, $options = [], $attributes = []) { |
|
| 466 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 467 | 467 | $this->OptionResolver->setDefaults([ |
| 468 | 468 | 'value'=>$this->getDefaultValue($label), |
| 469 | 469 | 'id'=>'input'.$this->normalize($label), |
@@ -471,48 +471,48 @@ discard block |
||
| 471 | 471 | 'type'=>'select', |
| 472 | 472 | 'placeholder'=>'Make a Choise...' |
| 473 | 473 | ]); |
| 474 | - $this->OptionResolver->addAllowedValues('type','select'); |
|
| 475 | - $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'select')); |
|
| 476 | - $multiple=false; |
|
| 477 | - if(strpos($attributes['id'],'input')!==0) |
|
| 474 | + $this->OptionResolver->addAllowedValues('type', 'select'); |
|
| 475 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, 'select')); |
|
| 476 | + $multiple = false; |
|
| 477 | + if (strpos($attributes['id'], 'input') !== 0) |
|
| 478 | 478 | $attributes['id'] = $this->normalize($attributes['id']); |
| 479 | - if($attributes['value']) |
|
| 479 | + if ($attributes['value']) |
|
| 480 | 480 | { |
| 481 | - if(!is_array($attributes['value'])) |
|
| 481 | + if (!is_array($attributes['value'])) |
|
| 482 | 482 | $attributes['value'] = array($attributes['value']); |
| 483 | 483 | } |
| 484 | 484 | else |
| 485 | 485 | $attributes['value'] = []; |
| 486 | - if(isset($attributes['multiple']) and ($attributes['multiple']==='multiple')) |
|
| 487 | - $multiple=true; |
|
| 488 | - if($multiple) |
|
| 489 | - { $attributes['size']= $attributes['size']?:3; |
|
| 490 | - if(substr($attributes['name'], -2) !== '[]') |
|
| 486 | + if (isset($attributes['multiple']) and ($attributes['multiple'] === 'multiple')) |
|
| 487 | + $multiple = true; |
|
| 488 | + if ($multiple) |
|
| 489 | + { $attributes['size'] = $attributes['size'] ?: 3; |
|
| 490 | + if (substr($attributes['name'], -2) !== '[]') |
|
| 491 | 491 | $attributes['name'] .= '[]'; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - $html = $this->InsertLabel($label,array('for'=>$attributes['id'])); |
|
| 495 | - $html .= '<select'.$this->BuildAttributes($attributes,array('value','selected','optgroup-attributes','option-attributes','placeholder')).'>'; |
|
| 496 | - if(!$attributes['value'] and isset($attributes['placeholder'])) |
|
| 494 | + $html = $this->InsertLabel($label, array('for'=>$attributes['id'])); |
|
| 495 | + $html .= '<select'.$this->BuildAttributes($attributes, array('value', 'selected', 'optgroup-attributes', 'option-attributes', 'placeholder')).'>'; |
|
| 496 | + if (!$attributes['value'] and isset($attributes['placeholder'])) |
|
| 497 | 497 | { |
| 498 | 498 | $html .= '<option value="" disabled selected>'.$attributes['placeholder'].'</option>'; |
| 499 | 499 | unset($attributes['placeholder']); |
| 500 | 500 | } |
| 501 | 501 | $selected = false; |
| 502 | - foreach($options as $OptionValue=>$OptionLabel): |
|
| 502 | + foreach ($options as $OptionValue=>$OptionLabel): |
|
| 503 | 503 | |
| 504 | - if(is_array($OptionLabel)) |
|
| 504 | + if (is_array($OptionLabel)) |
|
| 505 | 505 | { |
| 506 | - $html .= call_user_func_array($OptGroupHtml = function($groupName,$groupOptions) use (&$OptGroupHtml,&$attributes,&$selected) |
|
| 506 | + $html .= call_user_func_array($OptGroupHtml = function($groupName, $groupOptions) use (&$OptGroupHtml, &$attributes, &$selected) |
|
| 507 | 507 | { |
| 508 | - $output='<optgroup label="'.$groupName.'">'; |
|
| 509 | - foreach($groupOptions as $key=>$optLabel) |
|
| 508 | + $output = '<optgroup label="'.$groupName.'">'; |
|
| 509 | + foreach ($groupOptions as $key=>$optLabel) |
|
| 510 | 510 | { |
| 511 | - if(is_array($optLabel))$output .= $OptGroupHtml($key,$optLabel); |
|
| 511 | + if (is_array($optLabel))$output .= $OptGroupHtml($key, $optLabel); |
|
| 512 | 512 | else |
| 513 | 513 | { |
| 514 | 514 | $output .= '<option value="'.$key.'"'; |
| 515 | - if(!$selected and in_array($key,$attributes['value'])) |
|
| 515 | + if (!$selected and in_array($key, $attributes['value'])) |
|
| 516 | 516 | { |
| 517 | 517 | $output .= ' selected="selected"'; |
| 518 | 518 | $selected = true; |
@@ -521,14 +521,14 @@ discard block |
||
| 521 | 521 | $output .= $optLabel.'</option>'; |
| 522 | 522 | } |
| 523 | 523 | } |
| 524 | - $output.='</optgroup>'; |
|
| 524 | + $output .= '</optgroup>'; |
|
| 525 | 525 | return$output; |
| 526 | - },[$OptionValue,$OptionLabel]); |
|
| 526 | + },[$OptionValue, $OptionLabel]); |
|
| 527 | 527 | } |
| 528 | 528 | else |
| 529 | 529 | { |
| 530 | 530 | $html .= '<option value="'.$OptionValue.'"'; |
| 531 | - if(!$selected and in_array($OptionValue,$attributes['value'])) |
|
| 531 | + if (!$selected and in_array($OptionValue, $attributes['value'])) |
|
| 532 | 532 | { |
| 533 | 533 | $html .= ' selected="selected"'; |
| 534 | 534 | $selected = true; |
@@ -546,11 +546,11 @@ discard block |
||
| 546 | 546 | * @param array $attributes |
| 547 | 547 | * @return PhpFormBuilder |
| 548 | 548 | */ |
| 549 | - public function addSubmit($label,$attributes=[]){ |
|
| 550 | - $this->addHidden('token',array('value'=>sha1(session_id()))); |
|
| 549 | + public function addSubmit($label, $attributes = []) { |
|
| 550 | + $this->addHidden('token', array('value'=>sha1(session_id()))); |
|
| 551 | 551 | $attributes['type'] = 'submit'; |
| 552 | - $attributes['value'] = $attributes['value']?:$label; |
|
| 553 | - $html = $this->CreateInput($label,$attributes); |
|
| 552 | + $attributes['value'] = $attributes['value'] ?: $label; |
|
| 553 | + $html = $this->CreateInput($label, $attributes); |
|
| 554 | 554 | return $this->Save($html); |
| 555 | 555 | } |
| 556 | 556 | |
@@ -559,9 +559,9 @@ discard block |
||
| 559 | 559 | * @param array $attributes |
| 560 | 560 | * @return PhpFormBuilder |
| 561 | 561 | */ |
| 562 | - public function addText($label,$attributes=[]){ |
|
| 562 | + public function addText($label, $attributes = []) { |
|
| 563 | 563 | $attributes['type'] = 'text'; |
| 564 | - $html = $this->CreateInput($label,$attributes); |
|
| 564 | + $html = $this->CreateInput($label, $attributes); |
|
| 565 | 565 | return $this->Save($html); |
| 566 | 566 | } |
| 567 | 567 | |
@@ -570,8 +570,8 @@ discard block |
||
| 570 | 570 | * @param array $attributes |
| 571 | 571 | * @return PhpFormBuilder |
| 572 | 572 | */ |
| 573 | - public function addTextarea($label,$attributes=[]){ |
|
| 574 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 573 | + public function addTextarea($label, $attributes = []) { |
|
| 574 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 575 | 575 | $this->OptionResolver->setDefaults([ |
| 576 | 576 | 'id'=>'input'.$this->normalize($label), |
| 577 | 577 | 'autocomplete'=>'off', |
@@ -580,11 +580,11 @@ discard block |
||
| 580 | 580 | 'value' => $this->getDefaultValue($label), |
| 581 | 581 | 'name' => $this->normalize($label) |
| 582 | 582 | ]); |
| 583 | - $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'textarea')); |
|
| 584 | - if(strpos($attributes['id'],'input')!==0) |
|
| 583 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, 'textarea')); |
|
| 584 | + if (strpos($attributes['id'], 'input') !== 0) |
|
| 585 | 585 | $attributes['id'] = $this->normalize($attributes['id']); |
| 586 | - $html = $this->InsertLabel($label,array('for'=>$attributes['id'])); |
|
| 587 | - $html .= '<textarea'. $this->BuildAttributes($attributes,array('value')).'>'; |
|
| 586 | + $html = $this->InsertLabel($label, array('for'=>$attributes['id'])); |
|
| 587 | + $html .= '<textarea'.$this->BuildAttributes($attributes, array('value')).'>'; |
|
| 588 | 588 | $html .= $attributes['value']; |
| 589 | 589 | $html .= '</textarea>'; |
| 590 | 590 | return $this->Save($html); |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @param array $attributes |
| 596 | 596 | * @return PhpFormBuilder |
| 597 | 597 | */ |
| 598 | - public function addTextEditor($label,$attributes=[]) |
|
| 598 | + public function addTextEditor($label, $attributes = []) |
|
| 599 | 599 | { |
| 600 | 600 | $attributes['class'] = 'editor'; |
| 601 | 601 | return $this->addTextarea($label, $attributes); |
@@ -606,9 +606,9 @@ discard block |
||
| 606 | 606 | * @param array $attributes |
| 607 | 607 | * @return PhpFormBuilder |
| 608 | 608 | */ |
| 609 | - public function addTime($label,$attributes=[]){ |
|
| 609 | + public function addTime($label, $attributes = []) { |
|
| 610 | 610 | $attributes['type'] = 'time'; |
| 611 | - $html = $this->CreateInput($label,$attributes); |
|
| 611 | + $html = $this->CreateInput($label, $attributes); |
|
| 612 | 612 | return $this->Save($html); |
| 613 | 613 | } |
| 614 | 614 | |
@@ -617,9 +617,9 @@ discard block |
||
| 617 | 617 | * @param array $attributes |
| 618 | 618 | * @return PhpFormBuilder |
| 619 | 619 | */ |
| 620 | - public function addUrl($label,$attributes=[]){ |
|
| 620 | + public function addUrl($label, $attributes = []) { |
|
| 621 | 621 | $attributes['type'] = 'url'; |
| 622 | - $html = $this->CreateInput($label,$attributes); |
|
| 622 | + $html = $this->CreateInput($label, $attributes); |
|
| 623 | 623 | return $this->Save($html); |
| 624 | 624 | } |
| 625 | 625 | |
@@ -628,10 +628,10 @@ discard block |
||
| 628 | 628 | * @param array $attributes |
| 629 | 629 | * @return PhpFormBuilder |
| 630 | 630 | */ |
| 631 | - public function addVideo($label,$attributes=[]){ |
|
| 631 | + public function addVideo($label, $attributes = []) { |
|
| 632 | 632 | //$attributes['accept']='video/*;capture=camcorder'; |
| 633 | - $attributes['accept']='video/*'; |
|
| 634 | - return $this->addFile($label,$attributes); |
|
| 633 | + $attributes['accept'] = 'video/*'; |
|
| 634 | + return $this->addFile($label, $attributes); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -639,9 +639,9 @@ discard block |
||
| 639 | 639 | * @param array $attributes |
| 640 | 640 | * @return PhpFormBuilder |
| 641 | 641 | */ |
| 642 | - public function addWeek($label,$attributes=[]){ |
|
| 642 | + public function addWeek($label, $attributes = []) { |
|
| 643 | 643 | $attributes['type'] = 'week'; |
| 644 | - $html = $this->CreateInput($label,$attributes); |
|
| 644 | + $html = $this->CreateInput($label, $attributes); |
|
| 645 | 645 | return $this->Save($html); |
| 646 | 646 | } |
| 647 | 647 | |
@@ -650,12 +650,12 @@ discard block |
||
| 650 | 650 | * @param array $attributes |
| 651 | 651 | * @return PhpFormBuilder |
| 652 | 652 | */ |
| 653 | - public function addYesNo($label,$attributes=[]){ |
|
| 653 | + public function addYesNo($label, $attributes = []) { |
|
| 654 | 654 | $options = array( |
| 655 | 655 | '1' => 'Yes', |
| 656 | 656 | '0' => 'No' |
| 657 | 657 | ); |
| 658 | - return $this->addRadio($label,$options,$attributes); |
|
| 658 | + return $this->addRadio($label, $options, $attributes); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /* PRIVATES METHODS */ |
@@ -664,25 +664,25 @@ discard block |
||
| 664 | 664 | * @param null $ignore |
| 665 | 665 | * @return bool|null|string |
| 666 | 666 | */ |
| 667 | - private function BuildAttributes($attributes,$ignore = null){ |
|
| 668 | - if(!$attributes) return false; |
|
| 667 | + private function BuildAttributes($attributes, $ignore = null) { |
|
| 668 | + if (!$attributes) return false; |
|
| 669 | 669 | is_array($attributes) or $attributes = array($attributes); |
| 670 | 670 | $filtered = array_keys($attributes); |
| 671 | - if($ignore) |
|
| 671 | + if ($ignore) |
|
| 672 | 672 | { |
| 673 | 673 | if (!is_array($ignore)) $ignore = array($ignore); |
| 674 | 674 | $filtered = array_diff($filtered, $ignore); |
| 675 | 675 | } |
| 676 | 676 | $output = null; |
| 677 | - foreach($attributes as $key=>$value) |
|
| 677 | + foreach ($attributes as $key=>$value) |
|
| 678 | 678 | { |
| 679 | - if(!in_array($key,$filtered)) continue; |
|
| 679 | + if (!in_array($key, $filtered)) continue; |
|
| 680 | 680 | $output .= ' '; |
| 681 | 681 | $key = $this->normalize($key); |
| 682 | - if(is_array($value)): |
|
| 683 | - $output .= $key.'="'.implode(' ',array_values($value)).'"'; |
|
| 682 | + if (is_array($value)): |
|
| 683 | + $output .= $key.'="'.implode(' ', array_values($value)).'"'; |
|
| 684 | 684 | else: |
| 685 | - if(is_numeric($key)) $output .= $value; |
|
| 685 | + if (is_numeric($key)) $output .= $value; |
|
| 686 | 686 | else $output .= $key.'="'.$value.'"'; |
| 687 | 687 | endif; |
| 688 | 688 | } |
@@ -694,16 +694,16 @@ discard block |
||
| 694 | 694 | * @param array $attributes |
| 695 | 695 | * @return bool|string |
| 696 | 696 | */ |
| 697 | - private function CreateInput($label,$attributes=[]){ |
|
| 698 | - $attributes = array_change_key_case($attributes,CASE_LOWER); |
|
| 697 | + private function CreateInput($label, $attributes = []) { |
|
| 698 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 699 | 699 | $this->OptionResolver->setDefaults([ |
| 700 | 700 | 'value' => $this->getDefaultValue($label), |
| 701 | 701 | 'type' => 'text', |
| 702 | - 'id' => 'input' . $this->normalize($label), |
|
| 702 | + 'id' => 'input'.$this->normalize($label), |
|
| 703 | 703 | 'autocomplete' => 'off', |
| 704 | 704 | 'name' => $this->normalize($label) |
| 705 | 705 | ]); |
| 706 | - $this->OptionResolver->setAllowedValues('type',[ |
|
| 706 | + $this->OptionResolver->setAllowedValues('type', [ |
|
| 707 | 707 | 'button', |
| 708 | 708 | 'checkbox', |
| 709 | 709 | 'color', |
@@ -727,12 +727,12 @@ discard block |
||
| 727 | 727 | 'time', |
| 728 | 728 | 'url', |
| 729 | 729 | 'week']); |
| 730 | - $type = $attributes['type']?:'text'; |
|
| 731 | - $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,$type)); |
|
| 732 | - $notLabeled = array('hidden','submit','reset','button'); |
|
| 733 | - if(strpos($attributes['id'],'input')!==0) |
|
| 730 | + $type = $attributes['type'] ?: 'text'; |
|
| 731 | + $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes, $type)); |
|
| 732 | + $notLabeled = array('hidden', 'submit', 'reset', 'button'); |
|
| 733 | + if (strpos($attributes['id'], 'input') !== 0) |
|
| 734 | 734 | $attributes['id'] = $this->normalize($attributes['id']); |
| 735 | - $html = !in_array($attributes['type'],$notLabeled)?$this->InsertLabel($label,array('for'=>$attributes['id'])):''; |
|
| 735 | + $html = !in_array($attributes['type'], $notLabeled) ? $this->InsertLabel($label, array('for'=>$attributes['id'])) : ''; |
|
| 736 | 736 | $html .= '<input'; |
| 737 | 737 | $html .= $this->BuildAttributes($attributes); |
| 738 | 738 | $html .= ' >'; |
@@ -752,8 +752,8 @@ discard block |
||
| 752 | 752 | if (!$errorMsg) return ''; |
| 753 | 753 | if (is_array($errorMsg)) |
| 754 | 754 | { |
| 755 | - $html=''; |
|
| 756 | - foreach ($errorMsg as $error){ |
|
| 755 | + $html = ''; |
|
| 756 | + foreach ($errorMsg as $error) { |
|
| 757 | 757 | $html .= '<li class="hint"><span class="error">'; |
| 758 | 758 | $html .= $error; |
| 759 | 759 | $html .= '</span></li>'; |
@@ -773,10 +773,10 @@ discard block |
||
| 773 | 773 | * @param string $element |
| 774 | 774 | * @return array |
| 775 | 775 | */ |
| 776 | - private function FilterAttributes($attributes,$element='text'){ |
|
| 777 | - is_array($attributes) or $attributes=[$attributes]; |
|
| 778 | - $attributes=array_change_key_case($attributes,CASE_LOWER); |
|
| 779 | - $AcceptedAttributes = array_merge($this->AllowedEvents,$this->GlobalAttributes); |
|
| 776 | + private function FilterAttributes($attributes, $element = 'text') { |
|
| 777 | + is_array($attributes) or $attributes = [$attributes]; |
|
| 778 | + $attributes = array_change_key_case($attributes, CASE_LOWER); |
|
| 779 | + $AcceptedAttributes = array_merge($this->AllowedEvents, $this->GlobalAttributes); |
|
| 780 | 780 | $element = strtolower($element); |
| 781 | 781 | switch ($element): |
| 782 | 782 | case 'date': |
@@ -786,75 +786,75 @@ discard block |
||
| 786 | 786 | case 'number': |
| 787 | 787 | case 'time': |
| 788 | 788 | case 'week': |
| 789 | - if($element === 'number') $AcceptedAttributes[]='placeholder'; |
|
| 790 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['date']); |
|
| 789 | + if ($element === 'number') $AcceptedAttributes[] = 'placeholder'; |
|
| 790 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['date']); |
|
| 791 | 791 | break; |
| 792 | 792 | case 'color': |
| 793 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['color']); |
|
| 793 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['color']); |
|
| 794 | 794 | break; |
| 795 | 795 | case 'file': |
| 796 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['file']); |
|
| 796 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['file']); |
|
| 797 | 797 | break; |
| 798 | 798 | case 'image': |
| 799 | 799 | case 'video': |
| 800 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['image']); |
|
| 800 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['image']); |
|
| 801 | 801 | break; |
| 802 | 802 | case 'radio': |
| 803 | 803 | case 'checkbox': |
| 804 | - $tmpAttributesList=$this->AllowedAttributes['checkbox']; |
|
| 805 | - if($element === 'radio') |
|
| 804 | + $tmpAttributesList = $this->AllowedAttributes['checkbox']; |
|
| 805 | + if ($element === 'radio') |
|
| 806 | 806 | { |
| 807 | - $bannedIndex=array_search('indeterminate', $tmpAttributesList,true); |
|
| 808 | - if(isset($tmpAttributesList[$bannedIndex]))unset($tmpAttributesList[$bannedIndex]); |
|
| 807 | + $bannedIndex = array_search('indeterminate', $tmpAttributesList, true); |
|
| 808 | + if (isset($tmpAttributesList[$bannedIndex]))unset($tmpAttributesList[$bannedIndex]); |
|
| 809 | 809 | } |
| 810 | - $AcceptedAttributes = array_merge($AcceptedAttributes,array_values($tmpAttributesList)); |
|
| 810 | + $AcceptedAttributes = array_merge($AcceptedAttributes, array_values($tmpAttributesList)); |
|
| 811 | 811 | break; |
| 812 | 812 | |
| 813 | 813 | case 'submit': |
| 814 | 814 | case 'button': |
| 815 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['button']); |
|
| 815 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['button']); |
|
| 816 | 816 | break; |
| 817 | 817 | |
| 818 | 818 | case 'reset': |
| 819 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['reset']); |
|
| 819 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['reset']); |
|
| 820 | 820 | break; |
| 821 | 821 | case 'range': |
| 822 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['range']); |
|
| 822 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['range']); |
|
| 823 | 823 | break; |
| 824 | 824 | case 'textarea': |
| 825 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['textarea']); |
|
| 825 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['textarea']); |
|
| 826 | 826 | break; |
| 827 | 827 | case 'option': |
| 828 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['option']); |
|
| 828 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['option']); |
|
| 829 | 829 | break; |
| 830 | 830 | case 'label': |
| 831 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['label']); |
|
| 831 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['label']); |
|
| 832 | 832 | break; |
| 833 | 833 | case 'select': |
| 834 | - $AcceptedAttributes[]='placeholder'; |
|
| 835 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['select']); |
|
| 834 | + $AcceptedAttributes[] = 'placeholder'; |
|
| 835 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['select']); |
|
| 836 | 836 | break; |
| 837 | 837 | case 'form': |
| 838 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['form']); |
|
| 838 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['form']); |
|
| 839 | 839 | break; |
| 840 | 840 | case 'fieldset': |
| 841 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['fieldset']); |
|
| 841 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['fieldset']); |
|
| 842 | 842 | break; |
| 843 | 843 | case 'hidden': |
| 844 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['hidden']); |
|
| 844 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['hidden']); |
|
| 845 | 845 | break; |
| 846 | 846 | default: |
| 847 | - if($element === 'email') $AcceptedAttributes[]='multiple'; |
|
| 848 | - $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['text']); |
|
| 847 | + if ($element === 'email') $AcceptedAttributes[] = 'multiple'; |
|
| 848 | + $AcceptedAttributes = array_merge($AcceptedAttributes, $this->AllowedAttributes['text']); |
|
| 849 | 849 | break; |
| 850 | 850 | endswitch; |
| 851 | 851 | $AcceptedAttributes = array_unique($AcceptedAttributes); |
| 852 | - $attributesKeys=array_keys($attributes); |
|
| 852 | + $attributesKeys = array_keys($attributes); |
|
| 853 | 853 | foreach ($attributesKeys as $attribute): |
| 854 | - !is_numeric($attribute) or $attribute=$attributes[$attribute]; |
|
| 855 | - if(!in_array($attribute,$AcceptedAttributes)){ |
|
| 856 | - if(substr($attribute,0,5)!=='data-') |
|
| 857 | - $AcceptedAttributes[] +=$attribute; |
|
| 854 | + !is_numeric($attribute) or $attribute = $attributes[$attribute]; |
|
| 855 | + if (!in_array($attribute, $AcceptedAttributes)) { |
|
| 856 | + if (substr($attribute, 0, 5) !== 'data-') |
|
| 857 | + $AcceptedAttributes[] += $attribute; |
|
| 858 | 858 | else |
| 859 | 859 | unset($attributes[$attribute]); |
| 860 | 860 | } |
@@ -867,11 +867,11 @@ discard block |
||
| 867 | 867 | * @param $label |
| 868 | 868 | * @return bool|string |
| 869 | 869 | */ |
| 870 | - private function getDefaultValue($label){ |
|
| 871 | - if(!$label) return false; |
|
| 870 | + private function getDefaultValue($label) { |
|
| 871 | + if (!$label) return false; |
|
| 872 | 872 | $label = $this->normalize($label); |
| 873 | - $request = strcasecmp($this->RequestMethod,'get')==0 ? $_GET : $_POST; |
|
| 874 | - if(!$value = $request[$label]) return ''; |
|
| 873 | + $request = strcasecmp($this->RequestMethod, 'get') == 0 ? $_GET : $_POST; |
|
| 874 | + if (!$value = $request[$label]) return ''; |
|
| 875 | 875 | return $value; |
| 876 | 876 | } |
| 877 | 877 | |
@@ -880,9 +880,9 @@ discard block |
||
| 880 | 880 | * @param array $attributes |
| 881 | 881 | * @return bool|string |
| 882 | 882 | */ |
| 883 | - private function InsertLabel($label,$attributes=[]){ |
|
| 884 | - if(!$label or is_array($label)) return false; |
|
| 885 | - $labelAttributes = $this->FilterAttributes($attributes,'label'); |
|
| 883 | + private function InsertLabel($label, $attributes = []) { |
|
| 884 | + if (!$label or is_array($label)) return false; |
|
| 885 | + $labelAttributes = $this->FilterAttributes($attributes, 'label'); |
|
| 886 | 886 | $html = '<label'.$this->BuildAttributes($labelAttributes).'>'; |
| 887 | 887 | $html .= $label; |
| 888 | 888 | $html .= $this->DisplayError($label); |
@@ -895,11 +895,11 @@ discard block |
||
| 895 | 895 | */ |
| 896 | 896 | private function normalize($keys) |
| 897 | 897 | { |
| 898 | - if(is_array($keys)) return false; |
|
| 899 | - foreach (array(' ', ' ', '\n', '\t', '\r', '"','\'','_') as $strip) |
|
| 898 | + if (is_array($keys)) return false; |
|
| 899 | + foreach (array(' ', ' ', '\n', '\t', '\r', '"', '\'', '_') as $strip) |
|
| 900 | 900 | $keys = str_replace($strip, '', (string) $keys); |
| 901 | 901 | $keys = trim(preg_replace('/\W+/', '-', $keys), '-'); |
| 902 | - $keys = strtolower(str_ireplace('input','',$keys)); |
|
| 902 | + $keys = strtolower(str_ireplace('input', '', $keys)); |
|
| 903 | 903 | return $keys; |
| 904 | 904 | } |
| 905 | 905 | |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | private function Save($html) |
| 911 | 911 | { |
| 912 | 912 | print_r($html); |
| 913 | - return strcasecmp($html,'</form>') !== 0? $this: null; |
|
| 913 | + return strcasecmp($html, '</form>') !== 0 ? $this : null; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | public function __construct($method = 'post'){ |
| 45 | 45 | try{ |
| 46 | 46 | $method = strtolower(trim($method)); |
| 47 | - if(!in_array($method,['get','post'],true)) |
|
| 48 | - $method = $_SERVER['REQUEST_METHOD']; |
|
| 47 | + if(!in_array($method,['get','post'],true)) { |
|
| 48 | + $method = $_SERVER['REQUEST_METHOD']; |
|
| 49 | + } |
|
| 49 | 50 | $this->RequestMethod = $method; |
| 50 | 51 | $this->OptionResolver= new PhpOptionsResolver(); |
| 51 | 52 | return $this; |
| 52 | - } |
|
| 53 | - catch(\Exception $e){echo $e->getMessage();} |
|
| 53 | + } catch(\Exception $e){echo $e->getMessage();} |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | /* COMMON METHODS */ |
@@ -74,7 +74,9 @@ discard block |
||
| 74 | 74 | $this->OptionResolver->addAllowedTypes('action','string'); |
| 75 | 75 | $this->OptionResolver->addAllowedTypes('name','string'); |
| 76 | 76 | $attributes=$this->OptionResolver->resolve($this->FilterAttributes($attributes,'form')); |
| 77 | - if(strcasecmp($attributes['method'],'get') == 0) unset($attributes['enctype']); |
|
| 77 | + if(strcasecmp($attributes['method'],'get') == 0) { |
|
| 78 | + unset($attributes['enctype']); |
|
| 79 | + } |
|
| 78 | 80 | $html = '<form'; |
| 79 | 81 | $html .= $this->BuildAttributes($attributes); |
| 80 | 82 | $html .= '>'; |
@@ -100,8 +102,9 @@ discard block |
||
| 100 | 102 | ]); |
| 101 | 103 | $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'fieldset')); |
| 102 | 104 | $html ='<fieldset'; |
| 103 | - if($attributes) |
|
| 104 | - $html.= $this->BuildAttributes($attributes,array('legend','label','id','legend-attributes')); |
|
| 105 | + if($attributes) { |
|
| 106 | + $html.= $this->BuildAttributes($attributes,array('legend','label','id','legend-attributes')); |
|
| 107 | + } |
|
| 105 | 108 | $html .= ' >'; |
| 106 | 109 | if(isset($attributes['legend'])) |
| 107 | 110 | { |
@@ -227,8 +230,9 @@ discard block |
||
| 227 | 230 | $this->OptionResolver->addAllowedValues('type',['radio','checkbox']); |
| 228 | 231 | $type = $attributes['type']?:'checkbox'; |
| 229 | 232 | $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,$type)); |
| 230 | - if(strpos($attributes['id'],'input')!==0) |
|
| 231 | - $attributes['id'] = $this->normalize($attributes['id']); |
|
| 233 | + if(strpos($attributes['id'],'input')!==0) { |
|
| 234 | + $attributes['id'] = $this->normalize($attributes['id']); |
|
| 235 | + } |
|
| 232 | 236 | |
| 233 | 237 | if(sizeof($options)<2) |
| 234 | 238 | { |
@@ -237,17 +241,19 @@ discard block |
||
| 237 | 241 | $attributes['type'] = 'checkbox'; |
| 238 | 242 | $this->addHidden($label,array('value'=>'0')); |
| 239 | 243 | $html = $this->CreateInput($label,$attributes); |
| 240 | - } |
|
| 241 | - else |
|
| 244 | + } else |
|
| 242 | 245 | { |
| 243 | 246 | if(isset($attributes['value'])) |
| 244 | 247 | { |
| 245 | - if(!is_array($attributes['value'])) $attributes['value'] = array($attributes['value']); |
|
| 248 | + if(!is_array($attributes['value'])) { |
|
| 249 | + $attributes['value'] = array($attributes['value']); |
|
| 250 | + } |
|
| 251 | + } else { |
|
| 252 | + $attributes['value'] = []; |
|
| 253 | + } |
|
| 254 | + if(substr($attributes['name'], -2) !== '[]') { |
|
| 255 | + $attributes['name'] .= '[]'; |
|
| 246 | 256 | } |
| 247 | - else |
|
| 248 | - $attributes['value'] = []; |
|
| 249 | - if(substr($attributes['name'], -2) !== '[]') |
|
| 250 | - $attributes['name'] .= '[]'; |
|
| 251 | 257 | $count = 0; |
| 252 | 258 | $html = $this->InsertLabel($label,array('for'=>$attributes['id'])); |
| 253 | 259 | foreach($options as $value => $text) |
@@ -256,7 +262,9 @@ discard block |
||
| 256 | 262 | $html .= '<input id="'.$attributes['id'].'-'.$count.'"'; |
| 257 | 263 | $html .= ' value="'.$value.'"'; |
| 258 | 264 | $html .= $this->BuildAttributes($attributes,array('id', 'value', 'checked', 'required')); |
| 259 | - if(in_array($value, $attributes['value'])) $html .= ' checked="checked"'; |
|
| 265 | + if(in_array($value, $attributes['value'])) { |
|
| 266 | + $html .= ' checked="checked"'; |
|
| 267 | + } |
|
| 260 | 268 | $html .= ' >'.$text.'</label>'; |
| 261 | 269 | ++$count; |
| 262 | 270 | } |
@@ -474,21 +482,25 @@ discard block |
||
| 474 | 482 | $this->OptionResolver->addAllowedValues('type','select'); |
| 475 | 483 | $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'select')); |
| 476 | 484 | $multiple=false; |
| 477 | - if(strpos($attributes['id'],'input')!==0) |
|
| 478 | - $attributes['id'] = $this->normalize($attributes['id']); |
|
| 485 | + if(strpos($attributes['id'],'input')!==0) { |
|
| 486 | + $attributes['id'] = $this->normalize($attributes['id']); |
|
| 487 | + } |
|
| 479 | 488 | if($attributes['value']) |
| 480 | 489 | { |
| 481 | - if(!is_array($attributes['value'])) |
|
| 482 | - $attributes['value'] = array($attributes['value']); |
|
| 490 | + if(!is_array($attributes['value'])) { |
|
| 491 | + $attributes['value'] = array($attributes['value']); |
|
| 492 | + } |
|
| 493 | + } else { |
|
| 494 | + $attributes['value'] = []; |
|
| 495 | + } |
|
| 496 | + if(isset($attributes['multiple']) and ($attributes['multiple']==='multiple')) { |
|
| 497 | + $multiple=true; |
|
| 483 | 498 | } |
| 484 | - else |
|
| 485 | - $attributes['value'] = []; |
|
| 486 | - if(isset($attributes['multiple']) and ($attributes['multiple']==='multiple')) |
|
| 487 | - $multiple=true; |
|
| 488 | 499 | if($multiple) |
| 489 | 500 | { $attributes['size']= $attributes['size']?:3; |
| 490 | - if(substr($attributes['name'], -2) !== '[]') |
|
| 491 | - $attributes['name'] .= '[]'; |
|
| 501 | + if(substr($attributes['name'], -2) !== '[]') { |
|
| 502 | + $attributes['name'] .= '[]'; |
|
| 503 | + } |
|
| 492 | 504 | } |
| 493 | 505 | |
| 494 | 506 | $html = $this->InsertLabel($label,array('for'=>$attributes['id'])); |
@@ -508,8 +520,9 @@ discard block |
||
| 508 | 520 | $output='<optgroup label="'.$groupName.'">'; |
| 509 | 521 | foreach($groupOptions as $key=>$optLabel) |
| 510 | 522 | { |
| 511 | - if(is_array($optLabel))$output .= $OptGroupHtml($key,$optLabel); |
|
| 512 | - else |
|
| 523 | + if(is_array($optLabel)) { |
|
| 524 | + $output .= $OptGroupHtml($key,$optLabel); |
|
| 525 | + } else |
|
| 513 | 526 | { |
| 514 | 527 | $output .= '<option value="'.$key.'"'; |
| 515 | 528 | if(!$selected and in_array($key,$attributes['value'])) |
@@ -524,8 +537,7 @@ discard block |
||
| 524 | 537 | $output.='</optgroup>'; |
| 525 | 538 | return$output; |
| 526 | 539 | },[$OptionValue,$OptionLabel]); |
| 527 | - } |
|
| 528 | - else |
|
| 540 | + } else |
|
| 529 | 541 | { |
| 530 | 542 | $html .= '<option value="'.$OptionValue.'"'; |
| 531 | 543 | if(!$selected and in_array($OptionValue,$attributes['value'])) |
@@ -581,8 +593,9 @@ discard block |
||
| 581 | 593 | 'name' => $this->normalize($label) |
| 582 | 594 | ]); |
| 583 | 595 | $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,'textarea')); |
| 584 | - if(strpos($attributes['id'],'input')!==0) |
|
| 585 | - $attributes['id'] = $this->normalize($attributes['id']); |
|
| 596 | + if(strpos($attributes['id'],'input')!==0) { |
|
| 597 | + $attributes['id'] = $this->normalize($attributes['id']); |
|
| 598 | + } |
|
| 586 | 599 | $html = $this->InsertLabel($label,array('for'=>$attributes['id'])); |
| 587 | 600 | $html .= '<textarea'. $this->BuildAttributes($attributes,array('value')).'>'; |
| 588 | 601 | $html .= $attributes['value']; |
@@ -665,25 +678,35 @@ discard block |
||
| 665 | 678 | * @return bool|null|string |
| 666 | 679 | */ |
| 667 | 680 | private function BuildAttributes($attributes,$ignore = null){ |
| 668 | - if(!$attributes) return false; |
|
| 681 | + if(!$attributes) { |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 669 | 684 | is_array($attributes) or $attributes = array($attributes); |
| 670 | 685 | $filtered = array_keys($attributes); |
| 671 | 686 | if($ignore) |
| 672 | 687 | { |
| 673 | - if (!is_array($ignore)) $ignore = array($ignore); |
|
| 688 | + if (!is_array($ignore)) { |
|
| 689 | + $ignore = array($ignore); |
|
| 690 | + } |
|
| 674 | 691 | $filtered = array_diff($filtered, $ignore); |
| 675 | 692 | } |
| 676 | 693 | $output = null; |
| 677 | 694 | foreach($attributes as $key=>$value) |
| 678 | 695 | { |
| 679 | - if(!in_array($key,$filtered)) continue; |
|
| 696 | + if(!in_array($key,$filtered)) { |
|
| 697 | + continue; |
|
| 698 | + } |
|
| 680 | 699 | $output .= ' '; |
| 681 | 700 | $key = $this->normalize($key); |
| 682 | 701 | if(is_array($value)): |
| 683 | 702 | $output .= $key.'="'.implode(' ',array_values($value)).'"'; |
| 684 | - else: |
|
| 703 | + else { |
|
| 704 | + : |
|
| 685 | 705 | if(is_numeric($key)) $output .= $value; |
| 686 | - else $output .= $key.'="'.$value.'"'; |
|
| 706 | + } |
|
| 707 | + else { |
|
| 708 | + $output .= $key.'="'.$value.'"'; |
|
| 709 | + } |
|
| 687 | 710 | endif; |
| 688 | 711 | } |
| 689 | 712 | return $output; |
@@ -730,8 +753,9 @@ discard block |
||
| 730 | 753 | $type = $attributes['type']?:'text'; |
| 731 | 754 | $attributes = $this->OptionResolver->resolve($this->FilterAttributes($attributes,$type)); |
| 732 | 755 | $notLabeled = array('hidden','submit','reset','button'); |
| 733 | - if(strpos($attributes['id'],'input')!==0) |
|
| 734 | - $attributes['id'] = $this->normalize($attributes['id']); |
|
| 756 | + if(strpos($attributes['id'],'input')!==0) { |
|
| 757 | + $attributes['id'] = $this->normalize($attributes['id']); |
|
| 758 | + } |
|
| 735 | 759 | $html = !in_array($attributes['type'],$notLabeled)?$this->InsertLabel($label,array('for'=>$attributes['id'])):''; |
| 736 | 760 | $html .= '<input'; |
| 737 | 761 | $html .= $this->BuildAttributes($attributes); |
@@ -745,11 +769,15 @@ discard block |
||
| 745 | 769 | */ |
| 746 | 770 | private function DisplayError($label) |
| 747 | 771 | { |
| 748 | - if (!$label) return false; |
|
| 772 | + if (!$label) { |
|
| 773 | + return false; |
|
| 774 | + } |
|
| 749 | 775 | $label = $this->normalize($label); |
| 750 | 776 | $errorMsg = null; |
| 751 | 777 | !isset($this->ValidationErrors[$label]) OR $errorMsg = $this->ValidationErrors[$label]; |
| 752 | - if (!$errorMsg) return ''; |
|
| 778 | + if (!$errorMsg) { |
|
| 779 | + return ''; |
|
| 780 | + } |
|
| 753 | 781 | if (is_array($errorMsg)) |
| 754 | 782 | { |
| 755 | 783 | $html=''; |
@@ -758,8 +786,7 @@ discard block |
||
| 758 | 786 | $html .= $error; |
| 759 | 787 | $html .= '</span></li>'; |
| 760 | 788 | } |
| 761 | - } |
|
| 762 | - else |
|
| 789 | + } else |
|
| 763 | 790 | { |
| 764 | 791 | $html = '<li class="hint"><span class="error">'; |
| 765 | 792 | $html .= $errorMsg; |
@@ -786,7 +813,9 @@ discard block |
||
| 786 | 813 | case 'number': |
| 787 | 814 | case 'time': |
| 788 | 815 | case 'week': |
| 789 | - if($element === 'number') $AcceptedAttributes[]='placeholder'; |
|
| 816 | + if($element === 'number') { |
|
| 817 | + $AcceptedAttributes[]='placeholder'; |
|
| 818 | + } |
|
| 790 | 819 | $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['date']); |
| 791 | 820 | break; |
| 792 | 821 | case 'color': |
@@ -805,7 +834,9 @@ discard block |
||
| 805 | 834 | if($element === 'radio') |
| 806 | 835 | { |
| 807 | 836 | $bannedIndex=array_search('indeterminate', $tmpAttributesList,true); |
| 808 | - if(isset($tmpAttributesList[$bannedIndex]))unset($tmpAttributesList[$bannedIndex]); |
|
| 837 | + if(isset($tmpAttributesList[$bannedIndex])) { |
|
| 838 | + unset($tmpAttributesList[$bannedIndex]); |
|
| 839 | + } |
|
| 809 | 840 | } |
| 810 | 841 | $AcceptedAttributes = array_merge($AcceptedAttributes,array_values($tmpAttributesList)); |
| 811 | 842 | break; |
@@ -844,7 +875,9 @@ discard block |
||
| 844 | 875 | $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['hidden']); |
| 845 | 876 | break; |
| 846 | 877 | default: |
| 847 | - if($element === 'email') $AcceptedAttributes[]='multiple'; |
|
| 878 | + if($element === 'email') { |
|
| 879 | + $AcceptedAttributes[]='multiple'; |
|
| 880 | + } |
|
| 848 | 881 | $AcceptedAttributes = array_merge($AcceptedAttributes,$this->AllowedAttributes['text']); |
| 849 | 882 | break; |
| 850 | 883 | endswitch; |
@@ -853,10 +886,11 @@ discard block |
||
| 853 | 886 | foreach ($attributesKeys as $attribute): |
| 854 | 887 | !is_numeric($attribute) or $attribute=$attributes[$attribute]; |
| 855 | 888 | if(!in_array($attribute,$AcceptedAttributes)){ |
| 856 | - if(substr($attribute,0,5)!=='data-') |
|
| 857 | - $AcceptedAttributes[] +=$attribute; |
|
| 858 | - else |
|
| 859 | - unset($attributes[$attribute]); |
|
| 889 | + if(substr($attribute,0,5)!=='data-') { |
|
| 890 | + $AcceptedAttributes[] +=$attribute; |
|
| 891 | + } else { |
|
| 892 | + unset($attributes[$attribute]); |
|
| 893 | + } |
|
| 860 | 894 | } |
| 861 | 895 | |
| 862 | 896 | endforeach; |
@@ -868,10 +902,14 @@ discard block |
||
| 868 | 902 | * @return bool|string |
| 869 | 903 | */ |
| 870 | 904 | private function getDefaultValue($label){ |
| 871 | - if(!$label) return false; |
|
| 905 | + if(!$label) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 872 | 908 | $label = $this->normalize($label); |
| 873 | 909 | $request = strcasecmp($this->RequestMethod,'get')==0 ? $_GET : $_POST; |
| 874 | - if(!$value = $request[$label]) return ''; |
|
| 910 | + if(!$value = $request[$label]) { |
|
| 911 | + return ''; |
|
| 912 | + } |
|
| 875 | 913 | return $value; |
| 876 | 914 | } |
| 877 | 915 | |
@@ -881,7 +919,9 @@ discard block |
||
| 881 | 919 | * @return bool|string |
| 882 | 920 | */ |
| 883 | 921 | private function InsertLabel($label,$attributes=[]){ |
| 884 | - if(!$label or is_array($label)) return false; |
|
| 922 | + if(!$label or is_array($label)) { |
|
| 923 | + return false; |
|
| 924 | + } |
|
| 885 | 925 | $labelAttributes = $this->FilterAttributes($attributes,'label'); |
| 886 | 926 | $html = '<label'.$this->BuildAttributes($labelAttributes).'>'; |
| 887 | 927 | $html .= $label; |
@@ -895,9 +935,12 @@ discard block |
||
| 895 | 935 | */ |
| 896 | 936 | private function normalize($keys) |
| 897 | 937 | { |
| 898 | - if(is_array($keys)) return false; |
|
| 899 | - foreach (array(' ', ' ', '\n', '\t', '\r', '"','\'','_') as $strip) |
|
| 900 | - $keys = str_replace($strip, '', (string) $keys); |
|
| 938 | + if(is_array($keys)) { |
|
| 939 | + return false; |
|
| 940 | + } |
|
| 941 | + foreach (array(' ', ' ', '\n', '\t', '\r', '"','\'','_') as $strip) { |
|
| 942 | + $keys = str_replace($strip, '', (string) $keys); |
|
| 943 | + } |
|
| 901 | 944 | $keys = trim(preg_replace('/\W+/', '-', $keys), '-'); |
| 902 | 945 | $keys = strtolower(str_ireplace('input','',$keys)); |
| 903 | 946 | return $keys; |