|
1
|
|
|
<?php |
|
2
|
|
|
if ( ! defined('ABSPATH') ) { |
|
3
|
|
|
die( 'You are not allowed to call this page directly.' ); |
|
4
|
|
|
} |
|
5
|
|
|
|
|
6
|
|
|
class FrmFieldsHelper { |
|
7
|
|
|
|
|
8
|
|
|
public static function setup_new_vars( $type = '', $form_id = '' ) { |
|
9
|
|
|
|
|
10
|
|
|
if ( strpos($type, '|') ) { |
|
11
|
|
|
list($type, $setting) = explode('|', $type); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
$defaults = self::get_default_field_opts($type, $form_id); |
|
15
|
|
|
$defaults['field_options']['custom_html'] = self::get_default_html($type); |
|
16
|
|
|
|
|
17
|
|
|
$values = array(); |
|
18
|
|
|
|
|
19
|
|
|
foreach ( $defaults as $var => $default ) { |
|
20
|
|
|
if ( $var == 'field_options' ) { |
|
21
|
|
|
$values['field_options'] = array(); |
|
22
|
|
|
foreach ( $default as $opt_var => $opt_default ) { |
|
23
|
|
|
$values['field_options'][ $opt_var ] = $opt_default; |
|
24
|
|
|
unset($opt_var, $opt_default); |
|
25
|
|
|
} |
|
26
|
|
|
} else { |
|
27
|
|
|
$values[ $var ] = $default; |
|
28
|
|
|
} |
|
29
|
|
|
unset($var, $default); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ( isset( $setting ) && ! empty( $setting ) ) { |
|
33
|
|
|
if ( 'data' == $type ) { |
|
34
|
|
|
$values['field_options']['data_type'] = $setting; |
|
35
|
|
|
} else { |
|
36
|
|
|
$values['field_options'][ $setting ] = 1; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if ( $type == 'radio' || $type == 'checkbox' ) { |
|
41
|
|
|
$values['options'] = serialize( array( |
|
42
|
|
|
__( 'Option 1', 'formidable' ), |
|
43
|
|
|
__( 'Option 2', 'formidable' ), |
|
44
|
|
|
) ); |
|
45
|
|
|
} else if ( $type == 'select' ) { |
|
46
|
|
|
$values['options'] = serialize( array( |
|
47
|
|
|
'', __( 'Option 1', 'formidable' ), |
|
48
|
|
|
) ); |
|
49
|
|
|
} else if ( $type == 'textarea' ) { |
|
50
|
|
|
$values['field_options']['max'] = '5'; |
|
51
|
|
|
} else if ( $type == 'captcha' ) { |
|
52
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
53
|
|
|
$values['invalid'] = $frm_settings->re_msg; |
|
54
|
|
|
} else if ( 'url' == $type ) { |
|
55
|
|
|
$values['name'] = __( 'Website', 'formidable' ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$fields = FrmField::field_selection(); |
|
59
|
|
|
$fields = array_merge($fields, FrmField::pro_field_selection()); |
|
60
|
|
|
|
|
61
|
|
|
if ( isset( $fields[ $type ] ) ) { |
|
62
|
|
|
$values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
unset($fields); |
|
66
|
|
|
|
|
67
|
|
|
return $values; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public static function get_html_id( $field, $plus = '' ) { |
|
71
|
|
|
return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public static function setup_edit_vars( $record, $doing_ajax = false ) { |
|
75
|
|
|
$values = array( 'id' => $record->id, 'form_id' => $record->form_id ); |
|
76
|
|
|
$defaults = array( |
|
77
|
|
|
'name' => $record->name, |
|
78
|
|
|
'description' => $record->description, |
|
79
|
|
|
'field_key' => $record->field_key, |
|
80
|
|
|
'type' => $record->type, |
|
81
|
|
|
'default_value' => $record->default_value, |
|
82
|
|
|
'field_order' => $record->field_order, |
|
83
|
|
|
'required' => $record->required, |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
if ( $doing_ajax ) { |
|
87
|
|
|
$values = $values + $defaults; |
|
88
|
|
|
$values['form_name'] = ''; |
|
89
|
|
|
} else { |
|
90
|
|
|
foreach ( $defaults as $var => $default ) { |
|
91
|
|
|
$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' ); |
|
92
|
|
|
unset($var, $default); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$values['form_name'] = $record->form_id ? FrmForm::getName( $record->form_id ) : ''; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
unset( $defaults ); |
|
99
|
|
|
|
|
100
|
|
|
$values['options'] = $record->options; |
|
101
|
|
|
$values['field_options'] = $record->field_options; |
|
102
|
|
|
|
|
103
|
|
|
$defaults = self::get_default_field_opts($values['type'], $record, true); |
|
104
|
|
|
|
|
105
|
|
|
if ( $values['type'] == 'captcha' ) { |
|
106
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
107
|
|
|
$defaults['invalid'] = $frm_settings->re_msg; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
foreach ( $defaults as $opt => $default ) { |
|
111
|
|
|
$values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default; |
|
112
|
|
|
unset($opt, $default); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type); |
|
116
|
|
|
|
|
117
|
|
|
return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public static function get_default_field_opts( $type, $field, $limit = false ) { |
|
121
|
|
|
$field_options = array( |
|
122
|
|
|
'size' => '', 'max' => '', 'label' => '', 'blank' => '', |
|
123
|
|
|
'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0, |
|
124
|
|
|
'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '', |
|
125
|
|
|
'custom_html' => '', 'captcha_size' => 'default', 'captcha_theme' => 'light', |
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
|
|
if ( $limit ) { |
|
129
|
|
|
return $field_options; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
global $wpdb; |
|
133
|
|
|
|
|
134
|
|
|
$form_id = (is_numeric($field)) ? $field : $field->form_id; |
|
135
|
|
|
|
|
136
|
|
|
$key = is_numeric( $field ) ? FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ) : $field->field_key; |
|
137
|
|
|
|
|
138
|
|
|
$field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) ); |
|
139
|
|
|
|
|
140
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
141
|
|
|
return array( |
|
142
|
|
|
'name' => __( 'Untitled', 'formidable' ), 'description' => '', |
|
143
|
|
|
'field_key' => $key, 'type' => $type, 'options' => '', 'default_value' => '', |
|
144
|
|
|
'field_order' => $field_count + 1, 'required' => false, |
|
145
|
|
|
'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg, |
|
146
|
|
|
'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id, |
|
147
|
|
|
'field_options' => $field_options, |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public static function fill_field( &$values, $field, $form_id, $new_key = '' ) { |
|
152
|
|
|
global $wpdb; |
|
153
|
|
|
|
|
154
|
|
|
$values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
|
155
|
|
|
$values['form_id'] = $form_id; |
|
156
|
|
|
$values['options'] = maybe_serialize($field->options); |
|
157
|
|
|
$values['default_value'] = maybe_serialize($field->default_value); |
|
158
|
|
|
|
|
159
|
|
|
foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) { |
|
160
|
|
|
$values[ $col ] = $field->{$col}; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @since 2.0 |
|
166
|
|
|
*/ |
|
167
|
|
|
public static function get_error_msg( $field, $error ) { |
|
168
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
169
|
|
|
$default_settings = $frm_settings->default_options(); |
|
170
|
|
|
$field_name = is_array( $field ) ? $field['name'] : $field->name; |
|
171
|
|
|
|
|
172
|
|
|
$defaults = array( |
|
173
|
|
|
'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => sprintf( __('%s must be unique', 'formidable' ), $field_name ) ), |
|
174
|
|
|
'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => sprintf( __('%s is invalid', 'formidable' ), $field_name ) ), |
|
175
|
|
|
'blank' => array( 'full' => $frm_settings->blank_msg, 'part' => $frm_settings->blank_msg ), |
|
176
|
|
|
); |
|
177
|
|
|
|
|
178
|
|
|
$msg = FrmField::get_option( $field, $error ); |
|
179
|
|
|
$msg = ( $msg == $defaults[ $error ]['full'] || empty( $msg ) ) ? $defaults[ $error ]['part'] : $msg; |
|
180
|
|
|
$msg = do_shortcode( $msg ); |
|
181
|
|
|
return $msg; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public static function get_form_fields( $form_id, $error = false ) { |
|
185
|
|
|
$fields = FrmField::get_all_for_form($form_id); |
|
186
|
|
|
$fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error); |
|
187
|
|
|
return $fields; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public static function get_default_html( $type = 'text' ) { |
|
191
|
|
|
if ( apply_filters( 'frm_normal_field_type_html', true, $type ) ) { |
|
192
|
|
|
$input = ( in_array( $type, array( 'radio', 'checkbox', 'data' ) ) ) ? '<div class="frm_opt_container">[input]</div>' : '[input]'; |
|
193
|
|
|
$for = ''; |
|
194
|
|
|
if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale' ) ) ) { |
|
195
|
|
|
$for = 'for="field_[key]"'; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$default_html = <<<DEFAULT_HTML |
|
199
|
|
|
<div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]"> |
|
200
|
|
|
<label $for class="frm_primary_label">[field_name] |
|
201
|
|
|
<span class="frm_required">[required_label]</span> |
|
202
|
|
|
</label> |
|
203
|
|
|
$input |
|
204
|
|
|
[if description]<div class="frm_description">[description]</div>[/if description] |
|
205
|
|
|
[if error]<div class="frm_error">[error]</div>[/if error] |
|
206
|
|
|
</div> |
|
207
|
|
|
DEFAULT_HTML; |
|
208
|
|
|
} else { |
|
209
|
|
|
$default_html = apply_filters('frm_other_custom_html', '', $type); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
return apply_filters('frm_custom_html', $default_html, $type); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { |
|
216
|
|
|
$html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form); |
|
217
|
|
|
|
|
218
|
|
|
$defaults = array( |
|
219
|
|
|
'field_name' => 'item_meta[' . $field['id'] . ']', |
|
220
|
|
|
'field_id' => $field['id'], |
|
221
|
|
|
'field_plus_id' => '', |
|
222
|
|
|
'section_id' => '', |
|
223
|
|
|
); |
|
224
|
|
|
$args = wp_parse_args($args, $defaults); |
|
225
|
|
|
$field_name = $args['field_name']; |
|
226
|
|
|
$field_id = $args['field_id']; |
|
227
|
|
|
$html_id = self::get_html_id($field, $args['field_plus_id']); |
|
228
|
|
|
|
|
229
|
|
|
if ( FrmField::is_multiple_select($field) ) { |
|
230
|
|
|
$field_name .= '[]'; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
//replace [id] |
|
234
|
|
|
$html = str_replace('[id]', $field_id, $html); |
|
235
|
|
|
|
|
236
|
|
|
// Remove the for attribute for captcha |
|
237
|
|
|
if ( $field['type'] == 'captcha' ) { |
|
238
|
|
|
$html = str_replace(' for="field_[key]"', '', $html); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
// set the label for |
|
242
|
|
|
$html = str_replace('field_[key]', $html_id, $html); |
|
243
|
|
|
|
|
244
|
|
|
//replace [key] |
|
245
|
|
|
$html = str_replace('[key]', $field['field_key'], $html); |
|
246
|
|
|
|
|
247
|
|
|
//replace [description] and [required_label] and [error] |
|
248
|
|
|
$required = FrmField::is_required( $field ) ? $field['required_indicator'] : ''; |
|
249
|
|
|
if ( ! is_array( $errors ) ) { |
|
250
|
|
|
$errors = array(); |
|
251
|
|
|
} |
|
252
|
|
|
$error = isset( $errors[ 'field' . $field_id ] ) ? $errors[ 'field' . $field_id ] : false; |
|
253
|
|
|
|
|
254
|
|
|
//If field type is section heading, add class so a bottom margin can be added to either the h3 or description |
|
255
|
|
|
if ( $field['type'] == 'divider' ) { |
|
256
|
|
|
if ( FrmField::is_option_true( $field, 'description' ) ) { |
|
257
|
|
|
$html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html ); |
|
258
|
|
|
} else { |
|
259
|
|
|
$html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html); |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
foreach ( array( 'description' => $field['description'], 'required_label' => $required, 'error' => $error ) as $code => $value ) { |
|
264
|
|
|
self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html ); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
//replace [required_class] |
|
268
|
|
|
$required_class = FrmField::is_required( $field ) ? ' frm_required_field' : ''; |
|
269
|
|
|
$html = str_replace('[required_class]', $required_class, $html); |
|
270
|
|
|
|
|
271
|
|
|
//replace [label_position] |
|
272
|
|
|
$field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form); |
|
273
|
|
|
$field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top'; |
|
274
|
|
|
$html = str_replace( '[label_position]', ( ( in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ) ? $field['label'] : ' frm_primary_label' ), $html ); |
|
275
|
|
|
|
|
276
|
|
|
//replace [field_name] |
|
277
|
|
|
$html = str_replace('[field_name]', $field['name'], $html); |
|
278
|
|
|
|
|
279
|
|
|
//replace [error_class] |
|
280
|
|
|
$error_class = isset( $errors[ 'field' . $field_id ] ) ? ' frm_blank_field' : ''; |
|
281
|
|
|
self::get_more_field_classes( $error_class, $field, $field_id, $html ); |
|
282
|
|
|
if ( $field['type'] == 'html' && strpos( $html, '[error_class]' ) === false ) { |
|
283
|
|
|
// there is no error_class shortcode to use for addign fields |
|
284
|
|
|
$html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $error_class, $html ); |
|
285
|
|
|
} |
|
286
|
|
|
$html = str_replace('[error_class]', $error_class, $html); |
|
287
|
|
|
|
|
288
|
|
|
//replace [entry_key] |
|
289
|
|
|
$entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); |
|
290
|
|
|
$html = str_replace('[entry_key]', $entry_key, $html); |
|
291
|
|
|
|
|
292
|
|
|
//replace [input] |
|
293
|
|
|
preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER); |
|
294
|
|
|
global $frm_vars; |
|
295
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
296
|
|
|
|
|
297
|
|
|
foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
298
|
|
|
$atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
299
|
|
|
$tag = self::get_shortcode_tag( $shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false ) ); |
|
300
|
|
|
|
|
301
|
|
|
$replace_with = ''; |
|
302
|
|
|
|
|
303
|
|
|
if ( $tag == 'input' ) { |
|
304
|
|
|
if ( isset($atts['opt']) ) { |
|
305
|
|
|
$atts['opt']--; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
$field['input_class'] = isset($atts['class']) ? $atts['class'] : ''; |
|
309
|
|
|
if ( isset($atts['class']) ) { |
|
310
|
|
|
unset($atts['class']); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
$field['shortcodes'] = $atts; |
|
314
|
|
|
ob_start(); |
|
315
|
|
|
include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/input.php' ); |
|
316
|
|
|
$replace_with = ob_get_contents(); |
|
317
|
|
|
ob_end_clean(); |
|
318
|
|
|
} else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
|
319
|
|
|
$replace_with = FrmProEntriesController::entry_delete_link($atts); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
$html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html ); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
if ( $form ) { |
|
326
|
|
|
$form = (array) $form; |
|
327
|
|
|
|
|
328
|
|
|
//replace [form_key] |
|
329
|
|
|
$html = str_replace('[form_key]', $form['form_key'], $html); |
|
330
|
|
|
|
|
331
|
|
|
//replace [form_name] |
|
332
|
|
|
$html = str_replace('[form_name]', $form['name'], $html); |
|
333
|
|
|
} |
|
334
|
|
|
$html .= "\n"; |
|
335
|
|
|
|
|
336
|
|
|
//Return html if conf_field to prevent loop |
|
337
|
|
|
if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) { |
|
338
|
|
|
return $html; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
//If field is in repeating section |
|
342
|
|
|
if ( $args['section_id'] ) { |
|
343
|
|
|
$html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] )); |
|
344
|
|
|
} else { |
|
345
|
|
|
$html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form )); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
self::remove_collapse_shortcode( $html ); |
|
349
|
|
|
|
|
350
|
|
|
if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
|
351
|
|
|
$html = do_shortcode( $html ); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
return $html; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* Add more classes to certain fields (like confirmation fields, other fields, repeating fields, etc.) |
|
359
|
|
|
* |
|
360
|
|
|
* @since 2.0 |
|
361
|
|
|
* @param $error_class string, pass by reference |
|
362
|
|
|
* @param $field array |
|
363
|
|
|
* @param $field_id int |
|
364
|
|
|
* @param $html string |
|
365
|
|
|
*/ |
|
366
|
|
|
private static function get_more_field_classes( &$error_class, $field, $field_id, $html ) { |
|
367
|
|
|
$error_class .= ' frm_' . $field['label'] . '_container'; |
|
368
|
|
|
if ( $field['id'] != $field_id ) { |
|
369
|
|
|
// add a class for repeating/embedded fields |
|
370
|
|
|
$error_class .= ' frm_field_' . $field['id'] . '_container'; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
// Add class to embedded form field |
|
374
|
|
|
if ( $field['type'] == 'form' ) { |
|
375
|
|
|
$error_class .= ' frm_embed_form_container'; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
// Add class to HTML field |
|
379
|
|
|
if ( $field['type'] == 'html' ) { |
|
380
|
|
|
$error_class .= ' frm_html_container'; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
//Add classes to inline confirmation field (if it doesn't already have classes set) |
|
384
|
|
|
if ( isset( $field['conf_field'] ) && $field['conf_field'] == 'inline' && ! $field['classes'] ) { |
|
385
|
|
|
$error_class .= ' frm_first frm_half'; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
//Add class if field includes other option |
|
389
|
|
|
if ( isset( $field['other'] ) && true == $field['other'] ) { |
|
390
|
|
|
$error_class .= ' frm_other_container'; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
// Add class to Dynamic fields |
|
394
|
|
|
if ( $field['type'] == 'data' ) { |
|
395
|
|
|
$error_class .= ' frm_dynamic_' . $field['data_type'] . '_container'; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
// Add class to inline Scale field |
|
399
|
|
|
if ( $field['type'] == 'scale' && $field['label'] == 'inline' ) { |
|
400
|
|
|
$error_class .= ' frm_scale_container'; |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
// If this is a Section |
|
404
|
|
|
if ( $field['type'] == 'divider' ) { |
|
405
|
|
|
|
|
406
|
|
|
// If the top margin needs to be removed from a section heading |
|
407
|
|
|
if ( $field['label'] == 'none' ) { |
|
408
|
|
|
$error_class .= ' frm_hide_section'; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
// If this is a repeating section that should be hidden with exclude_fields or fields shortcode, hide it |
|
412
|
|
|
if ( $field['repeat'] ) { |
|
413
|
|
|
global $frm_vars; |
|
414
|
|
|
if ( isset( $frm_vars['show_fields'] ) && ! empty( $frm_vars['show_fields'] ) && ! in_array( $field['id'], $frm_vars['show_fields'] ) && ! in_array( $field['field_key'], $frm_vars['show_fields'] ) ) { |
|
415
|
|
|
$error_class .= ' frm_hidden'; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
//insert custom CSS classes |
|
421
|
|
|
if ( ! empty( $field['classes'] ) ) { |
|
422
|
|
|
if ( ! strpos( $html, 'frm_form_field ') ) { |
|
423
|
|
|
$error_class .= ' frm_form_field'; |
|
424
|
|
|
} |
|
425
|
|
|
$error_class .= ' ' . $field['classes']; |
|
426
|
|
|
} |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
|
430
|
|
|
if ( $no_vars ) { |
|
431
|
|
|
$html = str_replace( '[if ' . $code . ']', '', $html ); |
|
432
|
|
|
$html = str_replace( '[/if ' . $code . ']', '', $html ); |
|
433
|
|
|
} else { |
|
434
|
|
|
$html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html ); |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
$html = str_replace( '[' . $code . ']', $replace_with, $html ); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
|
441
|
|
|
$args = wp_parse_args( $args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false ) ); |
|
442
|
|
|
if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) { |
|
443
|
|
|
$args['conditional_check'] = true; |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
$prefix = ''; |
|
447
|
|
|
if ( $args['conditional_check'] ) { |
|
448
|
|
|
if ( $args['conditional'] ) { |
|
449
|
|
|
$prefix = 'if '; |
|
450
|
|
|
} else if ( $args['foreach'] ) { |
|
451
|
|
|
$prefix = 'foreach '; |
|
452
|
|
|
} |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
$with_tags = $args['conditional_check'] ? 3 : 2; |
|
456
|
|
|
if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { |
|
457
|
|
|
$tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); |
|
458
|
|
|
$tag = str_replace(']', '', $tag); |
|
459
|
|
|
$tags = explode(' ', $tag); |
|
460
|
|
|
if ( is_array($tags) ) { |
|
461
|
|
|
$tag = $tags[0]; |
|
462
|
|
|
} |
|
463
|
|
|
} else { |
|
464
|
|
|
$tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
return $tag; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* Remove [collapse_this] if it's still included after all processing |
|
472
|
|
|
* @since 2.0.8 |
|
473
|
|
|
*/ |
|
474
|
|
|
private static function remove_collapse_shortcode( &$html ) { |
|
475
|
|
|
if ( preg_match( '/\[(collapse_this)\]/s', $html ) ) { |
|
476
|
|
|
$html = str_replace( '[collapse_this]', '', $html ); |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
public static function display_recaptcha( $field ) { |
|
481
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
482
|
|
|
$lang = apply_filters( 'frm_recaptcha_lang', $frm_settings->re_lang, $field ); |
|
483
|
|
|
|
|
484
|
|
|
$class_prefix = ''; |
|
485
|
|
|
$api_js_url = 'https://www.google.com/recaptcha/api.js?'; |
|
486
|
|
|
|
|
487
|
|
|
$allow_mutiple = $frm_settings->re_multi; |
|
|
|
|
|
|
488
|
|
|
if ( $allow_mutiple ) { |
|
489
|
|
|
$api_js_url .= '&onload=frmRecaptcha&render=explicit'; |
|
490
|
|
|
$class_prefix = 'frm-'; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
if ( $lang != 'en' ) { |
|
494
|
|
|
$api_js_url .= '&hl=' . $lang; |
|
495
|
|
|
} |
|
496
|
|
|
$api_js_url = apply_filters( 'frm_recaptcha_js_url', $api_js_url ); |
|
497
|
|
|
|
|
498
|
|
|
wp_register_script( 'recaptcha-api', $api_js_url, '', true ); |
|
499
|
|
|
wp_enqueue_script( 'recaptcha-api' ); |
|
500
|
|
|
|
|
501
|
|
|
?> |
|
502
|
|
|
<div id="field_<?php echo esc_attr( $field['field_key'] ) ?>" class="<?php echo esc_attr( $class_prefix ) ?>g-recaptcha" data-sitekey="<?php echo esc_attr( $frm_settings->pubkey ) ?>" data-size="<?php echo esc_attr( $field['captcha_size'] ) ?>" data-theme="<?php echo esc_attr( $field['captcha_theme'] ) ?>"></div> |
|
503
|
|
|
<?php |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
public static function show_single_option( $field ) { |
|
507
|
|
|
$field_name = $field['name']; |
|
508
|
|
|
$html_id = self::get_html_id($field); |
|
509
|
|
|
foreach ( $field['options'] as $opt_key => $opt ) { |
|
510
|
|
|
$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
511
|
|
|
$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
512
|
|
|
|
|
513
|
|
|
// If this is an "Other" option, get the HTML for it |
|
514
|
|
|
if ( self::is_other_opt( $opt_key ) ) { |
|
515
|
|
|
// Get string for Other text field, if needed |
|
516
|
|
|
$other_val = self::get_other_val( compact( 'opt_key', 'field' ) ); |
|
517
|
|
|
require( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
|
518
|
|
|
} else { |
|
519
|
|
|
require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
|
520
|
|
|
} |
|
521
|
|
|
} |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
public static function dropdown_categories( $args ) { |
|
525
|
|
|
$defaults = array( 'field' => false, 'name' => false, 'show_option_all' => ' ' ); |
|
526
|
|
|
$args = wp_parse_args($args, $defaults); |
|
527
|
|
|
|
|
528
|
|
|
if ( ! $args['field'] ) { |
|
529
|
|
|
return; |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
if ( ! $args['name'] ) { |
|
533
|
|
|
$args['name'] = 'item_meta[' . $args['field']['id'] . ']'; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
$id = self::get_html_id($args['field']); |
|
537
|
|
|
$class = $args['field']['type']; |
|
538
|
|
|
|
|
539
|
|
|
$exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat']; |
|
540
|
|
|
$exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']); |
|
541
|
|
|
|
|
542
|
|
|
if ( is_array($args['field']['value']) ) { |
|
543
|
|
|
if ( ! empty($exclude) ) { |
|
544
|
|
|
$args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude)); |
|
545
|
|
|
} |
|
546
|
|
|
$selected = reset($args['field']['value']); |
|
547
|
|
|
} else { |
|
548
|
|
|
$selected = $args['field']['value']; |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
$tax_atts = array( |
|
552
|
|
|
'show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'], |
|
553
|
|
|
'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, |
|
554
|
|
|
'hide_empty' => false, 'echo' => 0, 'orderby' => 'name', |
|
555
|
|
|
); |
|
556
|
|
|
|
|
557
|
|
|
$tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']); |
|
558
|
|
|
|
|
559
|
|
|
if ( FrmAppHelper::pro_is_installed() ) { |
|
560
|
|
|
$post_type = FrmProFormsHelper::post_type($args['field']['form_id']); |
|
561
|
|
|
$tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']); |
|
562
|
|
|
if ( ! $tax_atts['taxonomy'] ) { |
|
563
|
|
|
return; |
|
564
|
|
|
} |
|
565
|
|
|
|
|
566
|
|
|
// If field type is dropdown (not Dynamic), exclude children when parent is excluded |
|
567
|
|
|
if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) { |
|
568
|
|
|
$tax_atts['exclude_tree'] = $exclude; |
|
569
|
|
|
} |
|
570
|
|
|
} |
|
571
|
|
|
|
|
572
|
|
|
$dropdown = wp_dropdown_categories($tax_atts); |
|
573
|
|
|
|
|
574
|
|
|
$add_html = FrmFieldsController::input_html($args['field'], false); |
|
575
|
|
|
|
|
576
|
|
|
if ( FrmAppHelper::pro_is_installed() ) { |
|
577
|
|
|
$add_html .= FrmProFieldsController::input_html($args['field'], false); |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
$dropdown = str_replace( "<select name='" . esc_attr( $args['name'] ) . "' id='" . esc_attr( $id ) . "' class='" . esc_attr( $class ) . "'", "<select name='" . esc_attr( $args['name'] ) . "' id='" . esc_attr( $id ) . "' " . $add_html, $dropdown ); |
|
581
|
|
|
|
|
582
|
|
|
if ( is_array($args['field']['value']) ) { |
|
583
|
|
|
$skip = true; |
|
584
|
|
|
foreach ( $args['field']['value'] as $v ) { |
|
585
|
|
|
if ( $skip ) { |
|
586
|
|
|
$skip = false; |
|
587
|
|
|
continue; |
|
588
|
|
|
} |
|
589
|
|
|
$dropdown = str_replace(' value="' . esc_attr( $v ) . '"', ' value="' . esc_attr( $v ) . '" selected="selected"', $dropdown ); |
|
590
|
|
|
unset($v); |
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
return $dropdown; |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
public static function get_term_link( $tax_id ) { |
|
598
|
|
|
$tax = get_taxonomy($tax_id); |
|
599
|
|
|
if ( ! $tax ) { |
|
600
|
|
|
return; |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
$link = sprintf( |
|
604
|
|
|
__( 'Please add options from the WordPress "%1$s" page', 'formidable' ), |
|
605
|
|
|
'<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>' |
|
|
|
|
|
|
606
|
|
|
); |
|
607
|
|
|
unset($tax); |
|
608
|
|
|
|
|
609
|
|
|
return $link; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
|
613
|
|
|
// Remove white space from hide_opt |
|
614
|
|
|
if ( ! is_array( $hide_opt ) ) { |
|
615
|
|
|
$hide_opt = rtrim( $hide_opt ); |
|
616
|
|
|
} |
|
617
|
|
|
|
|
618
|
|
|
if ( is_array($observed_value) ) { |
|
619
|
|
|
return self::array_value_condition($observed_value, $cond, $hide_opt); |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
$m = false; |
|
623
|
|
|
if ( $cond == '==' ) { |
|
624
|
|
|
$m = $observed_value == $hide_opt; |
|
625
|
|
|
} else if ( $cond == '!=' ) { |
|
626
|
|
|
$m = $observed_value != $hide_opt; |
|
627
|
|
|
} else if ( $cond == '>' ) { |
|
628
|
|
|
$m = $observed_value > $hide_opt; |
|
629
|
|
|
} else if ( $cond == '<' ) { |
|
630
|
|
|
$m = $observed_value < $hide_opt; |
|
631
|
|
|
} else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
|
632
|
|
|
$m = stripos($observed_value, $hide_opt); |
|
633
|
|
|
if ( $cond == 'not LIKE' ) { |
|
634
|
|
|
$m = ( $m === false ) ? true : false; |
|
635
|
|
|
} else { |
|
636
|
|
|
$m = ( $m === false ) ? false : true; |
|
637
|
|
|
} |
|
638
|
|
|
} |
|
639
|
|
|
return $m; |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
|
643
|
|
|
$m = false; |
|
644
|
|
|
if ( $cond == '==' ) { |
|
645
|
|
|
if ( is_array($hide_opt) ) { |
|
646
|
|
|
$m = array_intersect($hide_opt, $observed_value); |
|
647
|
|
|
$m = empty($m) ? false : true; |
|
648
|
|
|
} else { |
|
649
|
|
|
$m = in_array($hide_opt, $observed_value); |
|
650
|
|
|
} |
|
651
|
|
|
} else if ( $cond == '!=' ) { |
|
652
|
|
|
$m = ! in_array($hide_opt, $observed_value); |
|
653
|
|
|
} else if ( $cond == '>' ) { |
|
654
|
|
|
$min = min($observed_value); |
|
655
|
|
|
$m = $min > $hide_opt; |
|
656
|
|
|
} else if ( $cond == '<' ) { |
|
657
|
|
|
$max = max($observed_value); |
|
658
|
|
|
$m = $max < $hide_opt; |
|
659
|
|
|
} else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
|
660
|
|
|
foreach ( $observed_value as $ob ) { |
|
661
|
|
|
$m = strpos($ob, $hide_opt); |
|
662
|
|
|
if ( $m !== false ) { |
|
663
|
|
|
$m = true; |
|
664
|
|
|
break; |
|
665
|
|
|
} |
|
666
|
|
|
} |
|
667
|
|
|
|
|
668
|
|
|
if ( $cond == 'not LIKE' ) { |
|
669
|
|
|
$m = ( $m === false ) ? true : false; |
|
670
|
|
|
} |
|
671
|
|
|
} |
|
672
|
|
|
|
|
673
|
|
|
return $m; |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
/** |
|
677
|
|
|
* Replace a few basic shortcodes and field ids |
|
678
|
|
|
* @since 2.0 |
|
679
|
|
|
* @return string |
|
680
|
|
|
*/ |
|
681
|
|
|
public static function basic_replace_shortcodes( $value, $form, $entry ) { |
|
682
|
|
|
if ( strpos($value, '[sitename]') !== false ) { |
|
683
|
|
|
$new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
684
|
|
|
$value = str_replace('[sitename]', $new_value, $value); |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
$value = apply_filters('frm_content', $value, $form, $entry); |
|
688
|
|
|
$value = do_shortcode($value); |
|
689
|
|
|
|
|
690
|
|
|
return $value; |
|
691
|
|
|
} |
|
692
|
|
|
|
|
693
|
|
|
public static function get_shortcodes( $content, $form_id ) { |
|
694
|
|
|
if ( FrmAppHelper::pro_is_installed() ) { |
|
695
|
|
|
return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
|
696
|
|
|
} |
|
697
|
|
|
|
|
698
|
|
|
$fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) ); |
|
699
|
|
|
|
|
700
|
|
|
$tagregexp = self::allowed_shortcodes($fields); |
|
701
|
|
|
|
|
702
|
|
|
preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
|
703
|
|
|
|
|
704
|
|
|
return $matches; |
|
705
|
|
|
} |
|
706
|
|
|
|
|
707
|
|
|
public static function allowed_shortcodes( $fields = array() ) { |
|
708
|
|
|
$tagregexp = array( |
|
709
|
|
|
'editlink', 'id', 'key', 'ip', |
|
710
|
|
|
'siteurl', 'sitename', 'admin_email', |
|
711
|
|
|
'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', |
|
712
|
|
|
'parent[-|_]id', |
|
713
|
|
|
); |
|
714
|
|
|
|
|
715
|
|
|
foreach ( $fields as $field ) { |
|
716
|
|
|
$tagregexp[] = $field->id; |
|
717
|
|
|
$tagregexp[] = $field->field_key; |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
$tagregexp = implode('|', $tagregexp); |
|
721
|
|
|
return $tagregexp; |
|
722
|
|
|
} |
|
723
|
|
|
|
|
724
|
|
|
public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
|
725
|
|
|
$shortcode_values = array( |
|
726
|
|
|
'id' => $entry->id, |
|
727
|
|
|
'key' => $entry->item_key, |
|
728
|
|
|
'ip' => $entry->ip, |
|
729
|
|
|
); |
|
730
|
|
|
|
|
731
|
|
|
foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
732
|
|
|
$atts = shortcode_parse_atts( $shortcodes[3][ $short_key ] ); |
|
733
|
|
|
|
|
734
|
|
|
if ( ! empty( $shortcodes[3][ $short_key ] ) ) { |
|
735
|
|
|
$tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] ); |
|
736
|
|
|
$tags = explode(' ', $tag); |
|
737
|
|
|
if ( is_array($tags) ) { |
|
738
|
|
|
$tag = $tags[0]; |
|
739
|
|
|
} |
|
740
|
|
|
} else { |
|
741
|
|
|
$tag = $shortcodes[2][ $short_key ]; |
|
742
|
|
|
} |
|
743
|
|
|
|
|
744
|
|
|
switch ( $tag ) { |
|
745
|
|
|
case 'id': |
|
746
|
|
|
case 'key': |
|
747
|
|
|
case 'ip': |
|
748
|
|
|
$replace_with = $shortcode_values[ $tag ]; |
|
749
|
|
|
break; |
|
750
|
|
|
|
|
751
|
|
|
case 'user_agent': |
|
752
|
|
|
case 'user-agent': |
|
753
|
|
|
$entry->description = maybe_unserialize($entry->description); |
|
754
|
|
|
$replace_with = FrmEntryFormat::get_browser( $entry->description['browser'] ); |
|
755
|
|
|
break; |
|
756
|
|
|
|
|
757
|
|
|
case 'created_at': |
|
758
|
|
|
case 'created-at': |
|
759
|
|
|
case 'updated_at': |
|
760
|
|
|
case 'updated-at': |
|
761
|
|
|
if ( isset($atts['format']) ) { |
|
762
|
|
|
$time_format = ' '; |
|
763
|
|
|
} else { |
|
764
|
|
|
$atts['format'] = get_option('date_format'); |
|
765
|
|
|
$time_format = ''; |
|
766
|
|
|
} |
|
767
|
|
|
|
|
768
|
|
|
$this_tag = str_replace('-', '_', $tag); |
|
769
|
|
|
$replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format); |
|
770
|
|
|
unset($this_tag); |
|
771
|
|
|
break; |
|
772
|
|
|
|
|
773
|
|
|
case 'created_by': |
|
774
|
|
|
case 'created-by': |
|
775
|
|
|
case 'updated_by': |
|
776
|
|
|
case 'updated-by': |
|
777
|
|
|
$this_tag = str_replace('-', '_', $tag); |
|
778
|
|
|
$replace_with = self::get_display_value( $entry->{$this_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
|
779
|
|
|
unset($this_tag); |
|
780
|
|
|
break; |
|
781
|
|
|
|
|
782
|
|
|
case 'admin_email': |
|
783
|
|
|
case 'siteurl': |
|
784
|
|
|
case 'frmurl': |
|
785
|
|
|
case 'sitename': |
|
786
|
|
|
case 'get': |
|
787
|
|
|
$replace_with = self::dynamic_default_values( $tag, $atts ); |
|
788
|
|
|
break; |
|
789
|
|
|
|
|
790
|
|
|
default: |
|
791
|
|
|
$field = FrmField::getOne( $tag ); |
|
792
|
|
|
if ( ! $field ) { |
|
793
|
|
|
break; |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
|
|
$sep = isset($atts['sep']) ? $atts['sep'] : ', '; |
|
797
|
|
|
|
|
798
|
|
|
$replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id ); |
|
799
|
|
|
|
|
800
|
|
|
$atts['entry_id'] = $entry->id; |
|
801
|
|
|
$atts['entry_key'] = $entry->item_key; |
|
802
|
|
|
|
|
803
|
|
|
if ( isset($atts['show']) && $atts['show'] == 'field_label' ) { |
|
804
|
|
|
$replace_with = $field->name; |
|
805
|
|
|
} else if ( isset($atts['show']) && $atts['show'] == 'description' ) { |
|
806
|
|
|
$replace_with = $field->description; |
|
807
|
|
|
} else { |
|
808
|
|
|
$string_value = $replace_with; |
|
809
|
|
|
if ( is_array( $replace_with ) ) { |
|
810
|
|
|
$string_value = implode( $sep, $replace_with ); |
|
811
|
|
|
} |
|
812
|
|
|
|
|
813
|
|
|
if ( empty( $string_value ) && $string_value != '0' ) { |
|
814
|
|
|
$replace_with = ''; |
|
815
|
|
|
} else { |
|
816
|
|
|
$replace_with = self::get_display_value( $replace_with, $field, $atts ); |
|
817
|
|
|
} |
|
818
|
|
|
} |
|
819
|
|
|
|
|
820
|
|
|
unset($field); |
|
821
|
|
|
break; |
|
822
|
|
|
} |
|
823
|
|
|
|
|
824
|
|
|
if ( isset($replace_with) ) { |
|
825
|
|
|
$content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
|
826
|
|
|
} |
|
827
|
|
|
|
|
828
|
|
|
unset($atts, $conditional, $replace_with); |
|
829
|
|
|
} |
|
830
|
|
|
|
|
831
|
|
|
return $content; |
|
832
|
|
|
} |
|
833
|
|
|
|
|
834
|
|
|
/** |
|
835
|
|
|
* Get the value to replace a few standard shortcodes |
|
836
|
|
|
* |
|
837
|
|
|
* @since 2.0 |
|
838
|
|
|
* @return string |
|
839
|
|
|
*/ |
|
840
|
|
|
public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
|
841
|
|
|
$new_value = ''; |
|
842
|
|
|
switch ( $tag ) { |
|
843
|
|
|
case 'admin_email': |
|
844
|
|
|
$new_value = get_option('admin_email'); |
|
845
|
|
|
break; |
|
846
|
|
|
case 'siteurl': |
|
847
|
|
|
$new_value = FrmAppHelper::site_url(); |
|
848
|
|
|
break; |
|
849
|
|
|
case 'frmurl': |
|
850
|
|
|
$new_value = FrmAppHelper::plugin_url(); |
|
851
|
|
|
break; |
|
852
|
|
|
case 'sitename': |
|
853
|
|
|
$new_value = FrmAppHelper::site_name(); |
|
854
|
|
|
break; |
|
855
|
|
|
case 'get': |
|
856
|
|
|
$new_value = self::process_get_shortcode( $atts, $return_array ); |
|
857
|
|
|
break; |
|
858
|
|
|
} |
|
859
|
|
|
|
|
860
|
|
|
return $new_value; |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
/** |
|
864
|
|
|
* Process the [get] shortcode |
|
865
|
|
|
* |
|
866
|
|
|
* @since 2.0 |
|
867
|
|
|
* @return string|array |
|
868
|
|
|
*/ |
|
869
|
|
|
public static function process_get_shortcode( $atts, $return_array = false ) { |
|
870
|
|
|
if ( ! isset($atts['param']) ) { |
|
871
|
|
|
return ''; |
|
872
|
|
|
} |
|
873
|
|
|
|
|
874
|
|
|
if ( strpos($atts['param'], '[') ) { |
|
875
|
|
|
$atts['param'] = str_replace('[', '[', $atts['param']); |
|
876
|
|
|
$atts['param'] = str_replace(']', ']', $atts['param']); |
|
877
|
|
|
} |
|
878
|
|
|
|
|
879
|
|
|
$new_value = FrmAppHelper::get_param($atts['param'], ''); |
|
880
|
|
|
$new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
|
881
|
|
|
|
|
882
|
|
|
if ( $new_value == '' ) { |
|
883
|
|
|
if ( ! isset($atts['prev_val']) ) { |
|
884
|
|
|
$atts['prev_val'] = ''; |
|
885
|
|
|
} |
|
886
|
|
|
|
|
887
|
|
|
$new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
|
888
|
|
|
} |
|
889
|
|
|
|
|
890
|
|
|
if ( is_array($new_value) && ! $return_array ) { |
|
891
|
|
|
$new_value = implode(', ', $new_value); |
|
892
|
|
|
} |
|
893
|
|
|
|
|
894
|
|
|
return $new_value; |
|
895
|
|
|
} |
|
896
|
|
|
|
|
897
|
|
|
public static function get_display_value( $replace_with, $field, $atts = array() ) { |
|
898
|
|
|
$atts['sep'] = isset( $atts['sep'] ) ? $atts['sep'] : ', '; |
|
899
|
|
|
|
|
900
|
|
|
$replace_with = apply_filters( 'frm_get_' . $field->type . '_display_value', $replace_with, $field, $atts ); |
|
901
|
|
|
$replace_with = apply_filters( 'frm_get_display_value', $replace_with, $field, $atts ); |
|
902
|
|
|
|
|
903
|
|
|
if ( $field->type == 'textarea' || $field->type == 'rte' ) { |
|
904
|
|
|
$autop = isset($atts['wpautop']) ? $atts['wpautop'] : true; |
|
905
|
|
|
if ( apply_filters('frm_use_wpautop', $autop) ) { |
|
906
|
|
|
if ( is_array($replace_with) ) { |
|
907
|
|
|
$replace_with = implode("\n", $replace_with); |
|
908
|
|
|
} |
|
909
|
|
|
$replace_with = wpautop($replace_with); |
|
910
|
|
|
} |
|
911
|
|
|
unset( $autop ); |
|
912
|
|
|
} else if ( is_array( $replace_with ) ) { |
|
913
|
|
|
$replace_with = implode( $atts['sep'], $replace_with ); |
|
914
|
|
|
} |
|
915
|
|
|
|
|
916
|
|
|
return $replace_with; |
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
public static function get_field_types( $type ) { |
|
920
|
|
|
$single_input = array( |
|
921
|
|
|
'text', 'textarea', 'rte', 'number', 'email', 'url', |
|
922
|
|
|
'image', 'file', 'date', 'phone', 'hidden', 'time', |
|
923
|
|
|
'user_id', 'tag', 'password', |
|
924
|
|
|
); |
|
925
|
|
|
$multiple_input = array( 'radio', 'checkbox', 'select', 'scale' ); |
|
926
|
|
|
$other_type = array( 'divider', 'html', 'break' ); |
|
927
|
|
|
|
|
928
|
|
|
$field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() ); |
|
929
|
|
|
|
|
930
|
|
|
$field_types = array(); |
|
931
|
|
|
if ( in_array($type, $single_input) ) { |
|
932
|
|
|
self::field_types_for_input( $single_input, $field_selection, $field_types ); |
|
933
|
|
|
} else if ( in_array($type, $multiple_input) ) { |
|
934
|
|
|
self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
|
935
|
|
|
} else if ( in_array($type, $other_type) ) { |
|
936
|
|
|
self::field_types_for_input( $other_type, $field_selection, $field_types ); |
|
937
|
|
|
} else if ( isset( $field_selection[ $type ] ) ) { |
|
938
|
|
|
$field_types[ $type ] = $field_selection[ $type ]; |
|
939
|
|
|
} |
|
940
|
|
|
|
|
941
|
|
|
return $field_types; |
|
942
|
|
|
} |
|
943
|
|
|
|
|
944
|
|
|
private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
|
945
|
|
|
foreach ( $inputs as $input ) { |
|
946
|
|
|
$field_types[ $input ] = $fields[ $input ]; |
|
947
|
|
|
unset($input); |
|
948
|
|
|
} |
|
949
|
|
|
} |
|
950
|
|
|
|
|
951
|
|
|
/** |
|
952
|
|
|
* Check if current field option is an "other" option |
|
953
|
|
|
* |
|
954
|
|
|
* @since 2.0.6 |
|
955
|
|
|
* |
|
956
|
|
|
* @param string $opt_key |
|
957
|
|
|
* @return boolean Returns true if current field option is an "Other" option |
|
958
|
|
|
*/ |
|
959
|
|
|
public static function is_other_opt( $opt_key ) { |
|
960
|
|
|
return $opt_key && strpos( $opt_key, 'other' ) !== false; |
|
961
|
|
|
} |
|
962
|
|
|
|
|
963
|
|
|
/** |
|
964
|
|
|
* Get value that belongs in "Other" text box |
|
965
|
|
|
* |
|
966
|
|
|
* @since 2.0.6 |
|
967
|
|
|
* |
|
968
|
|
|
* @param array $args |
|
969
|
|
|
*/ |
|
970
|
|
|
public static function get_other_val( $args ) { |
|
971
|
|
|
$defaults = array( |
|
972
|
|
|
'opt_key' => 0, 'field' => array(), |
|
973
|
|
|
'parent' => false, 'pointer' => false, |
|
974
|
|
|
); |
|
975
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
976
|
|
|
|
|
977
|
|
|
$opt_key = $args['opt_key']; |
|
978
|
|
|
$field = $args['field']; |
|
979
|
|
|
$parent = $args['parent']; |
|
980
|
|
|
$pointer = $args['pointer']; |
|
981
|
|
|
$other_val = ''; |
|
982
|
|
|
|
|
983
|
|
|
// If option is an "other" option and there is a value set for this field, |
|
984
|
|
|
// check if the value belongs in the current "Other" option text field |
|
985
|
|
|
if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) { |
|
986
|
|
|
return $other_val; |
|
987
|
|
|
} |
|
988
|
|
|
|
|
989
|
|
|
// Check posted vals before checking saved values |
|
990
|
|
|
|
|
991
|
|
|
// For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
|
992
|
|
|
if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { |
|
993
|
|
|
if ( FrmField::is_field_with_multiple_values( $field ) ) { |
|
994
|
|
|
$other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) : ''; |
|
|
|
|
|
|
995
|
|
|
} else { |
|
996
|
|
|
$other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ); |
|
|
|
|
|
|
997
|
|
|
} |
|
998
|
|
|
return $other_val; |
|
999
|
|
|
|
|
1000
|
|
|
} else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { |
|
1001
|
|
|
// For normal fields |
|
1002
|
|
|
|
|
1003
|
|
|
if ( FrmField::is_field_with_multiple_values( $field ) ) { |
|
1004
|
|
|
$other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) : ''; |
|
|
|
|
|
|
1005
|
|
|
} else { |
|
1006
|
|
|
$other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] ); |
|
|
|
|
|
|
1007
|
|
|
} |
|
1008
|
|
|
return $other_val; |
|
1009
|
|
|
} |
|
1010
|
|
|
|
|
1011
|
|
|
// For checkboxes |
|
1012
|
|
|
if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) { |
|
1013
|
|
|
// Check if there is an "other" val in saved value and make sure the |
|
1014
|
|
|
// "other" val is not equal to the Other checkbox option |
|
1015
|
|
|
if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) { |
|
1016
|
|
|
$other_val = $field['value'][ $opt_key ]; |
|
1017
|
|
|
} |
|
1018
|
|
|
} else { |
|
1019
|
|
|
/** |
|
1020
|
|
|
* For radio buttons and dropdowns |
|
1021
|
|
|
* Check if saved value equals any of the options. If not, set it as the other value. |
|
1022
|
|
|
*/ |
|
1023
|
|
|
foreach ( $field['options'] as $opt_key => $opt_val ) { |
|
1024
|
|
|
$temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val; |
|
1025
|
|
|
// Multi-select dropdowns - key is not preserved |
|
1026
|
|
|
if ( is_array( $field['value'] ) ) { |
|
1027
|
|
|
$o_key = array_search( $temp_val, $field['value'] ); |
|
1028
|
|
|
if ( isset( $field['value'][ $o_key ] ) ) { |
|
1029
|
|
|
unset( $field['value'][ $o_key ], $o_key ); |
|
1030
|
|
|
} |
|
1031
|
|
|
} else if ( $temp_val == $field['value'] ) { |
|
1032
|
|
|
// For radio and regular dropdowns |
|
1033
|
|
|
return ''; |
|
1034
|
|
|
} else { |
|
1035
|
|
|
$other_val = $field['value']; |
|
1036
|
|
|
} |
|
1037
|
|
|
unset( $opt_key, $opt_val, $temp_val ); |
|
1038
|
|
|
} |
|
1039
|
|
|
// For multi-select dropdowns only |
|
1040
|
|
|
if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) { |
|
1041
|
|
|
$other_val = reset( $field['value'] ); |
|
1042
|
|
|
} |
|
1043
|
|
|
} |
|
1044
|
|
|
|
|
1045
|
|
|
return $other_val; |
|
1046
|
|
|
} |
|
1047
|
|
|
|
|
1048
|
|
|
/** |
|
1049
|
|
|
* Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
1050
|
|
|
* Intended for front-end use |
|
1051
|
|
|
* |
|
1052
|
|
|
* @since 2.0.6 |
|
1053
|
|
|
* |
|
1054
|
|
|
* @param array $args should include field, opt_key and field name |
|
1055
|
|
|
* @param boolean $other_opt |
|
1056
|
|
|
* @param string $checked |
|
1057
|
|
|
* @return string $other_val |
|
1058
|
|
|
*/ |
|
1059
|
|
|
public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
|
1060
|
|
|
//Check if this is an "Other" option |
|
1061
|
|
|
if ( ! self::is_other_opt( $args['opt_key'] ) ) { |
|
1062
|
|
|
return; |
|
1063
|
|
|
} |
|
1064
|
|
|
|
|
1065
|
|
|
$other_opt = true; |
|
1066
|
|
|
$other_args = array(); |
|
1067
|
|
|
|
|
1068
|
|
|
self::set_other_name( $args, $other_args ); |
|
1069
|
|
|
self::set_other_value( $args, $other_args ); |
|
1070
|
|
|
|
|
1071
|
|
|
if ( $other_args['value'] ) { |
|
1072
|
|
|
$checked = 'checked="checked" '; |
|
1073
|
|
|
} |
|
1074
|
|
|
|
|
1075
|
|
|
return $other_args; |
|
1076
|
|
|
} |
|
1077
|
|
|
|
|
1078
|
|
|
/** |
|
1079
|
|
|
* @param array $args |
|
1080
|
|
|
* @param array $other_args |
|
1081
|
|
|
* @since 2.0.6 |
|
1082
|
|
|
*/ |
|
1083
|
|
|
private static function set_other_name( $args, &$other_args ) { |
|
1084
|
|
|
//Set up name for other field |
|
1085
|
|
|
$other_args['name'] = str_replace( '[]', '', $args['field_name'] ); |
|
1086
|
|
|
$other_args['name'] = preg_replace('/\[' . $args['field']['id'] . '\]$/', '', $other_args['name']); |
|
1087
|
|
|
$other_args['name'] = $other_args['name'] . '[other]' . '[' . $args['field']['id'] . ']'; |
|
1088
|
|
|
|
|
1089
|
|
|
//Converts item_meta[field_id] => item_meta[other][field_id] and |
|
1090
|
|
|
//item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] |
|
1091
|
|
|
if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) { |
|
1092
|
|
|
$other_args['name'] .= '[' . $args['opt_key'] . ']'; |
|
1093
|
|
|
} |
|
1094
|
|
|
} |
|
1095
|
|
|
|
|
1096
|
|
|
/** |
|
1097
|
|
|
* Find the parent and pointer, and get text for "other" text field |
|
1098
|
|
|
* @param array $args |
|
1099
|
|
|
* @param array $other_args |
|
1100
|
|
|
* |
|
1101
|
|
|
* @since 2.0.6 |
|
1102
|
|
|
*/ |
|
1103
|
|
|
private static function set_other_value( $args, &$other_args ) { |
|
1104
|
|
|
$parent = $pointer = ''; |
|
1105
|
|
|
|
|
1106
|
|
|
// Check for parent ID and pointer |
|
1107
|
|
|
$temp_array = explode( '[', $args['field_name'] ); |
|
1108
|
|
|
|
|
1109
|
|
|
// Count should only be greater than 3 if inside of a repeating section |
|
1110
|
|
|
if ( count( $temp_array ) > 3 ) { |
|
1111
|
|
|
$parent = str_replace( ']', '', $temp_array[1] ); |
|
1112
|
|
|
$pointer = str_replace( ']', '', $temp_array[2]); |
|
1113
|
|
|
} |
|
1114
|
|
|
|
|
1115
|
|
|
// Get text for "other" text field |
|
1116
|
|
|
$other_args['value'] = self::get_other_val( array( 'opt_key' => $args['opt_key'], 'field' => $args['field'], 'parent' => $parent, 'pointer' => $pointer ) ); |
|
1117
|
|
|
} |
|
1118
|
|
|
|
|
1119
|
|
|
/** |
|
1120
|
|
|
* If this field includes an other option, show it |
|
1121
|
|
|
* @param $args array |
|
1122
|
|
|
* @since 2.0.6 |
|
1123
|
|
|
*/ |
|
1124
|
|
|
public static function include_other_input( $args ) { |
|
1125
|
|
|
if ( ! $args['other_opt'] ) { |
|
1126
|
|
|
return; |
|
1127
|
|
|
} |
|
1128
|
|
|
|
|
1129
|
|
|
$classes = array( 'frm_other_input' ); |
|
1130
|
|
|
if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) { |
|
1131
|
|
|
// hide the field if the other option is not selected |
|
1132
|
|
|
$classes[] = 'frm_pos_none'; |
|
1133
|
|
|
} |
|
1134
|
|
|
if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) { |
|
1135
|
|
|
$classes[] = 'frm_other_full'; |
|
1136
|
|
|
} |
|
1137
|
|
|
|
|
1138
|
|
|
// Set up HTML ID for Other field |
|
1139
|
|
|
$other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] ); |
|
1140
|
|
|
|
|
1141
|
|
|
?><input type="text" id="<?php echo esc_attr( $other_id ) ?>" class="<?php echo sanitize_text_field( implode( ' ', $classes ) ) ?>" <?php |
|
1142
|
|
|
echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ); |
|
|
|
|
|
|
1143
|
|
|
?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>" /><?php |
|
1144
|
|
|
} |
|
1145
|
|
|
|
|
1146
|
|
|
/** |
|
1147
|
|
|
* Get the HTML id for an "Other" text field |
|
1148
|
|
|
* Note: This does not affect fields in repeating sections |
|
1149
|
|
|
* |
|
1150
|
|
|
* @since 2.0.08 |
|
1151
|
|
|
* @param string $type - field type |
|
1152
|
|
|
* @param string $html_id |
|
1153
|
|
|
* @param string|boolean $opt_key |
|
1154
|
|
|
* @return string $other_id |
|
1155
|
|
|
*/ |
|
1156
|
|
|
public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
|
1157
|
|
|
$other_id = $html_id; |
|
1158
|
|
|
|
|
1159
|
|
|
// If hidden radio field, add an opt key of 0 |
|
1160
|
|
|
if ( $type == 'radio' && $opt_key === false ) { |
|
1161
|
|
|
$opt_key = 0; |
|
1162
|
|
|
} |
|
1163
|
|
|
|
|
1164
|
|
|
if ( $opt_key !== false ) { |
|
1165
|
|
|
$other_id .= '-' . $opt_key; |
|
1166
|
|
|
} |
|
1167
|
|
|
|
|
1168
|
|
|
$other_id .= '-otext'; |
|
1169
|
|
|
|
|
1170
|
|
|
return $other_id; |
|
1171
|
|
|
} |
|
1172
|
|
|
|
|
1173
|
|
|
public static function clear_on_focus_html( $field, $display, $id = '' ) { |
|
1174
|
|
|
if ( $display['clear_on_focus'] ) { |
|
1175
|
|
|
echo '<span id="frm_clear_on_focus_' . esc_attr( $field['id'] . $id ) . '" class="frm-show-click">'; |
|
1176
|
|
|
|
|
1177
|
|
|
if ( $display['default_blank'] ) { |
|
1178
|
|
|
self::show_default_blank_js( $field['default_blank'] ); |
|
1179
|
|
|
echo '<input type="hidden" name="field_options[default_blank_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['default_blank'] ) . '" />'; |
|
1180
|
|
|
} |
|
1181
|
|
|
|
|
1182
|
|
|
self::show_onfocus_js( $field['clear_on_focus'] ); |
|
1183
|
|
|
echo '<input type="hidden" name="field_options[clear_on_focus_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['clear_on_focus'] ) . '" />'; |
|
1184
|
|
|
|
|
1185
|
|
|
echo '</span>'; |
|
1186
|
|
|
} |
|
1187
|
|
|
} |
|
1188
|
|
|
|
|
1189
|
|
View Code Duplication |
public static function show_onfocus_js( $is_selected ) { |
|
|
|
|
|
|
1190
|
|
|
$atts = array( |
|
1191
|
|
|
'icon' => 'frm_reload_icon', |
|
1192
|
|
|
'message' => $is_selected ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' ), |
|
1193
|
|
|
'is_selected' => $is_selected, |
|
1194
|
|
|
); |
|
1195
|
|
|
self::show_icon_link_js( $atts ); |
|
1196
|
|
|
} |
|
1197
|
|
|
|
|
1198
|
|
View Code Duplication |
public static function show_default_blank_js( $is_selected ) { |
|
|
|
|
|
|
1199
|
|
|
$atts = array( |
|
1200
|
|
|
'icon' => 'frm_error_icon', |
|
1201
|
|
|
'message' => $is_selected ? __( 'Default value will NOT pass form validation', 'formidable' ) : __( 'Default value will pass form validation', 'formidable' ), |
|
1202
|
|
|
'is_selected' => $is_selected, |
|
1203
|
|
|
); |
|
1204
|
|
|
self::show_icon_link_js( $atts ); |
|
1205
|
|
|
} |
|
1206
|
|
|
|
|
1207
|
|
|
public static function show_icon_link_js( $atts ) { |
|
1208
|
|
|
$atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon '; |
|
1209
|
|
|
?><a href="javascript:void(0)" class="frm_bstooltip <?php echo esc_attr( $atts['icon'] ); ?>frm_default_val_icons frm_action_icon frm_icon_font" title="<?php echo esc_attr( $atts['message'] ); ?>"></a><?php |
|
1210
|
|
|
} |
|
1211
|
|
|
|
|
1212
|
|
|
public static function switch_field_ids( $val ) { |
|
1213
|
|
|
global $frm_duplicate_ids; |
|
1214
|
|
|
$replace = array(); |
|
1215
|
|
|
$replace_with = array(); |
|
1216
|
|
|
foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
|
1217
|
|
|
$replace[] = '[if ' . $old . ']'; |
|
1218
|
|
|
$replace_with[] = '[if ' . $new . ']'; |
|
1219
|
|
|
$replace[] = '[if ' . $old . ' '; |
|
1220
|
|
|
$replace_with[] = '[if ' . $new . ' '; |
|
1221
|
|
|
$replace[] = '[/if ' . $old . ']'; |
|
1222
|
|
|
$replace_with[] = '[/if ' . $new . ']'; |
|
1223
|
|
|
$replace[] = '[foreach ' . $old . ']'; |
|
1224
|
|
|
$replace_with[] = '[foreach ' . $new . ']'; |
|
1225
|
|
|
$replace[] = '[/foreach ' . $old . ']'; |
|
1226
|
|
|
$replace_with[] = '[/foreach ' . $new . ']'; |
|
1227
|
|
|
$replace[] = '[' . $old . ']'; |
|
1228
|
|
|
$replace_with[] = '[' . $new . ']'; |
|
1229
|
|
|
$replace[] = '[' . $old . ' '; |
|
1230
|
|
|
$replace_with[] = '[' . $new . ' '; |
|
1231
|
|
|
unset($old, $new); |
|
1232
|
|
|
} |
|
1233
|
|
|
if ( is_array( $val ) ) { |
|
1234
|
|
|
foreach ( $val as $k => $v ) { |
|
1235
|
|
|
$val[ $k ] = str_replace( $replace, $replace_with, $v ); |
|
1236
|
|
|
unset($k, $v); |
|
1237
|
|
|
} |
|
1238
|
|
|
} else { |
|
1239
|
|
|
$val = str_replace($replace, $replace_with, $val); |
|
1240
|
|
|
} |
|
1241
|
|
|
|
|
1242
|
|
|
return $val; |
|
1243
|
|
|
} |
|
1244
|
|
|
|
|
1245
|
|
|
public static function get_us_states() { |
|
1246
|
|
|
return apply_filters( 'frm_us_states', array( |
|
1247
|
|
|
'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona', |
|
1248
|
|
|
'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', |
|
1249
|
|
|
'DC' => 'District of Columbia', |
|
1250
|
|
|
'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', |
|
1251
|
|
|
'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', |
|
1252
|
|
|
'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland', |
|
1253
|
|
|
'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', |
|
1254
|
|
|
'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', |
|
1255
|
|
|
'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', |
|
1256
|
|
|
'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', |
|
1257
|
|
|
'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', |
|
1258
|
|
|
'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', |
|
1259
|
|
|
'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', |
|
1260
|
|
|
'WI' => 'Wisconsin', 'WY' => 'Wyoming', |
|
1261
|
|
|
) ); |
|
1262
|
|
|
} |
|
1263
|
|
|
|
|
1264
|
|
|
public static function get_countries() { |
|
1265
|
|
|
return apply_filters( 'frm_countries', array( |
|
1266
|
|
|
__( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ), |
|
1267
|
|
|
__( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ), |
|
1268
|
|
|
__( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ), |
|
1269
|
|
|
__( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ), |
|
1270
|
|
|
__( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ), |
|
1271
|
|
|
__( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ), |
|
1272
|
|
|
__( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ), |
|
1273
|
|
|
__( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ), |
|
1274
|
|
|
__( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ), |
|
1275
|
|
|
__( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ), |
|
1276
|
|
|
__( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ), |
|
1277
|
|
|
__( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ), |
|
1278
|
|
|
__( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ), |
|
1279
|
|
|
__( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ), |
|
1280
|
|
|
__( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ), |
|
1281
|
|
|
__( 'Costa Rica', 'formidable' ), __( 'Côte d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ), |
|
1282
|
|
|
__( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ), |
|
1283
|
|
|
__( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ), |
|
1284
|
|
|
__( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ), |
|
1285
|
|
|
__( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ), |
|
1286
|
|
|
__( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ), |
|
1287
|
|
|
__( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ), |
|
1288
|
|
|
__( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ), |
|
1289
|
|
|
__( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ), |
|
1290
|
|
|
__( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ), |
|
1291
|
|
|
__( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ), |
|
1292
|
|
|
__( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ), |
|
1293
|
|
|
__( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ), |
|
1294
|
|
|
__( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ), |
|
1295
|
|
|
__( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ), |
|
1296
|
|
|
__( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ), |
|
1297
|
|
|
__( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ), |
|
1298
|
|
|
__( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ), |
|
1299
|
|
|
__( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ), |
|
1300
|
|
|
__( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ), |
|
1301
|
|
|
__( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ), |
|
1302
|
|
|
__( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ), |
|
1303
|
|
|
__( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ), |
|
1304
|
|
|
__( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ), |
|
1305
|
|
|
__( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ), |
|
1306
|
|
|
__( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ), |
|
1307
|
|
|
__( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ), |
|
1308
|
|
|
__( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ), |
|
1309
|
|
|
__( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ), |
|
1310
|
|
|
__( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ), |
|
1311
|
|
|
__( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ), |
|
1312
|
|
|
__( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ), |
|
1313
|
|
|
__( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ), |
|
1314
|
|
|
__( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ), |
|
1315
|
|
|
__( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ), |
|
1316
|
|
|
__( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ), |
|
1317
|
|
|
__( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ), |
|
1318
|
|
|
__( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ), |
|
1319
|
|
|
__( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ), |
|
1320
|
|
|
__( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ), |
|
1321
|
|
|
__( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ), |
|
1322
|
|
|
__( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ), |
|
1323
|
|
|
__( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ), |
|
1324
|
|
|
__( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ), |
|
1325
|
|
|
__( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ), |
|
1326
|
|
|
__( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ), |
|
1327
|
|
|
__( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ), |
|
1328
|
|
|
__( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ), |
|
1329
|
|
|
__( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ), |
|
1330
|
|
|
__( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ), |
|
1331
|
|
|
__( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ), |
|
1332
|
|
|
__( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ), |
|
1333
|
|
|
__( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ), |
|
1334
|
|
|
__( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ), |
|
1335
|
|
|
__( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ), |
|
1336
|
|
|
__( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ), |
|
1337
|
|
|
__( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ), |
|
1338
|
|
|
__( 'Zimbabwe', 'formidable' ), |
|
1339
|
|
|
) ); |
|
1340
|
|
|
} |
|
1341
|
|
|
|
|
1342
|
|
|
public static function get_bulk_prefilled_opts( array &$prepop ) { |
|
1343
|
|
|
$prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries(); |
|
1344
|
|
|
|
|
1345
|
|
|
$states = FrmFieldsHelper::get_us_states(); |
|
1346
|
|
|
$state_abv = array_keys($states); |
|
1347
|
|
|
sort($state_abv); |
|
1348
|
|
|
$prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv; |
|
1349
|
|
|
|
|
1350
|
|
|
$states = array_values($states); |
|
1351
|
|
|
sort($states); |
|
1352
|
|
|
$prepop[ __( 'U.S. States', 'formidable' ) ] = $states; |
|
1353
|
|
|
unset($state_abv, $states); |
|
1354
|
|
|
|
|
1355
|
|
|
$prepop[ __( 'Age', 'formidable' ) ] = array( |
|
1356
|
|
|
__( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ), |
|
1357
|
|
|
__( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ), |
|
1358
|
|
|
__( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ), |
|
1359
|
|
|
); |
|
1360
|
|
|
|
|
1361
|
|
|
$prepop[ __( 'Satisfaction', 'formidable' ) ] = array( |
|
1362
|
|
|
__( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1363
|
|
|
__( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1364
|
|
|
); |
|
1365
|
|
|
|
|
1366
|
|
|
$prepop[ __( 'Importance', 'formidable' ) ] = array( |
|
1367
|
|
|
__( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1368
|
|
|
__( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1369
|
|
|
); |
|
1370
|
|
|
|
|
1371
|
|
|
$prepop[ __( 'Agreement', 'formidable' ) ] = array( |
|
1372
|
|
|
__( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1373
|
|
|
__( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1374
|
|
|
); |
|
1375
|
|
|
|
|
1376
|
|
|
$prepop = apply_filters( 'frm_bulk_field_choices', $prepop ); |
|
1377
|
|
|
} |
|
1378
|
|
|
|
|
1379
|
|
|
public static function field_selection() { |
|
1380
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::field_selection' ); |
|
1381
|
|
|
return FrmField::field_selection(); |
|
1382
|
|
|
} |
|
1383
|
|
|
|
|
1384
|
|
|
public static function pro_field_selection() { |
|
1385
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::pro_field_selection' ); |
|
1386
|
|
|
return FrmField::pro_field_selection(); |
|
1387
|
|
|
} |
|
1388
|
|
|
|
|
1389
|
|
|
public static function is_no_save_field( $type ) { |
|
1390
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::is_no_save_field' ); |
|
1391
|
|
|
return FrmField::is_no_save_field( $type ); |
|
1392
|
|
|
} |
|
1393
|
|
|
|
|
1394
|
|
|
public static function no_save_fields() { |
|
1395
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::no_save_fields' ); |
|
1396
|
|
|
return FrmField::no_save_fields(); |
|
1397
|
|
|
} |
|
1398
|
|
|
|
|
1399
|
|
|
public static function is_multiple_select( $field ) { |
|
1400
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::is_multiple_select' ); |
|
1401
|
|
|
return FrmField::is_multiple_select( $field ); |
|
1402
|
|
|
} |
|
1403
|
|
|
|
|
1404
|
|
|
public static function is_field_with_multiple_values( $field ) { |
|
1405
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::is_field_with_multiple_values' ); |
|
1406
|
|
|
return FrmField::is_field_with_multiple_values( $field ); |
|
1407
|
|
|
} |
|
1408
|
|
|
|
|
1409
|
|
|
public static function is_required_field( $field ) { |
|
1410
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::is_required' ); |
|
1411
|
|
|
return FrmField::is_required( $field ); |
|
1412
|
|
|
} |
|
1413
|
|
|
|
|
1414
|
|
|
public static function maybe_get_field( &$field ) { |
|
1415
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::maybe_get_field' ); |
|
1416
|
|
|
FrmField::maybe_get_field( $field ); |
|
1417
|
|
|
} |
|
1418
|
|
|
} |
|
1419
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.