@@ -23,7 +23,8 @@ public function __construct( Array $formData, Array $elements ){
23
23
$ this ->formData = array_merge (
24
24
[
25
25
"method " => "post " ,
26
- "display " => "table "
26
+ "display " => "table " ,
27
+ "action " => ""
27
28
],
28
29
$ formData
29
30
);
@@ -65,15 +66,16 @@ protected function renderInputs(){
65
66
foreach ($ this ->elements as $ element ) {
66
67
67
68
//Values to be reset for each input
68
- $ opts = $ input = $ label = $ attributes = "" ;
69
+ $ opts = $ input = $ hidden = $ label = $ attributes = "" ;
69
70
70
71
71
72
//Extract key data from attributes
72
73
$ id = htmlspecialchars ( $ element ["id " ] );
73
74
$ name = htmlspecialchars ( $ element ["name " ] );
74
75
$ options = $ element ["options " ] ;
76
+ $ wrapper = isset ( $ element ["wrapper " ] ) ? $ element ["wrapper " ] : [] ;
75
77
$ default = htmlspecialchars ( $ element ["default " ] );
76
- $ type = htmlspecialchars ( $ element ["type " ] );
78
+ $ type = isset ( $ element [ " type " ]) ? htmlspecialchars ( $ element ["type " ] ) : " text " ;
77
79
78
80
79
81
@@ -82,6 +84,7 @@ protected function renderInputs(){
82
84
$ element ["name " ],
83
85
$ element ["options " ],
84
86
$ element ["type " ],
87
+ $ element ["wrapper " ],
85
88
$ element ["default " ]
86
89
);
87
90
@@ -94,20 +97,30 @@ protected function renderInputs(){
94
97
$ val = htmlspecialchars ( $ val );
95
98
96
99
if ( gettype ( $ val ) === true ){
97
- $ attributes .= "$ attr=' $ attr' " ;
100
+ $ attributes .= "$ attr= \" $ attr\" " ;
98
101
}
99
102
if ( gettype ( $ val ) === false ){
100
103
101
104
}
102
105
else {
103
- $ attributes .= "$ attr=' $ val' " ;
106
+ $ attributes .= "$ attr= \" $ val\" " ;
104
107
}
105
108
}
106
109
110
+ //Create Attributes
111
+ $ wrapper_attr = "" ;
112
+ foreach ( $ wrapper as $ attr => $ val ){
113
+
114
+ $ val = htmlspecialchars ( $ val );
115
+ $ wrapper_attr .= "$ attr= \"$ val \" " ;
116
+ }
117
+
107
118
//Create options
119
+ $ label = "<label for= \"$ inputID \"> $ name</label> " ;
120
+
108
121
switch ( $ type ) {
109
- case ' textarea ' :
110
- $ input = "<textarea id=' $ inputID' name=' $ id' value=' $ default' $ attributes></textarea> " ;
122
+ case " textarea " :
123
+ $ input = "<textarea id= \" $ inputID\" name= \" $ id\" value= \" $ default\" $ attributes></textarea> " ;
111
124
break ;
112
125
case "select " :
113
126
foreach ( $ options as $ key => $ val ){
@@ -116,52 +129,62 @@ protected function renderInputs(){
116
129
}
117
130
else {
118
131
$ key = htmlspecialchars ( $ key );
119
- $ value = "value=' $ key' " ;
132
+ $ value = "value= \" $ key\" " ;
120
133
}
121
134
$ opts .= "\n <option $ value> $ val</option> " ;
122
135
}
123
- $ input = "<select id=' $ inputID' name=' $ id' $ attributes value=' $ default' >$ opts \n </select> " ;
136
+ $ input = "<select id= \" $ inputID\" name= \" $ id\" $ attributes value= \" $ default\" > $ opts \n </select> " ;
124
137
125
138
break ;
126
139
case "radio " :
127
140
case "checkbox " :
128
141
foreach ( $ options as $ key =>$ val ){
129
142
if ( is_numeric ( $ key ) ){
130
143
$ val = htmlspecialchars ( $ val );
131
- $ value = "value=' $ val' " ;
144
+ $ value = "value= \" $ val\" " ;
132
145
}
133
146
else {
134
147
$ key = htmlspecialchars ( $ key );
135
- $ value = "value=' $ key' " ;
148
+ $ value = "value= \" $ key\" " ;
136
149
}
137
- $ input .= "\n<label><input type=' $ type' name=' $ id' $ attributes $ value/> $ val</label> " ;
150
+ $ input .= "\n<label><input type= \" $ type\" name= \" $ id\" $ attributes $ value/> $ val</label> " ;
138
151
}
139
152
140
153
break ;
141
- case ' submit ' :
142
- $ input = ' <input type="submit" name=" ' . $ id . ' " value=" ' . $ name . ' "> ' ;
143
- $ label = '' ;
154
+ case " submit " :
155
+ $ input = " <input type= \ "submit \ " name= \" $ id\ " value= \" $ name\" > " ;
156
+ $ label = "" ;
144
157
break ;
145
- default :
146
- $ input = "<input id=' $ inputID' type=' $ type' name=' $ id' $ attributes /> " ;
158
+ case "custom " :
159
+ $ input = $ element ["custom " ];
160
+ $ label = "" ;
147
161
break ;
162
+ default :
163
+ $ input = "<input id= \"$ inputID \" type= \"$ type \" name= \"$ id \" $ attributes value= \"$ default \" /> " ;
164
+
165
+ }
166
+
167
+ //Do not display hidden forms
168
+ if ( $ type == "hidden " ){
169
+ $ hidden .= $ input ;
170
+ continue ;
148
171
}
149
172
150
173
switch ( $ this ->formData ["display " ] ){
151
174
152
175
case "table " :
153
176
$ output .=<<<INPUT
154
- <tr>
155
- <td class="DFForm-input-title"><label for=" $ inputID "> $ name </ label> </td>
177
+ <tr $ wrapper_attr >
178
+ <td class="DFForm-input-title"> $ label</td>
156
179
<td class="DFForm-input-content"> $ input</td>
157
180
</tr>
158
181
INPUT ;
159
182
break ;
160
183
161
184
default :
162
185
$ output .=<<<INPUT
163
- <div class="DFForm-input">
164
- <div><label for=" $ inputID "> $ name </ label></div>
186
+ <div $ wrapper_attr class="DFForm-input-wrap ">
187
+ $ label
165
188
<div> $ input</div>
166
189
</div>
167
190
INPUT ;
@@ -170,13 +193,16 @@ protected function renderInputs(){
170
193
171
194
}
172
195
173
- return $ output ;
196
+ return [ $ output, $ hidden ] ;
174
197
}
175
198
176
- protected function printOutput ( $ output ){
199
+ protected function printOutput ( $ inputs ){
200
+
201
+ $ output = $ inputs [0 ];
202
+ $ hidden = $ inputs [1 ];
177
203
178
204
$ formData = $ this ->formData ;
179
- $ classes = $ formData ["class " ];
205
+ $ class = $ formData ["class " ];
180
206
181
207
unset(
182
208
$ formData ["id " ],
@@ -196,6 +222,7 @@ protected function printOutput( $output ){
196
222
return "
197
223
<form id='DFF $ this ->id - $ this ->formNo ' class='DFForm $ class' $ attributes>
198
224
$ wrapper [0 ] $ output $ wrapper [1 ]
225
+ $ hidden
199
226
</form> " ;
200
227
}
201
228
}
0 commit comments