Skip to content

Commit c7cea8e

Browse files
committed
WIP
1 parent 876c7e4 commit c7cea8e

File tree

1 file changed

+101
-102
lines changed

1 file changed

+101
-102
lines changed

src/Form/Handler.php

Lines changed: 101 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -4,221 +4,220 @@
44

55
use HTTPFriend\Tags\Tag as Tag;
66

7-
class Handler {
7+
class Handler
8+
{
89

910
public $subittedData;
1011
public $files;
1112

12-
public function __construct(){
13+
public function __construct()
14+
{
1315
$this->tag = new Tag;
1416
}
1517

16-
public function open( $formSettings = [] ){
18+
public function open($formSettings = [])
19+
{
1720

18-
if( !isset( $formSettings["method"] ) )
19-
{
21+
if (!isset($formSettings["method"])) {
2022
$attributes["method"] = "POST";
21-
}
22-
else{
23-
$attributes["method"] = trim( $formSettings["method"] );
23+
} else {
24+
$attributes["method"] = trim($formSettings["method"]);
2425
}
2526

26-
if( isset( $formSettings["action"] ) ) {
27+
if (isset($formSettings["action"])) {
2728
$attributes["action"] = $formSettings["action"];
28-
}
29-
else {
29+
} else {
3030
$attributes["action"] = "./";
3131
}
3232

3333
$formname = "http-friend-name-";
3434

35-
if( isset( $formSettings["controller"] ) && isset( $formSettings["method"] ) )
36-
{
35+
if (isset($formSettings["controller"]) && isset($formSettings["method"])) {
3736
$formname .= "-{$formSettings["controller"]}-{$formSettings["method"]}";
3837
}
3938

4039
$formname .= "-{$this->formcount}";
4140

42-
if( isset( $_POST[$formname] ) ){
41+
if (isset($_POST[$formname])) {
4342

4443
$this->processFormSubmission();
4544
}
4645

4746
ob_start();
48-
$this->tag->output([ "tag" => "form", "attr" => $attributes ] );
47+
$this->tag->output(["tag" => "form", "attr" => $attributes]);
4948

5049

5150

52-
$this->tag->output([ "tag" => "input", "attr" => [ "type" => "hidden", "name" => "http-friend-name" ] ] );
51+
$this->tag->output(["tag" => "input", "attr" => ["type" => "hidden", "name" => "http-friend-name"]]);
5352
echo ob_get_clean();
5453
return $this;
5554
}
5655

57-
public function close(){
58-
$this->tag->output( [ "tag" => "form", "close" => true ] );
56+
public function close()
57+
{
58+
$this->tag->output(["tag" => "form", "close" => true]);
5959
}
6060

6161

6262
public function processFormSubmission()
6363
{
6464

65-
}
65+
}
6666

67-
public function text( $attr = [], $options = [] )
67+
public function text($attr = [], $options = [])
6868
{
69-
$attr["type"] = strtolower( __METHOD__ );
70-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
69+
$attr["type"] = strtolower("text");
70+
$this->tag->output(["tag" => "input", "attr" => $attr]);
7171
}
7272

73-
public function phone( $attr = [], $options = [] )
73+
public function phone($attr = [], $options = [])
7474
{
75-
$attr["type"] = strtolower( __METHOD__ );
76-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
75+
$attr["type"] = strtolower("phone");
76+
$this->tag->output(["tag" => "input", "attr" => $attr]);
7777
}
7878

79-
public function email( $attr = [], $options = [] )
79+
public function email($attr = [], $options = [])
8080
{
81-
$attr["type"] = strtolower( __METHOD__ );
82-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
81+
$attr["type"] = strtolower("email");
82+
$this->tag->output(["tag" => "input", "attr" => $attr]);
8383
}
8484

85-
public function number( $attr = [], $options = [] )
85+
public function number($attr = [], $options = [])
8686
{
87-
$attr["type"] = strtolower( __METHOD__ );
88-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
87+
$attr["type"] = strtolower("number");
88+
$this->tag->output(["tag" => "input", "attr" => $attr]);
8989
}
90-
91-
public function button( $attr = [], $options = [] )
90+
91+
public function button($attr = [], $options = [])
9292
{
93-
$attr["type"] = strtolower( __METHOD__ );
94-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
95-
}
93+
$attr["type"] = strtolower("button");
94+
$this->tag->output(["tag" => "input", "attr" => $attr]);
95+
}
9696

97-
public function password( $attr = [], $options = [] )
97+
public function password($attr = [], $options = [])
9898
{
99-
$attr["type"] = strtolower( __METHOD__ );
100-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
99+
$attr["type"] = strtolower("password");
100+
$this->tag->output(["tag" => "input", "attr" => $attr]);
101101
}
102-
public function hidden( $attr = [], $options = [] )
102+
public function hidden($attr = [], $options = [])
103103
{
104-
$attr["type"] = strtolower( __METHOD__ );
105-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
106-
}
104+
$attr["type"] = strtolower("hidden");
105+
$this->tag->output(["tag" => "input", "attr" => $attr]);
106+
}
107107

108-
public function checkbox( $attr = [], $options = [] )
108+
public function checkbox($attr = [], $options = [])
109109
{
110-
$attr["type"] = strtolower( __METHOD__ );
111-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
110+
$attr["type"] = strtolower("checkbox");
111+
$this->tag->output(["tag" => "input", "attr" => $attr]);
112112
}
113113

114-
public function radio( $attr = [], $options = [] )
114+
public function radio($attr = [], $options = [])
115115
{
116-
$attr["type"] = strtolower( __METHOD__ );
117-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
116+
$attr["type"] = strtolower("radio");
117+
$this->tag->output(["tag" => "input", "attr" => $attr]);
118118
}
119119

120-
public function file( $attr = [], $options = [] )
120+
public function file($attr = [], $options = [])
121121
{
122-
$attr["type"] = strtolower( __METHOD__ );
123-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
122+
$attr["type"] = strtolower("file");
123+
$this->tag->output(["tag" => "input", "attr" => $attr]);
124124
}
125125

126-
public function image( $attr = [], $options = [] )
126+
public function image($attr = [], $options = [])
127127
{
128-
$attr["type"] = strtolower( __METHOD__ );
129-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
128+
$attr["type"] = strtolower("image");
129+
$this->tag->output(["tag" => "input", "attr" => $attr]);
130130
}
131131

132-
public function color( $attr = [], $options = [] )
132+
public function color($attr = [], $options = [])
133133
{
134-
$attr["type"] = strtolower( __METHOD__ );
135-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
134+
$attr["type"] = strtolower("color");
135+
$this->tag->output(["tag" => "input", "attr" => $attr]);
136136
}
137137

138-
public function date( $attr = [], $options = [] )
138+
public function date($attr = [], $options = [])
139139
{
140-
$attr["type"] = strtolower( __METHOD__ );
141-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
140+
$attr["type"] = strtolower("date");
141+
$this->tag->output(["tag" => "input", "attr" => $attr]);
142142
}
143143

144-
public function datetimeLocal( $attr = [], $options = [] )
144+
public function datetimeLocal($attr = [], $options = [])
145145
{
146-
$attr["type"] = strtolower( str_replace( "L", "-l", __METHOD__) );
147-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
146+
$attr["type"] = strtolower("datetime-local");
147+
$this->tag->output(["tag" => "input", "attr" => $attr]);
148148
}
149149

150-
public function month( $attr = [], $options = [] )
150+
public function month($attr = [], $options = [])
151151
{
152-
$attr["type"] = strtolower( __METHOD__ );
153-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
152+
$attr["type"] = strtolower("month");
153+
$this->tag->output(["tag" => "input", "attr" => $attr]);
154154
}
155155

156-
public function range( $attr = [], $options = [] )
156+
public function range($attr = [], $options = [])
157157
{
158-
$attr["type"] = strtolower( __METHOD__ );
159-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
160-
}
158+
$attr["type"] = strtolower("range");
159+
$this->tag->output(["tag" => "input", "attr" => $attr]);
160+
}
161161

162-
public function reset( $attr = [], $options = [] )
162+
public function reset($attr = [], $options = [])
163163
{
164-
$attr["type"] = strtolower( __METHOD__ );
165-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
164+
$attr["type"] = strtolower("reset");
165+
$this->tag->output(["tag" => "input", "attr" => $attr]);
166166
}
167167

168-
public function search( $attr = [], $options = [] )
168+
public function search($attr = [], $options = [])
169169
{
170-
$attr["type"] = strtolower( __METHOD__ );
171-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
170+
$attr["type"] = strtolower("search");
171+
$this->tag->output(["tag" => "input", "attr" => $attr]);
172172
}
173173

174-
public function tel( $attr = [], $options = [] )
174+
public function tel($attr = [], $options = [])
175175
{
176-
$attr["type"] = strtolower( __METHOD__ );
177-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
176+
$attr["type"] = strtolower("tel");
177+
$this->tag->output(["tag" => "input", "attr" => $attr]);
178178
}
179179

180-
public function url( $attr = [], $options = [] )
180+
public function url($attr = [], $options = [])
181181
{
182-
$attr["type"] = strtolower( __METHOD__ );
183-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
182+
$attr["type"] = strtolower("url");
183+
$this->tag->output(["tag" => "input", "attr" => $attr]);
184184
}
185185

186-
public function week( $attr = [], $options = [] )
186+
public function week($attr = [], $options = [])
187187
{
188-
$attr["type"] = strtolower( __METHOD__ );
189-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
188+
$attr["type"] = strtolower("week");
189+
$this->tag->output(["tag" => "input", "attr" => $attr]);
190190
}
191191

192-
public function submit( $attr = [], $options = [] )
192+
public function submit($attr = [], $options = [])
193193
{
194-
$attr["type"] = strtolower( __METHOD__ );
195-
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
194+
$attr["type"] = strtolower("submit");
195+
$this->tag->output(["tag" => "input", "attr" => $attr]);
196196
}
197197

198-
public function textarea( $attr = [], $options )
198+
public function textarea($attr = [], $options)
199199
{
200200

201201
$value = $attr["value"];
202-
unset( $attr["value"] );
203-
$this->tag->output( [ "tag" => "textarea", "attr" => $attr ] );
202+
unset($attr["value"]);
203+
$this->tag->output(["tag" => "textarea", "attr" => $attr]);
204204
echo $value;
205-
$this->tag->output( [ "tag" => "textarea", "close" => true ] );
205+
$this->tag->output(["tag" => "textarea", "close" => true]);
206206
}
207207

208-
public function select( $attr = [], $options = [] )
208+
public function select($attr = [], $options = [])
209209
{
210210
$value = $attr["value"];
211-
unset( $attr["value"] );
212-
$this->tag->output( [ "tag" => "select", "attr" => $attr ] );
211+
unset($attr["value"]);
212+
$this->tag->output(["tag" => "select", "attr" => $attr]);
213213

214-
if( !empty( $options ) ) {
214+
if ( !empty($options) ) {
215215

216-
foreach( $options as $ak => $av ){
216+
foreach ($options as $ak => $av) {
217217
echo "<option ";
218-
if( isset( $attr["valueOnly"] ) ){
218+
if (isset($attr["valueOnly"])) {
219219
echo " value=\"{$av}\" ";
220-
}
221-
else {
220+
} else {
222221
echo " value=\"{$ak}\" ";
223222
}
224223
echo ">{$av}</option>";
@@ -227,7 +226,7 @@ public function select( $attr = [], $options = [] )
227226

228227
}
229228

230-
$this->tag->output( [ "tag", "close" => true ] );
229+
$this->tag->output(["tag", "close" => true]);
231230

232231
}
233232

0 commit comments

Comments
 (0)