Skip to content

Commit b351769

Browse files
committed
Update handler
1 parent c7cea8e commit b351769

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

src/Form/Handler.php

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,22 @@ public function open($formSettings = [])
3232

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

35-
if (isset($formSettings["controller"]) && isset($formSettings["method"])) {
36-
$formname .= "-{$formSettings["controller"]}-{$formSettings["method"]}";
35+
if (isset($formSettings["controller"]) && isset($formSettings["controllerMethod"])) {
36+
$formname .= "-{$formSettings["controller"]}-{$formSettings["controllerMethod"]}";
3737
}
3838

3939
$formname .= "-{$this->formcount}";
4040

4141
if (isset($_POST[$formname])) {
4242

43-
$this->processFormSubmission();
43+
$returnData = $this->processFormSubmission($_POST, $formSettings);
44+
return $returnData;
4445
}
4546

4647
ob_start();
4748
$this->tag->output(["tag" => "form", "attr" => $attributes]);
4849

49-
50-
51-
$this->tag->output(["tag" => "input", "attr" => ["type" => "hidden", "name" => "http-friend-name"]]);
50+
$this->tag->output(["tag" => "input", "attr" => ["type" => "hidden", "name" => $formname]]);
5251
echo ob_get_clean();
5352
return $this;
5453
}
@@ -59,139 +58,153 @@ public function close()
5958
}
6059

6160

62-
public function processFormSubmission()
61+
public function processFormSubmission($data = [], $settings)
6362
{
63+
$returnData = [];
64+
if (isset($settings["controller"]) && class_exists($settings["controller"])) {
65+
66+
$controller = new $settings["controller"](@$settings["controllerPassin"]);
67+
68+
if (isset($settings["controllerMethod"]) && method_exists($controller, $settings["controllerMethod"])) {
69+
$returnData = $controller->{$settings["controllerMethod"]}(@$settings["passin"]);
70+
} else {
71+
throw new Exception("No method defined for {$settings["controller"]}:{$settings["controllerMethod"]}");
72+
}
73+
} else {
74+
throw new Exception("Could not find {$settings["controller"]}");
75+
}
6476

77+
return $returnData;
6578
}
6679

6780
public function text($attr = [], $options = [])
6881
{
69-
$attr["type"] = strtolower("text");
82+
$attr["type"] = strtolower(__FUNCTION__);
7083
$this->tag->output(["tag" => "input", "attr" => $attr]);
7184
}
7285

7386
public function phone($attr = [], $options = [])
7487
{
75-
$attr["type"] = strtolower("phone");
88+
$attr["type"] = strtolower(__FUNCTION__);
7689
$this->tag->output(["tag" => "input", "attr" => $attr]);
7790
}
7891

7992
public function email($attr = [], $options = [])
8093
{
81-
$attr["type"] = strtolower("email");
94+
$attr["type"] = strtolower(__FUNCTION__);
8295
$this->tag->output(["tag" => "input", "attr" => $attr]);
8396
}
8497

8598
public function number($attr = [], $options = [])
8699
{
87-
$attr["type"] = strtolower("number");
100+
$attr["type"] = strtolower(__FUNCTION__);
88101
$this->tag->output(["tag" => "input", "attr" => $attr]);
89102
}
90103

91104
public function button($attr = [], $options = [])
92105
{
93-
$attr["type"] = strtolower("button");
106+
$attr["type"] = strtolower(__FUNCTION__);
94107
$this->tag->output(["tag" => "input", "attr" => $attr]);
95108
}
96109

97110
public function password($attr = [], $options = [])
98111
{
99-
$attr["type"] = strtolower("password");
112+
$attr["type"] = strtolower(__FUNCTION__);
100113
$this->tag->output(["tag" => "input", "attr" => $attr]);
101114
}
102115
public function hidden($attr = [], $options = [])
103116
{
104-
$attr["type"] = strtolower("hidden");
117+
$attr["type"] = strtolower(__FUNCTION__);
105118
$this->tag->output(["tag" => "input", "attr" => $attr]);
106119
}
107120

108121
public function checkbox($attr = [], $options = [])
109122
{
110-
$attr["type"] = strtolower("checkbox");
123+
$attr["type"] = strtolower(__FUNCTION__);
111124
$this->tag->output(["tag" => "input", "attr" => $attr]);
112125
}
113126

114127
public function radio($attr = [], $options = [])
115128
{
116-
$attr["type"] = strtolower("radio");
129+
$attr["type"] = strtolower(__FUNCTION__);
117130
$this->tag->output(["tag" => "input", "attr" => $attr]);
118131
}
119132

120133
public function file($attr = [], $options = [])
121134
{
122-
$attr["type"] = strtolower("file");
135+
$attr["type"] = strtolower(__FUNCTION__);
123136
$this->tag->output(["tag" => "input", "attr" => $attr]);
124137
}
125138

126139
public function image($attr = [], $options = [])
127140
{
128-
$attr["type"] = strtolower("image");
141+
$attr["type"] = strtolower(__FUNCTION__);
129142
$this->tag->output(["tag" => "input", "attr" => $attr]);
130143
}
131144

132145
public function color($attr = [], $options = [])
133146
{
134-
$attr["type"] = strtolower("color");
147+
$attr["type"] = strtolower(__FUNCTION__);
135148
$this->tag->output(["tag" => "input", "attr" => $attr]);
136149
}
137150

138151
public function date($attr = [], $options = [])
139152
{
140-
$attr["type"] = strtolower("date");
153+
$attr["type"] = strtolower(__FUNCTION__);
141154
$this->tag->output(["tag" => "input", "attr" => $attr]);
142155
}
143156

144157
public function datetimeLocal($attr = [], $options = [])
145158
{
146-
$attr["type"] = strtolower("datetime-local");
159+
$attr["type"] = strtolower(stFUNCTIONe("L", "-l", __METHOD__));
147160
$this->tag->output(["tag" => "input", "attr" => $attr]);
148161
}
149162

150163
public function month($attr = [], $options = [])
151164
{
152-
$attr["type"] = strtolower("month");
165+
$attr["type"] = strtolower(__FUNCTION__);
153166
$this->tag->output(["tag" => "input", "attr" => $attr]);
154167
}
155168

156169
public function range($attr = [], $options = [])
157170
{
158-
$attr["type"] = strtolower("range");
171+
$attr["type"] = strtolower(__FUNCTION__);
159172
$this->tag->output(["tag" => "input", "attr" => $attr]);
160173
}
161174

162175
public function reset($attr = [], $options = [])
163176
{
164-
$attr["type"] = strtolower("reset");
177+
$attr["type"] = strtolower(__FUNCTION__);
165178
$this->tag->output(["tag" => "input", "attr" => $attr]);
166179
}
167180

168181
public function search($attr = [], $options = [])
169182
{
170-
$attr["type"] = strtolower("search");
183+
$attr["type"] = strtolower(__FUNCTION__);
171184
$this->tag->output(["tag" => "input", "attr" => $attr]);
172185
}
173186

174187
public function tel($attr = [], $options = [])
175188
{
176-
$attr["type"] = strtolower("tel");
189+
$attr["type"] = strtolower(__FUNCTION__);
177190
$this->tag->output(["tag" => "input", "attr" => $attr]);
178191
}
179192

180193
public function url($attr = [], $options = [])
181194
{
182-
$attr["type"] = strtolower("url");
195+
$attr["type"] = strtolower(__FUNCTION__);
183196
$this->tag->output(["tag" => "input", "attr" => $attr]);
184197
}
185198

186199
public function week($attr = [], $options = [])
187200
{
188-
$attr["type"] = strtolower("week");
201+
$attr["type"] = strtolower(__FUNCTION__);
189202
$this->tag->output(["tag" => "input", "attr" => $attr]);
190203
}
191204

192205
public function submit($attr = [], $options = [])
193206
{
194-
$attr["type"] = strtolower("submit");
207+
$attr["type"] = strtolower(__FUNCTION__);
195208
$this->tag->output(["tag" => "input", "attr" => $attr]);
196209
}
197210

@@ -211,7 +224,7 @@ public function select($attr = [], $options = [])
211224
unset($attr["value"]);
212225
$this->tag->output(["tag" => "select", "attr" => $attr]);
213226

214-
if ( !empty($options) ) {
227+
if (!empty($options)) {
215228

216229
foreach ($options as $ak => $av) {
217230
echo "<option ";

0 commit comments

Comments
 (0)