1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
<?php /** * Outputs the HTML for each field within a given form_id. * It is attached to the ninja_forms_display_fields hook which is excuted by ninja_forms_display_form() in display-form.php **/ add_action('init', 'ninja_forms_register_display_fields'); function ninja_forms_register_display_fields(){ add_action('ninja_forms_display_fields', 'ninja_forms_display_fields', 10, 2); }
function ninja_forms_display_fields($form_id){ global $ninja_forms_fields, $ninja_forms_loading, $ninja_forms_processing;
$field_results = ninja_forms_get_fields_by_form_id($form_id); $field_results = apply_filters('ninja_forms_display_fields_array', $field_results, $form_id);
if ( is_array ( $field_results ) AND !empty ( $field_results ) ) { foreach ( $field_results as $field ) { if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { $field = $ninja_forms_loading->get_field_settings( $field['id'] ); } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { $field = $ninja_forms_processing->get_field_settings( $field['id'] ); }
if( isset( $ninja_forms_fields[$field['type']] ) ){ $type = $ninja_forms_fields[$field['type']];
$field_id = $field['id']; if(isset($field['data']['req'])){ $req = $field['data']['req']; }else{ $req = ''; }
$default_label_pos = $type['default_label_pos']; $display_wrap = $type['display_wrap']; $display_label = $type['display_label']; $sub_edit_function = $type['sub_edit_function']; $display_function = $type['display_function'];
//Check to see if we are currently editing a form submission. //If we are, then $display_function should be set to the sub_edit_function instead. if( is_object( $ninja_forms_processing)){ $sub_id = $ninja_forms_processing->get_form_setting('sub_id'); }else if(isset($_REQUEST['sub_id'])){ $sub_id = absint( $_REQUEST['sub_id'] ); }else{ $sub_id = ''; }
if ( $sub_id != '' AND $sub_edit_function != '' AND is_admin() ){ $display_function = $sub_edit_function; }
$process_field = $type['process_field']; $data = $field['data'];
//These filters can be used to temporarily modify the settings of a field, i.e. default_value. $data = apply_filters( 'ninja_forms_field', $data, $field_id ); //Check the show_field value of our $data array. If it is set to false, don't output the field. if(isset($data['show_field'])){ $show_field = $data['show_field']; }else{ $show_field = true; }
if( isset( $data['display_style'] ) ){ $display_style = $data['display_style']; }else{ $display_style = ''; }
if( isset( $data['visible'] ) ){ $visible = $data['visible']; }else{ $visible = true; }
if ( $display_style != '' ) { $display_style = 'style="'.$display_style.'"'; }
if ( $display_function != '' AND $show_field ) { if ( isset( $data['label_pos'] ) ) { $label_pos = $data['label_pos']; }else{ $label_pos = ''; } if( $label_pos == '' ) { $label_pos = $default_label_pos; }
do_action( 'ninja_forms_display_before_field', $field_id, $data );
//Check to see if display_wrap has been disabled. If it hasn't, show the wrapping DIV. if($display_wrap){ $field_wrap_class = ninja_forms_get_field_wrap_class($field_id, $form_id); $field_wrap_class = apply_filters( 'ninja_forms_field_wrap_class', $field_wrap_class, $field_id ); do_action( 'ninja_forms_display_before_opening_field_wrap', $field_id, $data ); ?> <div class="<?php echo $field_wrap_class;?>" <?php echo $display_style;?> id="ninja_forms_field_<?php echo $field_id;?>_div_wrap" data-visible="<?php echo $visible;?>"> <?php do_action( 'ninja_forms_display_after_opening_field_wrap', $field_id, $data ); }
//Check to see if display_label has been disabled. If it hasn't, show the label. if( $display_label ){ if( $label_pos == 'left' OR $label_pos == 'above' ){ // Check the label position variable. If it is left or above, show the label. do_action( 'ninja_forms_display_before_field_label', $field_id, $data ); do_action( 'ninja_forms_display_field_label', $field_id, $data ); do_action( 'ninja_forms_display_after_field_label', $field_id, $data ); } }
//Check to see if there is a registered display function. If so, call it. if($display_function != ''){
do_action( 'ninja_forms_display_before_field_function', $field_id, $data ); $arguments['field_id'] = $field_id; $arguments['data'] = $data; $arguments['form_id'] = $form_id; call_user_func_array($display_function, $arguments); do_action( 'ninja_forms_display_after_field_function', $field_id, $data ); if( $label_pos == 'left' OR $label_pos == 'inside'){ do_action( 'ninja_forms_display_field_help', $field_id, $data ); } }
//Check to see if display_label has been disabled. If it hasn't, show the label. if($display_label){ if($label_pos == 'right' OR $label_pos == 'below'){ // Check the label position variable. If it is right or below, show the label. do_action( 'ninja_forms_display_before_field_label', $field_id, $data ); do_action( 'ninja_forms_display_field_label', $field_id, $data ); do_action( 'ninja_forms_display_after_field_label', $field_id, $data ); } }
//Check to see if display_wrap has been disabled. If it hasn't close the wrapping DIV if($display_wrap){ do_action( 'ninja_forms_display_before_closing_field_wrap', $field_id, $data ); ?> </div> <?php do_action( 'ninja_forms_display_after_closing_field_wrap', $field_id, $data ); } do_action( 'ninja_forms_display_after_field', $field_id, $data ); } } } } }
/** * The next two functions are used to get CSS class names based upon field settings. * **/
function ninja_forms_get_field_wrap_class( $field_id, $form_id = '' ){ global $ninja_forms_loading, $ninja_forms_processing; $field_wrap_class = 'field-wrap';
if ( '' == $form_id ) { $field = ninja_forms_get_field_by_id( $field_id ); $form_id = $field['form_id']; }
if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { $field_row = $ninja_forms_loading->get_field_settings( $field_id ); } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { $field_row = $ninja_forms_processing->get_field_settings( $field_id ); }
$form_id = $field_row['form_id']; $data = $field_row['data'];
if ( isset ( $field_row['type'] ) ) { $type_slug = $field_row['type']; } else { $type_slug = ''; }
if(strpos($type_slug, "_") === 0){ $type_slug = substr($type_slug, 1); }
$field_wrap_class .= " ".$type_slug."-wrap"; if(isset($data['label_pos'])){ $label_pos = $data['label_pos']; }else{ $label_pos = 'above'; } $field_wrap_class .= " label-".$label_pos;
$x = 0; $custom_class = '';
if(isset($data['class']) AND !empty($data['class'])){ $class_array = explode(",", $data['class']); foreach($class_array as $class){ $custom_class .= $class; if($x != (count($class_array) - 1)){ $custom_class .= " "; } $x++; } }
if($custom_class != ''){ $custom_class = str_replace( ' ', '-wrap ', $custom_class ); $field_wrap_class .= ' '.$custom_class.'-wrap'; }
if( is_object( $ninja_forms_processing) AND is_array($ninja_forms_processing->get_errors_by_location($field_id))){ foreach($ninja_forms_processing->get_errors_by_location($field_id) as $error){ $field_wrap_class .= ' ninja-forms-error'; break; } } return apply_filters( 'ninja_forms_display_field_wrap_class', $field_wrap_class, $field_id, $field_row ); }
function ninja_forms_get_field_class( $field_id, $form_id = '' ) { global $ninja_forms_loading, $ninja_forms_processing;
if ( '' == $form_id ) { $field = ninja_forms_get_field_by_id( $field_id ); $form_id = $field['form_id']; }
if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { $field_row = $ninja_forms_loading->get_field_settings( $field_id ); $field_class = $ninja_forms_loading->get_field_setting( $field_id, 'field_class' ); } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { $field_row = $ninja_forms_processing->get_field_settings( $field_id ); $field_class = $ninja_forms_processing->get_field_setting( $field_id, 'field_class' ); } $field_data = $field_row['data']; $field_data = apply_filters( 'ninja_forms_field', $field_data, $field_id );
$field_type = isset ( $field_row['type'] ) ? $field_row['type'] : '';
$x = 0; $custom_class = '';
if ( isset( $field_data['class'] ) AND !empty ( $field_data['class'] ) ) { $class_array = explode(",", $field_data['class']); foreach($class_array as $class){ $custom_class .= $class; if($x != (count($class_array) - 1)){ $custom_class .= " "; } $x++; } }
$req_class = ''; if(isset($field_data['req']) AND $field_data['req'] == 1){ $req_class = 'ninja-forms-req'; }
// Check to see if we are dealing with a field that has the user_info_field_group set. if ( isset ( $field_data['user_info_field_group_name'] ) and $field_data['user_info_field_group_name'] != '' ) { $user_info_group_class = $field_data['user_info_field_group_name'].'-address'; } else { $user_info_group_class = ''; }
$address_class = ''; // Check to see if we are dealing with an address field. if ( isset ( $field_data['user_address_1'] ) and $field_data['user_address_1'] == 1 ) { $address_class = 'address address1'; }
if ( isset ( $field_data['user_address_2'] ) and $field_data['user_address_2'] == 1 ) { $address_class = 'address address2'; }
if ( isset ( $field_data['user_city'] ) and $field_data['user_city'] == 1 ) { $address_class = 'address city'; }
if ( isset ( $field_data['user_state'] ) and $field_data['user_state'] == 1 ) { $address_class = 'address state'; }
if ( isset ( $field_data['user_zip'] ) and $field_data['user_zip'] == 1 ) { $address_class = 'address zip'; }
if ( '_country' == $field_type ) { $address_class = 'address country'; }
if($req_class != ''){ $field_class .= " ".$req_class; }
if($custom_class != ''){ $field_class .= " ".$custom_class; }
if ( $user_info_group_class != '' ) { $field_class .= " ".$user_info_group_class; } if ( $address_class != '' ) { $field_class .= " ".$address_class; }
if ( isset ( $field_data['input_limit'] ) and $field_data['input_limit'] != '' ) { $field_class .= " input-limit"; }
return apply_filters( 'ninja_forms_display_field_class', $field_class, $field_id, $field_row ); }
|