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
|
|
|
/** |
41
|
|
|
* @var AbstractLayout |
42
|
|
|
*/ |
43
|
|
|
protected $layout; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Form constructor. |
47
|
|
|
* @param AbstractLayout $layout |
48
|
|
|
*/ |
49
|
|
|
public function __construct(?AbstractLayout $layout = null) |
50
|
|
|
{ |
51
|
|
|
parent::__construct(); |
52
|
|
|
|
53
|
|
|
$this->layout = $layout; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string|null $value |
58
|
|
|
* @return Form |
59
|
|
|
*/ |
60
|
|
|
public function action(?string $value = ''): Form |
61
|
|
|
{ |
62
|
|
|
$this->action = $value; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string|null $value |
69
|
|
|
* @return Form |
70
|
|
|
*/ |
71
|
|
|
public function method(?string $value): Form |
72
|
|
|
{ |
73
|
|
|
$this->method = $value; |
74
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Сеттер для установки типа кодировки данных при отправке |
80
|
|
|
* |
81
|
|
|
* @param string $value |
82
|
|
|
* @return Form |
83
|
|
|
*/ |
84
|
|
|
protected function enctype(string $value): Form |
85
|
|
|
{ |
86
|
|
|
$this->enctype = $value; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Сеттер для установки указания в каком окнеоткрывать результат работы |
93
|
|
|
* |
94
|
|
|
* @param string|null $value |
95
|
|
|
* @return Form |
96
|
|
|
*/ |
97
|
|
|
public function target(?string $value): Form |
98
|
|
|
{ |
99
|
|
|
$this->target = $value; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Установить тип отправки данных multipart/form-data |
106
|
|
|
* |
107
|
|
|
* @return Form |
108
|
|
|
*/ |
109
|
|
|
public function multipart(): Form |
110
|
|
|
{ |
111
|
|
|
return $this->enctype('multipart/form-data'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Установить тип отправки данных text/plain |
116
|
|
|
* |
117
|
|
|
* @return Form |
118
|
|
|
*/ |
119
|
|
|
public function plain(): Form |
120
|
|
|
{ |
121
|
|
|
return $this->enctype('text/plain'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Установить тип отправки данных application/x-www-form-urlencoded |
126
|
|
|
* |
127
|
|
|
* @return Form |
128
|
|
|
*/ |
129
|
|
|
public function urlencoded(): Form |
130
|
|
|
{ |
131
|
|
|
return $this->enctype('application/x-www-form-urlencoded'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Сеттер для установки признака включения/отключения автозаполнения полей формы |
136
|
|
|
* |
137
|
|
|
* @param bool|null $state |
138
|
|
|
* @return Form |
139
|
|
|
*/ |
140
|
|
|
public function autocomplete(?bool $state = true): Form |
141
|
|
|
{ |
142
|
|
|
$this->autocomplete = $state; |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Сеттер для установки признака включения/отключения автовалидации перед отправкой данных |
149
|
|
|
* |
150
|
|
|
* @param bool|null $state |
151
|
|
|
* @return Form |
152
|
|
|
*/ |
153
|
|
|
public function novalidate(?bool $state = true): Form |
154
|
|
|
{ |
155
|
|
|
$this->novalidate = $state; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function tag(): void |
161
|
|
|
{ |
162
|
|
|
$this->tag = 'form'; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function __toString(): string |
166
|
|
|
{ |
167
|
|
|
if ($this->layout) { |
168
|
|
|
$this->class($this->layout->getFormClasses()); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$this->attrs([ |
|
|
|
|
172
|
|
|
'action' => $this->action, |
173
|
|
|
'method' => $this->method, |
174
|
|
|
'target' => $this->target, |
175
|
|
|
'enctype' => $this->enctype, |
176
|
|
|
'autocomplete' => $this->autocomplete, |
177
|
|
|
'novalidate' => $this->novalidate, |
178
|
|
|
]); |
179
|
|
|
|
180
|
|
|
return parent::__toString(); |
181
|
|
|
} |
182
|
|
|
} |
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: