22
33namespace HTTPFriend \Form ;
44
5+ use HTTPFriend \Tags \Tag as Tag ;
6+
57class Handler {
6-
8+
9+ public $ subittedData ;
10+ public $ files ;
11+
12+ public function __construct (){
13+ $ this ->tag = new Tag ;
14+ }
15+
16+ public function open ( $ formSettings = [] ){
17+
18+ if ( !isset ( $ formSettings ["method " ] ) )
19+ {
20+ $ attributes ["method " ] = "POST " ;
21+ }
22+ else {
23+ $ attributes ["method " ] = trim ( $ formSettings ["method " ] );
24+ }
25+
26+ if ( isset ( $ formSettings ["action " ] ) ) {
27+ $ attributes ["action " ] = $ formSettings ["action " ];
28+ }
29+ else {
30+ $ attributes ["action " ] = "./ " ;
31+ }
32+
33+ $ formname = "http-friend-name- " ;
34+
35+ if ( isset ( $ formSettings ["controller " ] ) && isset ( $ formSettings ["method " ] ) )
36+ {
37+ $ formname .= "- {$ formSettings ["controller " ]}- {$ formSettings ["method " ]}" ;
38+ }
39+
40+ $ formname .= "- {$ this ->formcount }" ;
41+
42+ if ( isset ( $ _POST [$ formname ] ) ){
43+
44+ $ this ->processFormSubmission ();
45+ }
46+
47+ ob_start ();
48+ $ this ->tag ->output ([ "tag " => "form " , "attr " => $ attributes ] );
49+
50+
51+
52+ $ this ->tag ->output ([ "tag " => "input " , "attr " => [ "type " => "hidden " , "name " => "http-friend-name " ] ] );
53+ echo ob_get_clean ();
54+ }
55+
56+ public function close (){
57+ $ this ->tag ->output ( [ "tag " => "form " , "close " => true ] );
58+ }
59+
60+
61+ public function processFormSubmission ()
62+ {
63+
64+ }
65+
66+ public function text ( $ attr = [], $ options = [] )
67+ {
68+ $ attr ["type " ] = strtolower ( __METHOD__ );
69+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
70+ }
71+
72+ public function phone ( $ attr = [], $ options = [] )
73+ {
74+ $ attr ["type " ] = strtolower ( __METHOD__ );
75+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
76+ }
77+
78+ public function email ( $ attr = [], $ options = [] )
79+ {
80+ $ attr ["type " ] = strtolower ( __METHOD__ );
81+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
82+ }
83+
84+ public function number ( $ attr = [], $ options = [] )
85+ {
86+ $ attr ["type " ] = strtolower ( __METHOD__ );
87+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
88+ }
89+
90+ public function button ( $ attr = [], $ options = [] )
91+ {
92+ $ attr ["type " ] = strtolower ( __METHOD__ );
93+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
94+ }
95+
96+ public function password ( $ attr = [], $ options = [] )
97+ {
98+ $ attr ["type " ] = strtolower ( __METHOD__ );
99+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
100+ }
101+ public function hidden ( $ attr = [], $ options = [] )
102+ {
103+ $ attr ["type " ] = strtolower ( __METHOD__ );
104+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
105+ }
106+
107+ public function checkbox ( $ attr = [], $ options = [] )
108+ {
109+ $ attr ["type " ] = strtolower ( __METHOD__ );
110+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
111+ }
112+
113+ public function radio ( $ attr = [], $ options = [] )
114+ {
115+ $ attr ["type " ] = strtolower ( __METHOD__ );
116+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
117+ }
118+
119+ public function file ( $ attr = [], $ options = [] )
120+ {
121+ $ attr ["type " ] = strtolower ( __METHOD__ );
122+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
123+ }
124+
125+ public function image ( $ attr = [], $ options = [] )
126+ {
127+ $ attr ["type " ] = strtolower ( __METHOD__ );
128+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
129+ }
130+
131+ public function color ( $ attr = [], $ options = [] )
132+ {
133+ $ attr ["type " ] = strtolower ( __METHOD__ );
134+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
135+ }
136+
137+ public function color ( $ attr = [], $ options = [] )
138+ {
139+ $ attr ["type " ] = strtolower ( __METHOD__ );
140+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
141+ }
142+
143+ public function date ( $ attr = [], $ options = [] )
144+ {
145+ $ attr ["type " ] = strtolower ( __METHOD__ );
146+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
147+ }
148+
149+ public function datetimeLocal ( $ attr = [], $ options = [] )
150+ {
151+ $ attr ["type " ] = strtolower ( str_replace ( "L " , "-l " , __METHOD__ ) );
152+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
153+ }
154+
155+ public function month ( $ attr = [], $ options = [] )
156+ {
157+ $ attr ["type " ] = strtolower ( __METHOD__ );
158+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
159+ }
160+
161+ public function range ( $ attr = [], $ options = [] )
162+ {
163+ $ attr ["type " ] = strtolower ( __METHOD__ );
164+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
165+ }
166+
167+ public function reset ( $ attr = [], $ options = [] )
168+ {
169+ $ attr ["type " ] = strtolower ( __METHOD__ );
170+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
171+ }
172+
173+ public function search ( $ attr = [], $ options = [] )
174+ {
175+ $ attr ["type " ] = strtolower ( __METHOD__ );
176+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
177+ }
178+
179+ public function tel ( $ attr = [], $ options = [] )
180+ {
181+ $ attr ["type " ] = strtolower ( __METHOD__ );
182+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
183+ }
184+
185+ public function url ( $ attr = [], $ options = [] )
186+ {
187+ $ attr ["type " ] = strtolower ( __METHOD__ );
188+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
189+ }
190+
191+ public function week ( $ attr = [], $ options = [] )
192+ {
193+ $ attr ["type " ] = strtolower ( __METHOD__ );
194+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
195+ }
196+
197+ public function submit ( $ attr = [], $ options = [] )
198+ {
199+ $ attr ["type " ] = strtolower ( __METHOD__ );
200+ $ this ->tag ->output ( [ "tag " => "input " , "attr " => $ attr ] );
201+ }
202+
203+ public function textarea ( $ attr = [], $ options )
204+ {
205+
206+ $ value = $ attr ["value " ];
207+ unset( $ attr ["value " ] );
208+ $ this ->tag ->output ( [ "tag " => "textarea " , "attr " => $ attr ] );
209+ echo $ value ;
210+ $ this ->tag ->output ( [ "tag " => "textarea " , "close " => true ] );
211+ }
212+
213+ public function select ( $ attr = [], $ options = [] )
214+ {
215+ $ value = $ attr ["value " ];
216+ unset( $ attr ["value " ] );
217+ $ this ->tag ->output ( [ "tag " => "select " , "attr " => $ attr ] );
218+
219+ if ( !empty ( $ options ) ) {
220+
221+ foreach ( $ options as $ ak => $ av ){
222+ echo "<option "
223+ if ( isset ( $ attr ["valueOnly " ] ) ){
224+ echo " value= \"{$ av }\" " ;
225+ }
226+ else {
227+ echo " value= \"{$ ak }\" " ;
228+ }
229+ echo "> {$ av }</option> " ;
230+
231+ }
232+
233+ }
234+
235+ $ this ->tag ->output ( [ "tag " , "close " => true ] );
236+
237+ }
238+
7239}
0 commit comments