Skip to content

Commit 53f6132

Browse files
committed
WIP
1 parent b368779 commit 53f6132

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

php-error.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[19-Feb-2019 17:13:21 Europe/London] PHP Catchable fatal error: Object of class Test could not be converted to string in /websites/active/_tom/HTTPFriend/src/Form/FormHandler.php on line 39
2+
[19-Feb-2019 17:13:42 Europe/London] PHP Catchable fatal error: Object of class Test could not be converted to string in /websites/active/_tom/HTTPFriend/src/Form/FormHandler.php on line 39
3+
[19-Feb-2019 17:17:18 Europe/London]
4+
[19-Feb-2019 17:17:18 Europe/London] PHP Fatal error: Call to a member function text() on null in /websites/active/_tom/HTTPFriend/test/index.php on line 21

src/Form/Handler.php renamed to src/Form/FormHandler.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use HTTPFriend\Tags\Tag as Tag;
66

7-
class Handler
7+
class FormHandler
88
{
99

1010
public $subittedData;
@@ -16,25 +16,34 @@ public function __construct()
1616
$this->tag = new Tag;
1717
}
1818

19-
public function open($formSettings = [])
19+
public function open( $formSettings = [])
2020
{
2121

2222
if (!isset($formSettings["method"])) {
2323
$attributes["method"] = "POST";
24-
} else {
24+
}
25+
else {
2526
$attributes["method"] = trim($formSettings["method"]);
2627
}
2728

2829
if (isset($formSettings["action"])) {
2930
$attributes["action"] = $formSettings["action"];
30-
} else {
31+
}
32+
else {
3133
$attributes["action"] = "./";
3234
}
3335

3436
$formname = "http-friend-name-";
3537

36-
if (isset($formSettings["controller"]) && isset($formSettings["controllerMethod"])) {
37-
$formname .= "-{$formSettings["controller"]}-{$formSettings["controllerMethod"]}";
38+
if( isset( $formSettings["controller"] ) && is_string( $formSettings["controller"] ) ) {
39+
$formname .= "{$formSettings["controller"]}-";
40+
}
41+
else if( is_object( $formSettings["controller"] ) ){
42+
$formname .= get_class( $formSettings["controller"] )."-";
43+
}
44+
45+
if( isset( $formSettings["controllerMethod"] ) && is_string( $formSettings["controllerMethod"] ) ) {
46+
$formname .= "-{$formSettings["controllerMethod"]}";
3847
}
3948

4049
$formname .= "-{$this->formcount}";
@@ -46,13 +55,15 @@ public function open($formSettings = [])
4655
}
4756

4857
ob_start();
58+
4959
$this->tag->output(["tag" => "form", "attr" => $attributes]);
5060

5161
$this->tag->output(["tag" => "input", "attr" => ["type" => "hidden", "name" => $formname]]);
5262

5363
$this->formcount++;
5464

5565
echo ob_get_clean();
66+
5667
return $this;
5768
}
5869

@@ -65,21 +76,29 @@ public function close()
6576
public function processFormSubmission($data = [], $settings)
6677
{
6778
$returnData = [];
68-
if (isset($settings["controller"]) && class_exists($settings["controller"])) {
69-
79+
if (isset($settings["controller"]) && is_string( $settings["controller"] ) && class_exists($settings["controller"]) ) {
7080
$controller = new $settings["controller"](@$settings["controllerPassin"]);
81+
}
82+
else if( isset( $settings["controller"] ) && is_object( $settings["controller"] ) ){
83+
$controller = $settings["controller"];
84+
}
85+
else if( !isset( $settings["controller"] ) ) {
86+
throw new \Exception("No Controller passed to form");
87+
}
88+
else {
89+
throw new \Exception("Could not find {$settings["controller"]}");
90+
}
7191

72-
if (isset($settings["controllerMethod"]) && method_exists($controller, $settings["controllerMethod"])) {
73-
$returnData = $controller->{$settings["controllerMethod"]}(@$settings["passin"]);
74-
} else {
75-
throw new Exception("No method defined for {$settings["controller"]}:{$settings["controllerMethod"]}");
76-
}
92+
if (isset($settings["controllerMethod"]) && method_exists( $controller, $settings["controllerMethod"])) {
93+
$returnData = $controller->{$settings["controllerMethod"]}(@$settings["passin"]);
7794
} else {
78-
throw new Exception("Could not find {$settings["controller"]}");
95+
throw new \Exception("No method defined for {$settings["controller"]}:{$settings["controllerMethod"]}");
7996
}
8097

8198
return $returnData;
82-
}
99+
}
100+
101+
83102

84103
public function text($attr = [], $options = [])
85104
{

src/HTTPHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace HTTPFriend;
44

55

6-
use HTTPFriend\Form\Handler as Handler;
6+
use HTTPFriend\Form\FormHandler as FormHandler;
77
use HTTPFriend\Tags\Tag as Tag;
88
use HTTPFriend\Tags\Link as Link;
99
use HTTPFriend\Tags\Meta as Meta;
@@ -24,7 +24,7 @@ class HTTPHelper
2424
public function __construct($config = [])
2525
{
2626
$this->setConfig($config);
27-
$this->form = $this->form ?: new Handler;
27+
$this->form = $this->form ?: new FormHandler;
2828
$this->tag = $this->tag ? : new Tag;
2929
$this->CSS = $this->CSS ? : new Css;
3030
$this->JS = $this->JS ? : new Js;

test/testimg.jpg

-8.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)