Skip to content

Commit f07fc04

Browse files
committed
Solving issue #50
1 parent b59d4e2 commit f07fc04

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/FormBuilder.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function open(): string
283283
if ($this->_Fmethod !== 'get') {
284284
$ret .= csrf_field();
285285

286-
if ($this->_Fmethod !== 'post') {
286+
if ($this->_Fmethod !== 'post' && $this->_Fmethod !== 'get') {
287287
$ret .= method_field($this->_Fmethod);
288288
}
289289
}
@@ -649,20 +649,32 @@ private function _getLabel(): string
649649
*/
650650
private function _buildAttrs(array $props = [], array $ignore = []): string
651651
{
652+
$props = array_merge(array_filter($this->_attrs, function($k){
653+
return $k != 'class';
654+
}, ARRAY_FILTER_USE_KEY), $props);
652655

653-
$props['type'] = $this->_type;
654-
$props['name'] = $this->_name;
656+
if($this->_type){
657+
$props['type'] = $this->_type;
658+
}
659+
660+
if($this->_name){
661+
$props['name'] = $this->_name;
662+
}
655663

656664
if (!is_null($this->_autocomplete)) {
657665
$props['autocomplete'] = $this->_autocomplete;
658-
} else if (isset($this->_allowedAutoComplete[$props['name']])) {
659-
$props['autocomplete'] = $props['name'];
666+
} else if ($this->_name && isset($this->_allowedAutoComplete[$this->_name])) {
667+
$props['autocomplete'] = $this->_name;
668+
}
669+
670+
$id = $this->_getId();
671+
if($id){
672+
$props['id'] = $this->_getId();
660673
}
661674

662-
$props['id'] = $this->_getId();
663675
$props['class'] = isset($props['class']) ? $props['class'] : '';
664676

665-
if ($this->_type == 'select' && $this->_multiple) {
677+
if ($this->_type == 'select' && $this->_multiple && $this->_name) {
666678
$props['name'] = $props['name'] . '[]';
667679
}
668680

0 commit comments

Comments
 (0)