1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ngtfkx\Laradeck\FormBuilder\Elements; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Ngtfkx\Laradeck\FormBuilder\Layouts\AbstractLayout; |
7
|
|
|
|
8
|
|
|
class Form extends AbstractElement |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string URL для отправки данных формы |
12
|
|
|
*/ |
13
|
|
|
protected $action = ''; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string Метод отправки данных формы |
17
|
|
|
*/ |
18
|
|
|
protected $method = 'get'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var bool Признак включения/отключения автозаполнения полей формы |
22
|
|
|
*/ |
23
|
|
|
protected $autocomplete; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var bool Признак включения/откючения автовалидации перед отправкой данных |
27
|
|
|
*/ |
28
|
|
|
protected $novalidate; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string В каком окне открывать результат обработки формы |
32
|
|
|
*/ |
33
|
|
|
protected $target; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string Тип кодировки данных при отправке |
37
|
|
|
*/ |
38
|
|
|
protected $enctype; |
39
|
|
|
|
40
|
|
|
protected $onlyTagRender = true; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Form constructor. |
44
|
|
|
* @param AbstractLayout $layout |
45
|
|
|
*/ |
46
|
|
|
public function __construct(?AbstractLayout $layout = null) |
47
|
|
|
{ |
48
|
|
|
parent::__construct(); |
49
|
|
|
|
50
|
|
|
$this->layout = $layout; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string|null $value |
55
|
|
|
* @return Form |
56
|
|
|
*/ |
57
|
|
|
public function action(?string $value = ''): Form |
58
|
|
|
{ |
59
|
|
|
$this->action = $value; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string|null $value |
66
|
|
|
* @return Form |
67
|
|
|
*/ |
68
|
|
|
public function method(?string $value): Form |
69
|
|
|
{ |
70
|
|
|
$this->method = $value; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Сеттер для установки типа кодировки данных при отправке |
77
|
|
|
* |
78
|
|
|
* @param string $value |
79
|
|
|
* @return Form |
80
|
|
|
*/ |
81
|
|
|
protected function enctype(string $value): Form |
82
|
|
|
{ |
83
|
|
|
$this->enctype = $value; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Сеттер для установки указания в каком окнеоткрывать результат работы |
90
|
|
|
* |
91
|
|
|
* @param string|null $value |
92
|
|
|
* @return Form |
93
|
|
|
*/ |
94
|
|
|
public function target(?string $value): Form |
95
|
|
|
{ |
96
|
|
|
$this->target = $value; |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Установить тип отправки данных multipart/form-data |
103
|
|
|
* |
104
|
|
|
* @return Form |
105
|
|
|
*/ |
106
|
|
|
public function multipart(): Form |
107
|
|
|
{ |
108
|
|
|
return $this->enctype('multipart/form-data'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Установить тип отправки данных text/plain |
113
|
|
|
* |
114
|
|
|
* @return Form |
115
|
|
|
*/ |
116
|
|
|
public function plain(): Form |
117
|
|
|
{ |
118
|
|
|
return $this->enctype('text/plain'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Установить тип отправки данных application/x-www-form-urlencoded |
123
|
|
|
* |
124
|
|
|
* @return Form |
125
|
|
|
*/ |
126
|
|
|
public function urlencoded(): Form |
127
|
|
|
{ |
128
|
|
|
return $this->enctype('application/x-www-form-urlencoded'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Сеттер для установки признака включения/отключения автозаполнения полей формы |
133
|
|
|
* |
134
|
|
|
* @param bool|null $state |
135
|
|
|
* @return Form |
136
|
|
|
*/ |
137
|
|
|
public function autocomplete(?bool $state = true): Form |
138
|
|
|
{ |
139
|
|
|
$this->autocomplete = $state; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Сеттер для установки признака включения/отключения автовалидации перед отправкой данных |
146
|
|
|
* |
147
|
|
|
* @param bool|null $state |
148
|
|
|
* @return Form |
149
|
|
|
*/ |
150
|
|
|
public function novalidate(?bool $state = true): Form |
151
|
|
|
{ |
152
|
|
|
$this->novalidate = $state; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function tag(): void |
158
|
|
|
{ |
159
|
|
|
$this->tag = 'form'; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
protected function beforeToParts(): void |
163
|
|
|
{ |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function __toString(): string |
168
|
|
|
{ |
169
|
|
|
if ($this->layout) { |
170
|
|
|
$this->class($this->layout->getFormClasses()); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->attrs([ |
|
|
|
|
174
|
|
|
'action' => $this->action, |
175
|
|
|
'method' => $this->method, |
176
|
|
|
'target' => $this->target, |
177
|
|
|
'enctype' => $this->enctype, |
178
|
|
|
'autocomplete' => $this->autocomplete, |
179
|
|
|
'novalidate' => $this->novalidate, |
180
|
|
|
]); |
181
|
|
|
|
182
|
|
|
return parent::__toString(); |
183
|
|
|
} |
184
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: