@@ -8,8 +8,10 @@ class FormHandler
88{
99
1010 public $ subittedData ;
11+ public $ rawSubmittedData ;
1112 public $ files ;
1213 public $ formcount ;
14+ public $ returnData ;
1315
1416 public function __construct ()
1517 {
@@ -19,6 +21,8 @@ public function __construct()
1921 public function open ( $ formSettings = [])
2022 {
2123
24+ $ attributes = [];
25+
2226 if (!isset ($ formSettings ["method " ])) {
2327 $ attributes ["method " ] = "POST " ;
2428 }
@@ -33,6 +37,9 @@ public function open( $formSettings = [])
3337 $ attributes ["action " ] = "./ " ;
3438 }
3539
40+
41+ $ attributes = array_merge ( $ attributes , is_array ( $ formSettings ["attributes " ] ) ? $ formSettings ["attributes " ] : [] );
42+
3643 $ formname = "http-friend-name- " ;
3744
3845 if ( isset ( $ formSettings ["controller " ] ) && is_string ( $ formSettings ["controller " ] ) ) {
@@ -48,15 +55,42 @@ public function open( $formSettings = [])
4855
4956 $ formname .= "- {$ this ->formcount }" ;
5057
51- if (isset ($ _POST [$ formname ])) {
58+ if ( strtolower ( $ attributes ["method " ] ) == "post " ) {
59+ $ this ->submittedData = $ _POST ;
60+ $ this ->submittedData ["files " ] = $ _FILES ;
61+
62+ if ( $ attributes ["enctype " ] == "multipart/form-data " ) {
63+ $ raw = http_build_query ( $ _POST );
64+ }
65+ else {
66+ $ raw = file_get_contents ( "php://input " );
67+ }
68+ }
69+ else {
70+ $ this ->submittedData = $ _GET ;
71+ $ raw = $ _SERVER ["QUERY_STRING " ];
72+ }
73+
74+ $ this ->rawSubmittedData = [];
75+
76+ if ( strlen ( $ raw ) ) {
77+ $ raw = explode ( "& " , $ raw );
78+
79+ foreach ( $ raw as $ d ) {
80+ $ d = explode ( "= " , $ d );
81+ $ this ->rawSubmittedData [urlencode ( $ d [0 ] )] = urlencode ( $ d [1 ] );
82+ }
83+ }
5284
53- $ returnData = $ this -> processFormSubmission ( $ _POST , $ formSettings);
54- return $ returnData ;
85+ if ( isset ( $ formSettings[ " controller " ] ) ){
86+ $ this -> returnData = $ this -> processFormSubmission ( $ this -> submittedData , $ formSettings ) ;
5587 }
5688
89+
90+
5791 ob_start ();
5892
59- $ this ->tag ->output (["tag " => "form " , "attr " => $ attributes ]);
93+ $ this ->tag ->output (["tag " => "form " , "attr " => $ attributes ]);
6094
6195 $ this ->tag ->output (["tag " => "input " , "attr " => ["type " => "hidden " , "name " => $ formname ]]);
6296
@@ -73,7 +107,7 @@ public function close()
73107 }
74108
75109
76- public function processFormSubmission ($ data = [], $ settings )
110+ public function processFormSubmission ( $ data = [], $ settings )
77111 {
78112 $ returnData = [];
79113 if (isset ($ settings ["controller " ]) && is_string ( $ settings ["controller " ] ) && class_exists ($ settings ["controller " ]) ) {
0 commit comments