legacy
6 years ago
class-evf-background-process.php
7 years ago
class-evf-deprecated-hooks.php
6 years ago
class-evf-form-fields.php
2 years ago
class-evf-integration.php
5 years ago
class-evf-log-handler.php
6 years ago
class-evf-session.php
8 years ago
class-evf-settings-api.php
4 years ago
class-evf-form-fields.php
2727 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Abstract EVF_Form_Fields Class |
| 4 | * |
| 5 | * @version 1.0.0 |
| 6 | * @package EverestFroms/Abstracts |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Form fields class. |
| 13 | */ |
| 14 | abstract class EVF_Form_Fields { |
| 15 | |
| 16 | /** |
| 17 | * Field name. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | public $name; |
| 22 | |
| 23 | /** |
| 24 | * Field type. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | public $type; |
| 29 | |
| 30 | /** |
| 31 | * Field icon. |
| 32 | * |
| 33 | * @var mixed |
| 34 | */ |
| 35 | public $icon = ''; |
| 36 | |
| 37 | /** |
| 38 | * Field class. |
| 39 | * |
| 40 | * @var string |
| 41 | */ |
| 42 | public $class = ''; |
| 43 | |
| 44 | /** |
| 45 | * Form ID. |
| 46 | * |
| 47 | * @var int|mixed |
| 48 | */ |
| 49 | public $form_id; |
| 50 | |
| 51 | /** |
| 52 | * Field group. |
| 53 | * |
| 54 | * @var string |
| 55 | */ |
| 56 | public $group = 'general'; |
| 57 | |
| 58 | /** |
| 59 | * Is available in Pro? |
| 60 | * |
| 61 | * @var boolean |
| 62 | */ |
| 63 | public $is_pro = false; |
| 64 | |
| 65 | /** |
| 66 | * Placeholder to hold default value(s) for some field types. |
| 67 | * |
| 68 | * @var mixed |
| 69 | */ |
| 70 | public $defaults; |
| 71 | |
| 72 | /** |
| 73 | * Array of form data. |
| 74 | * |
| 75 | * @var array |
| 76 | */ |
| 77 | public $form_data; |
| 78 | |
| 79 | /** |
| 80 | * Array of field settings. |
| 81 | * |
| 82 | * @var array |
| 83 | */ |
| 84 | protected $settings = array(); |
| 85 | |
| 86 | /** |
| 87 | * Constructor. |
| 88 | */ |
| 89 | public function __construct() { |
| 90 | $get_license = evf_get_license_plan(); |
| 91 | $this->class = $this->is_pro ? ( false === $get_license ? 'upgrade-modal' : 'evf-upgrade-addon' ) : $this->class; |
| 92 | $this->form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification |
| 93 | |
| 94 | // Init hooks. |
| 95 | $this->init_hooks(); |
| 96 | |
| 97 | // Hooks. |
| 98 | add_action( 'everest_forms_builder_fields_options_' . $this->type, array( $this, 'field_options' ) ); |
| 99 | add_action( 'everest_forms_builder_fields_preview_' . $this->type, array( $this, 'field_preview' ) ); |
| 100 | add_action( 'wp_ajax_everest_forms_new_field_' . $this->type, array( $this, 'field_new' ) ); |
| 101 | add_action( 'everest_forms_display_field_' . $this->type, array( $this, 'field_display' ), 10, 3 ); |
| 102 | add_action( 'everest_forms_display_edit_form_field_' . $this->type, array( $this, 'edit_form_field_display' ), 10, 3 ); |
| 103 | add_action( 'everest_forms_process_validate_' . $this->type, array( $this, 'validate' ), 10, 3 ); |
| 104 | add_action( 'everest_forms_process_format_' . $this->type, array( $this, 'format' ), 10, 4 ); |
| 105 | add_filter( 'everest_forms_field_properties', array( $this, 'field_prefill_value_property' ), 10, 3 ); |
| 106 | add_filter( 'everest_forms_field_exporter_' . $this->type, array( $this, 'field_exporter' ) ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Hook in tabs. |
| 111 | */ |
| 112 | public function init_hooks() {} |
| 113 | |
| 114 | /** |
| 115 | * Prefill field value with either fallback or dynamic data. |
| 116 | * Needs to be public (although internal) to be used in WordPress hooks. |
| 117 | * |
| 118 | * @since 1.6.5 |
| 119 | * |
| 120 | * @param array $properties Field properties. |
| 121 | * @param array $field Current field specific data. |
| 122 | * @param array $form_data Prepared form data/settings. |
| 123 | * |
| 124 | * @return array Modified field properties. |
| 125 | */ |
| 126 | public function field_prefill_value_property( $properties, $field, $form_data ) { |
| 127 | // Process only for current field. |
| 128 | if ( $this->type !== $field['type'] ) { |
| 129 | return $properties; |
| 130 | } |
| 131 | |
| 132 | // Set the form data, so we can reuse it later, even on front-end. |
| 133 | $this->form_data = $form_data; |
| 134 | |
| 135 | return $properties; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Get the form fields after they are initialized. |
| 140 | * |
| 141 | * @return array of options |
| 142 | */ |
| 143 | public function get_field_settings() { |
| 144 | return apply_filters( 'everest_forms_get_field_settings_' . $this->type, $this->settings ); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Output form fields options. |
| 149 | * |
| 150 | * Loops though the field options array and outputs each field. |
| 151 | * |
| 152 | * @param array $field Field data. |
| 153 | */ |
| 154 | public function field_options( $field ) { |
| 155 | $settings = apply_filters( 'everest_forms_builder_fields_option', $this->get_field_settings() ); |
| 156 | |
| 157 | foreach ( $settings as $option_key => $option ) { |
| 158 | $this->field_option( |
| 159 | $option_key, |
| 160 | $field, |
| 161 | array( |
| 162 | 'markup' => 'open', |
| 163 | ) |
| 164 | ); |
| 165 | |
| 166 | if ( ! empty( $option['field_options'] ) ) { |
| 167 | foreach ( $option['field_options'] as $option_name ) { |
| 168 | $this->field_option( $option_name, $field ); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | $this->field_option( |
| 173 | $option_key, |
| 174 | $field, |
| 175 | array( |
| 176 | 'markup' => 'close', |
| 177 | ) |
| 178 | ); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Field preview inside the builder. |
| 184 | * |
| 185 | * @since 1.0.0 |
| 186 | * |
| 187 | * @param array $field Field data and settings. |
| 188 | */ |
| 189 | public function field_preview( $field ) {} |
| 190 | |
| 191 | /** |
| 192 | * Helper function to create field option elements. |
| 193 | * |
| 194 | * Field option elements are pieces that help create a field option. |
| 195 | * They are used to quickly build field options. |
| 196 | * |
| 197 | * @since 1.0.0 |
| 198 | * |
| 199 | * @param string $option Field option to render. |
| 200 | * @param array $field Field data and settings. |
| 201 | * @param array $args Field preview arguments. |
| 202 | * @param boolean $echo Print or return the value. Print by default. |
| 203 | * |
| 204 | * @return mixed echo or return string |
| 205 | */ |
| 206 | public function field_element( $option, $field, $args = array(), $echo = true ) { |
| 207 | $id = (string) $field['id']; |
| 208 | $class = ! empty( $args['class'] ) && is_string( $args['class'] ) ? esc_attr( $args['class'] ) : ''; |
| 209 | $slug = ! empty( $args['slug'] ) ? sanitize_title( $args['slug'] ) : ''; |
| 210 | $data = ''; |
| 211 | $output = ''; |
| 212 | |
| 213 | if ( ! empty( $args['data'] ) ) { |
| 214 | foreach ( $args['data'] as $key => $val ) { |
| 215 | if ( is_array( $val ) ) { |
| 216 | $val = wp_json_encode( $val ); |
| 217 | } |
| 218 | $data .= ' data-' . $key . '=\'' . $val . '\''; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // BW compat for number attrs. |
| 223 | if ( ! empty( $args['min'] ) ) { |
| 224 | $args['attrs']['min'] = esc_attr( $args['min'] ); |
| 225 | unset( $args['min'] ); |
| 226 | } |
| 227 | if ( ! empty( $args['max'] ) ) { |
| 228 | $args['attrs']['max'] = esc_attr( $args['max'] ); |
| 229 | unset( $args['min'] ); |
| 230 | } |
| 231 | if ( ! empty( $args['required'] ) && $args['required'] ) { |
| 232 | $args['attrs']['required'] = 'required'; |
| 233 | unset( $args['required'] ); |
| 234 | } |
| 235 | |
| 236 | if ( ! empty( $args['attrs'] ) ) { |
| 237 | foreach ( $args['attrs'] as $arg_key => $val ) { |
| 238 | if ( is_array( $val ) ) { |
| 239 | $val = wp_json_encode( $val ); |
| 240 | } |
| 241 | $data .= $arg_key . '=\'' . $val . '\''; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | switch ( $option ) { |
| 246 | |
| 247 | // Row. |
| 248 | case 'row': |
| 249 | $output = sprintf( '<div class="everest-forms-field-option-row everest-forms-field-option-row-%s %s" id="everest-forms-field-option-row-%s-%s" data-field-id="%s" %s>%s</div>', $slug, $class, $id, $slug, $id, $data, $args['content'] ); |
| 250 | break; |
| 251 | |
| 252 | // Icon. |
| 253 | case 'icon': |
| 254 | $element_tooltip = isset( $args['tooltip'] ) ? $args['tooltip'] : 'Edit Label'; |
| 255 | $icon = isset( $args['icon'] ) ? $args['icon'] : 'dashicons-edit'; |
| 256 | $output .= sprintf( ' <i class="dashicons %s everest-forms-icon %s" title="%s" %s></i>', esc_attr( $icon ), $class, esc_attr( $element_tooltip ), $data ); |
| 257 | break; |
| 258 | |
| 259 | // Label. |
| 260 | case 'label': |
| 261 | $output = sprintf( '<label for="everest-forms-field-option-%s-%s" class="%s" %s>%s', $id, $slug, $class, $data, esc_html( $args['value'] ) ); |
| 262 | if ( isset( $args['tooltip'] ) && ! empty( $args['tooltip'] ) ) { |
| 263 | $output .= ' ' . sprintf( '<i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) ); |
| 264 | } |
| 265 | if ( isset( $args['after_tooltip'] ) && ! empty( $args['after_tooltip'] ) ) { |
| 266 | $output .= $args['after_tooltip']; |
| 267 | } |
| 268 | $output .= '</label>'; |
| 269 | break; |
| 270 | |
| 271 | // Text input. |
| 272 | case 'text': |
| 273 | $type = ! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text'; |
| 274 | $placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : ''; |
| 275 | $before = ! empty( $args['before'] ) ? '<span class="before-input">' . esc_html( $args['before'] ) . '</span>' : ''; |
| 276 | if ( ! empty( $before ) ) { |
| 277 | $class .= ' has-before'; |
| 278 | } |
| 279 | |
| 280 | $output = sprintf( '%s<input type="%s" class="widefat %s" id="everest-forms-field-option-%s-%s" name="form_fields[%s][%s]" value="%s" placeholder="%s" %s>', $before, $type, $class, $id, $slug, $id, $slug, esc_attr( $args['value'] ), $placeholder, $data ); |
| 281 | break; |
| 282 | |
| 283 | // Textarea. |
| 284 | case 'textarea': |
| 285 | $rows = ! empty( $args['rows'] ) ? (int) $args['rows'] : '3'; |
| 286 | $output = sprintf( '<textarea class="widefat %s" id="everest-forms-field-option-%s-%s" name="form_fields[%s][%s]" rows="%s" %s>%s</textarea>', $class, $id, $slug, $id, $slug, $rows, $data, $args['value'] ); |
| 287 | break; |
| 288 | |
| 289 | // Checkbox. |
| 290 | case 'checkbox': |
| 291 | $checked = checked( '1', $args['value'], false ); |
| 292 | $output = sprintf( '<input type="checkbox" class="widefat %s" id="everest-forms-field-option-%s-%s" name="form_fields[%s][%s]" value="1" %s %s>', $class, $id, $slug, $id, $slug, $checked, $data ); |
| 293 | $output .= sprintf( '<label for="everest-forms-field-option-%s-%s" class="inline">%s', $id, $slug, $args['desc'] ); |
| 294 | if ( isset( $args['tooltip'] ) && ! empty( $args['tooltip'] ) ) { |
| 295 | $output .= ' ' . sprintf( '<i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) ); |
| 296 | } |
| 297 | $output .= '</label>'; |
| 298 | break; |
| 299 | |
| 300 | // Toggle. |
| 301 | case 'toggle': |
| 302 | $checked = checked( '1', $args['value'], false ); |
| 303 | $output .= sprintf( '<div class="evf-toggle-section">' ); |
| 304 | $output .= sprintf( '<span class="everest-forms-toggle-form">' ); |
| 305 | $output .= sprintf( '<input type="checkbox" class="widefat %s" id="everest-forms-field-option-%s-%s" name="form_fields[%s][%s]" value="1" %s %s>', $class, $id, $slug, $id, $slug, $checked, $data ); |
| 306 | $output .= sprintf( '<span class="slider round"></span>' ); |
| 307 | $output .= sprintf( '</span>' ); |
| 308 | $output .= sprintf( '<label for="everest-forms-field-option-%s-%s" class="inline">%s', $id, $slug, $args['desc'] ); |
| 309 | if ( isset( $args['tooltip'] ) && ! empty( $args['tooltip'] ) ) { |
| 310 | $output .= ' ' . sprintf( '<i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) ); |
| 311 | } |
| 312 | $output .= '</label>'; |
| 313 | $output .= sprintf( '</div>' ); |
| 314 | break; |
| 315 | |
| 316 | // Select. |
| 317 | case 'select': |
| 318 | $options = $args['options']; |
| 319 | $value = isset( $args['value'] ) ? $args['value'] : ''; |
| 320 | $is_multiple = isset( $args['multiple'] ) && true === $args['multiple']; |
| 321 | |
| 322 | if ( true === $is_multiple ) { |
| 323 | $output = sprintf( '<select class="widefat %s" id="everest-forms-field-option-%s-%s" name="form_fields[%s][%s][]" %s multiple>', $class, $id, $slug, $id, $slug, $data ); |
| 324 | } else { |
| 325 | $output = sprintf( '<select class="widefat %s" id="everest-forms-field-option-%s-%s" name="form_fields[%s][%s]" %s >', $class, $id, $slug, $id, $slug, $data ); |
| 326 | } |
| 327 | |
| 328 | foreach ( $options as $key => $option_value ) { |
| 329 | |
| 330 | if ( true === $is_multiple && is_array( $value ) ) { |
| 331 | $selected_value = in_array( $key, $value, true ) ? 'selected="selected"' : ''; |
| 332 | } else { |
| 333 | $selected_value = ( $value == $key ) ? 'selected="selected"' : ''; |
| 334 | } |
| 335 | $output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), $selected_value, $option_value ); |
| 336 | } |
| 337 | $output .= '</select>'; |
| 338 | break; |
| 339 | |
| 340 | // Radio. |
| 341 | case 'radio': |
| 342 | $options = $args['options']; |
| 343 | $default = isset( $args['default'] ) ? $args['default'] : ''; |
| 344 | $output = '<label>' . $args['desc']; |
| 345 | |
| 346 | if ( isset( $args['tooltip'] ) && ! empty( $args['tooltip'] ) ) { |
| 347 | $output .= ' ' . sprintf( '<i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i></label>', esc_attr( $args['tooltip'] ) ); |
| 348 | } else { |
| 349 | $output .= '</label>'; |
| 350 | } |
| 351 | $output .= '<ul>'; |
| 352 | |
| 353 | foreach ( $options as $key => $option ) { |
| 354 | $output .= '<li>'; |
| 355 | $output .= sprintf( '<label><input type="radio" class="widefat %s" id="everest-forms-field-option-%s-%s-%s" value="%s" name="form_fields[%s][%s]" %s %s>%s</label>', $class, $id, $slug, $key, $key, $id, $slug, $data, checked( $key, $default, false ), $option ); |
| 356 | $output .= '</li>'; |
| 357 | } |
| 358 | $output .= '</ul>'; |
| 359 | break; |
| 360 | } |
| 361 | |
| 362 | if ( $echo ) { |
| 363 | echo wp_kses( $output, evf_get_allowed_html_tags( 'builder' ) ); |
| 364 | } else { |
| 365 | return $output; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Helper function to create common field options that are used frequently. |
| 371 | * |
| 372 | * @since 1.0.0 |
| 373 | * |
| 374 | * @param string $option Option. |
| 375 | * @param array $field Field data. |
| 376 | * @param array $args Arguments. |
| 377 | * @param boolean $echo True to echo. |
| 378 | * |
| 379 | * @return mixed echo or return string |
| 380 | */ |
| 381 | public function field_option( $option, $field, $args = array(), $echo = true ) { |
| 382 | $output = ''; |
| 383 | $markup = ! empty( $args['markup'] ) ? $args['markup'] : 'open'; |
| 384 | $class = ! empty( $args['class'] ) ? esc_html( $args['class'] ) : ''; |
| 385 | |
| 386 | if ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'open' === $markup ) { |
| 387 | do_action( "everest_forms_field_options_before_{$option}", $field, $this ); |
| 388 | } elseif ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'close' === $markup ) { |
| 389 | do_action( "everest_forms_field_options_bottom_{$option}", $field, $this ); |
| 390 | } |
| 391 | |
| 392 | switch ( $option ) { |
| 393 | /** |
| 394 | * Basic Fields. |
| 395 | */ |
| 396 | |
| 397 | /* |
| 398 | * Basic Options markup. |
| 399 | */ |
| 400 | case 'basic-options': |
| 401 | if ( 'open' === $markup ) { |
| 402 | if ( $echo ) { |
| 403 | echo sprintf( '<div class="everest-forms-field-option-group everest-forms-field-option-group-basic open" id="everest-forms-field-option-basic-%s">', esc_attr( $field['id'] ) ); |
| 404 | echo sprintf( '<a href="#" class="everest-forms-field-option-group-toggle">%s<span> (ID #%s)</span> <i class="handlediv"></i></a>', esc_html( $this->name ), esc_html( $field['id'] ) ); |
| 405 | echo sprintf( '<div class="everest-forms-field-option-group-inner %s">', esc_attr( $class ) ); |
| 406 | } else { |
| 407 | $output = sprintf( '<div class="everest-forms-field-option-group everest-forms-field-option-group-basic open" id="everest-forms-field-option-basic-%s">', $field['id'] ); |
| 408 | $output .= sprintf( '<a href="#" class="everest-forms-field-option-group-toggle">%s<span> (ID #%s)</span> <i class="handlediv"></i></a>', $this->name, $field['id'] ); |
| 409 | $output .= sprintf( '<div class="everest-forms-field-option-group-inner %s">', $class ); |
| 410 | } |
| 411 | } else { |
| 412 | if ( $echo ) { |
| 413 | echo '</div></div>'; |
| 414 | } else { |
| 415 | $output = '</div></div>'; |
| 416 | } |
| 417 | } |
| 418 | break; |
| 419 | |
| 420 | /* |
| 421 | * Field Label. |
| 422 | */ |
| 423 | case 'label': |
| 424 | $value = ! empty( $field['label'] ) ? esc_attr( $field['label'] ) : ''; |
| 425 | $tooltip = esc_html__( 'Enter text for the form field label. This is recommended and can be hidden in the Advanced Settings.', 'everest-forms' ); |
| 426 | $output = $this->field_element( |
| 427 | 'label', |
| 428 | $field, |
| 429 | array( |
| 430 | 'slug' => 'label', |
| 431 | 'value' => esc_html__( 'Label', 'everest-forms' ), |
| 432 | 'tooltip' => $tooltip, |
| 433 | ), |
| 434 | false |
| 435 | ); |
| 436 | $output .= $this->field_element( |
| 437 | 'text', |
| 438 | $field, |
| 439 | array( |
| 440 | 'slug' => 'label', |
| 441 | 'value' => $value, |
| 442 | ), |
| 443 | false |
| 444 | ); |
| 445 | $output = $this->field_element( |
| 446 | 'row', |
| 447 | $field, |
| 448 | array( |
| 449 | 'slug' => 'label', |
| 450 | 'content' => $output, |
| 451 | ), |
| 452 | $echo |
| 453 | ); |
| 454 | break; |
| 455 | |
| 456 | /* |
| 457 | * Field Meta. |
| 458 | */ |
| 459 | case 'meta': |
| 460 | $value = ! empty( $field['meta-key'] ) ? esc_attr( $field['meta-key'] ) : evf_get_meta_key_field_option( $field ); |
| 461 | $tooltip = esc_html__( 'Enter meta key to be stored in database.', 'everest-forms' ); |
| 462 | $output = $this->field_element( |
| 463 | 'label', |
| 464 | $field, |
| 465 | array( |
| 466 | 'slug' => 'meta-key', |
| 467 | 'value' => esc_html__( 'Meta Key', 'everest-forms' ), |
| 468 | 'tooltip' => $tooltip, |
| 469 | ), |
| 470 | false |
| 471 | ); |
| 472 | $output .= $this->field_element( |
| 473 | 'text', |
| 474 | $field, |
| 475 | array( |
| 476 | 'slug' => 'meta-key', |
| 477 | 'class' => 'evf-input-meta-key', |
| 478 | 'value' => $value, |
| 479 | ), |
| 480 | false |
| 481 | ); |
| 482 | $output = $this->field_element( |
| 483 | 'row', |
| 484 | $field, |
| 485 | array( |
| 486 | 'slug' => 'meta-key', |
| 487 | 'content' => $output, |
| 488 | ), |
| 489 | $echo |
| 490 | ); |
| 491 | break; |
| 492 | |
| 493 | /* |
| 494 | * Field Description. |
| 495 | */ |
| 496 | case 'description': |
| 497 | $value = ! empty( $field['description'] ) ? esc_attr( $field['description'] ) : ''; |
| 498 | $tooltip = esc_html__( 'Enter text for the form field description.', 'everest-forms' ); |
| 499 | $output = $this->field_element( |
| 500 | 'label', |
| 501 | $field, |
| 502 | array( |
| 503 | 'slug' => 'description', |
| 504 | 'value' => esc_html__( 'Description', 'everest-forms' ), |
| 505 | 'tooltip' => $tooltip, |
| 506 | ), |
| 507 | false |
| 508 | ); |
| 509 | $output .= $this->field_element( |
| 510 | 'textarea', |
| 511 | $field, |
| 512 | array( |
| 513 | 'slug' => 'description', |
| 514 | 'value' => $value, |
| 515 | ), |
| 516 | false |
| 517 | ); |
| 518 | $output = $this->field_element( |
| 519 | 'row', |
| 520 | $field, |
| 521 | array( |
| 522 | 'slug' => 'description', |
| 523 | 'content' => $output, |
| 524 | ), |
| 525 | $echo |
| 526 | ); |
| 527 | break; |
| 528 | |
| 529 | /* |
| 530 | * Field Required toggle. |
| 531 | */ |
| 532 | case 'required': |
| 533 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 534 | $value = isset( $field['required'] ) ? $field['required'] : $default; |
| 535 | $tooltip = esc_html__( 'Check this option to mark the field required. A form will not submit unless all required fields are provided.', 'everest-forms' ); |
| 536 | $output = $this->field_element( |
| 537 | 'toggle', |
| 538 | $field, |
| 539 | array( |
| 540 | 'slug' => 'required', |
| 541 | 'value' => $value, |
| 542 | 'desc' => esc_html__( 'Required', 'everest-forms' ), |
| 543 | 'tooltip' => $tooltip, |
| 544 | ), |
| 545 | false |
| 546 | ); |
| 547 | $output = $this->field_element( |
| 548 | 'row', |
| 549 | $field, |
| 550 | array( |
| 551 | 'slug' => 'required', |
| 552 | 'content' => $output, |
| 553 | ), |
| 554 | $echo |
| 555 | ); |
| 556 | break; |
| 557 | |
| 558 | /* |
| 559 | * Field Required toggle. |
| 560 | */ |
| 561 | case 'required_field_message_setting': |
| 562 | $default = ! empty( $args['default'] ) ? $args['default'] : 'global'; |
| 563 | if ( isset( $field['required_field_message_setting'] ) ) { |
| 564 | if ( 'global' === $field['required_field_message_setting'] ) { |
| 565 | $value = $field['required_field_message_setting']; |
| 566 | } elseif ( 'individual' === $field['required_field_message_setting'] ) { |
| 567 | $value = $field['required_field_message_setting']; |
| 568 | } |
| 569 | } elseif ( ! empty( $field['required-field-message'] ) ) { |
| 570 | $value = 'individual'; |
| 571 | } else { |
| 572 | $value = $default; |
| 573 | } |
| 574 | $output = $this->field_element( |
| 575 | 'radio', |
| 576 | $field, |
| 577 | array( |
| 578 | 'slug' => 'required_field_message_setting', |
| 579 | 'default' => $value, |
| 580 | 'desc' => '', |
| 581 | 'options' => array( |
| 582 | 'global' => esc_html__( 'Show Required Message From Global Setting', 'everest-forms' ), |
| 583 | 'individual' => esc_html__( 'Custom Required Message', 'everest-forms' ), |
| 584 | ), |
| 585 | ), |
| 586 | false |
| 587 | ); |
| 588 | $output = $this->field_element( |
| 589 | 'row', |
| 590 | $field, |
| 591 | array( |
| 592 | 'slug' => 'required_field_message_setting', |
| 593 | 'class' => isset( $field['required'] ) ? '' : 'hidden', |
| 594 | 'content' => $output, |
| 595 | ), |
| 596 | $echo |
| 597 | ); |
| 598 | break; |
| 599 | /** |
| 600 | * Required Field Message. |
| 601 | */ |
| 602 | case 'required_field_message': |
| 603 | $has_sub_fields = false; |
| 604 | $sub_fields = array(); |
| 605 | $required_validation = get_option( 'everest_forms_required_validation' ); |
| 606 | if ( in_array( $field['type'], array( 'number', 'email', 'url', 'phone' ), true ) ) { |
| 607 | $required_validation = get_option( 'everest_forms_' . $field['type'] . '_validation' ); |
| 608 | } |
| 609 | $hidden = true; |
| 610 | if ( isset( $field['required_field_message_setting'], $field['required'] ) ) { |
| 611 | if ( 'global' === $field['required_field_message_setting'] ) { |
| 612 | $hidden = true; |
| 613 | } elseif ( 'individual' === $field['required_field_message_setting'] ) { |
| 614 | $hidden = false; |
| 615 | } |
| 616 | } elseif ( ! empty( $field['required-field-message'] ) && isset( $field['required'] ) ) { |
| 617 | $hidden = false; |
| 618 | } |
| 619 | |
| 620 | if ( 'likert' === $field['type'] ) { |
| 621 | $has_sub_fields = true; |
| 622 | $likert_rows = isset( $field['likert_rows'] ) ? $field['likert_rows'] : array(); |
| 623 | foreach ( $likert_rows as $row_number => $row_label ) { |
| 624 | $row_slug = 'required-field-message-' . $row_number; |
| 625 | $sub_fields[ $row_slug ] = array( |
| 626 | 'label' => array( |
| 627 | 'value' => $row_label, |
| 628 | 'tooltip' => esc_html__( 'Enter a message to show for this row if it\'s required.', 'everest-forms' ), |
| 629 | ), |
| 630 | 'text' => array( |
| 631 | 'value' => isset( $field[ $row_slug ] ) ? esc_attr( $field[ $row_slug ] ) : '', |
| 632 | ), |
| 633 | ); |
| 634 | } |
| 635 | } elseif ( 'address' === $field['type'] ) { |
| 636 | $has_sub_fields = true; |
| 637 | $sub_fields = array( |
| 638 | 'required-field-message-address1' => array( |
| 639 | 'label' => array( |
| 640 | 'value' => esc_html__( 'Address Line 1', 'everest-forms' ), |
| 641 | 'tooltip' => esc_html__( 'Enter a message to show for Address Line 1 if it\'s required.', 'everest-forms' ), |
| 642 | ), |
| 643 | 'text' => array( |
| 644 | 'value' => isset( $field['required-field-message-address1'] ) ? esc_attr( $field['required-field-message-address1'] ) : '', |
| 645 | ), |
| 646 | ), |
| 647 | 'required-field-message-city' => array( |
| 648 | 'label' => array( |
| 649 | 'value' => esc_html__( 'City', 'everest-forms' ), |
| 650 | 'tooltip' => esc_html__( 'Enter a message to show for City if it\'s required.', 'everest-forms' ), |
| 651 | ), |
| 652 | 'text' => array( |
| 653 | 'value' => isset( $field['required-field-message-city'] ) ? esc_attr( $field['required-field-message-city'] ) : '', |
| 654 | ), |
| 655 | ), |
| 656 | 'required-field-message-state' => array( |
| 657 | 'label' => array( |
| 658 | 'value' => esc_html__( 'State / Province / Region', 'everest-forms' ), |
| 659 | 'tooltip' => esc_html__( 'Enter a message to show for State/Province/Region if it\'s required.', 'everest-forms' ), |
| 660 | ), |
| 661 | 'text' => array( |
| 662 | 'value' => isset( $field['required-field-message-state'] ) ? esc_attr( $field['required-field-message-state'] ) : '', |
| 663 | ), |
| 664 | ), |
| 665 | 'required-field-message-postal' => array( |
| 666 | 'label' => array( |
| 667 | 'value' => esc_html__( 'Zip / Postal Code', 'everest-forms' ), |
| 668 | 'tooltip' => esc_html__( 'Enter a message to show for Zip/Postal Code if it\'s required.', 'everest-forms' ), |
| 669 | ), |
| 670 | 'text' => array( |
| 671 | 'value' => isset( $field['required-field-message-postal'] ) ? esc_attr( $field['required-field-message-postal'] ) : '', |
| 672 | ), |
| 673 | ), |
| 674 | 'required-field-message-country' => array( |
| 675 | 'label' => array( |
| 676 | 'value' => esc_html__( 'Country', 'everest-forms' ), |
| 677 | 'tooltip' => esc_html__( 'Enter a message to show for Country if it\'s required.', 'everest-forms' ), |
| 678 | ), |
| 679 | 'text' => array( |
| 680 | 'value' => isset( $field['required-field-message-country'] ) ? esc_attr( $field['required-field-message-country'] ) : '', |
| 681 | ), |
| 682 | ), |
| 683 | ); |
| 684 | } |
| 685 | |
| 686 | if ( true === $has_sub_fields ) { |
| 687 | $sub_field_output_array = array(); |
| 688 | foreach ( $sub_fields as $sub_field_slug => $sub_field_data ) { |
| 689 | $value = isset( $field['required-field-message'] ) ? esc_attr( $field['required-field-message'] ) : ''; |
| 690 | $tooltip = esc_html__( 'Enter a message to show for this field if it\'s required.', 'everest-forms' ); |
| 691 | $output = $this->field_element( |
| 692 | 'label', |
| 693 | $field, |
| 694 | array( |
| 695 | 'slug' => $sub_field_slug, |
| 696 | 'value' => $sub_field_data['label']['value'], |
| 697 | 'tooltip' => $sub_field_data['label']['tooltip'], |
| 698 | ), |
| 699 | false |
| 700 | ); |
| 701 | $output .= $this->field_element( |
| 702 | 'text', |
| 703 | $field, |
| 704 | array( |
| 705 | 'slug' => $sub_field_slug, |
| 706 | 'value' => $sub_field_data['text']['value'], |
| 707 | ), |
| 708 | false |
| 709 | ); |
| 710 | $output = $this->field_element( |
| 711 | 'row', |
| 712 | $field, |
| 713 | array( |
| 714 | 'slug' => $sub_field_slug, |
| 715 | 'content' => $output, |
| 716 | ), |
| 717 | false |
| 718 | ); |
| 719 | |
| 720 | $sub_field_output_array[] = $output; |
| 721 | } |
| 722 | |
| 723 | $output = implode( '', $sub_field_output_array ); |
| 724 | $output = $this->field_element( |
| 725 | 'row', |
| 726 | $field, |
| 727 | array( |
| 728 | 'slug' => 'required-field-message', |
| 729 | 'class' => false === $hidden ? '' : 'hidden', |
| 730 | 'content' => $output, |
| 731 | ), |
| 732 | $echo |
| 733 | ); |
| 734 | } else { |
| 735 | $value = isset( $field['required-field-message'] ) ? esc_attr( $field['required-field-message'] ) : ''; |
| 736 | $tooltip = esc_html__( 'Enter a message to show for this field if it\'s required.', 'everest-forms' ); |
| 737 | |
| 738 | $output = $this->field_element( |
| 739 | 'label', |
| 740 | $field, |
| 741 | array( |
| 742 | 'slug' => 'required-field-message', |
| 743 | 'value' => esc_html__( 'Required Field Message', 'everest-forms' ), |
| 744 | 'tooltip' => $tooltip, |
| 745 | ), |
| 746 | false |
| 747 | ); |
| 748 | $output .= $this->field_element( |
| 749 | 'text', |
| 750 | $field, |
| 751 | array( |
| 752 | 'slug' => 'required-field-message', |
| 753 | 'value' => $value, |
| 754 | 'class' => 'everest-forms-field-option-row', |
| 755 | ), |
| 756 | false |
| 757 | ); |
| 758 | $output = $this->field_element( |
| 759 | 'row', |
| 760 | $field, |
| 761 | array( |
| 762 | 'slug' => 'required-field-message', |
| 763 | 'class' => false === $hidden ? '' : 'hidden', |
| 764 | 'content' => $output, |
| 765 | ), |
| 766 | $echo |
| 767 | ); |
| 768 | } |
| 769 | break; |
| 770 | |
| 771 | /** |
| 772 | * Field Visibilty. |
| 773 | */ |
| 774 | case 'field_visiblity': |
| 775 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 776 | $readonly_value = isset( $field['readonly_field_visibility'] ) ? $field['readonly_field_visibility'] : $default; |
| 777 | $hidden_value = isset( $field['hidden_field_visibility'] ) ? $field['hidden_field_visibility'] : $default; |
| 778 | $tooltip = esc_html__( 'Check this option to mark the field readonly and hidden.', 'everest-forms' ); |
| 779 | $label = $this->field_element( |
| 780 | 'label', |
| 781 | $field, |
| 782 | array( |
| 783 | 'slug' => 'field_visibility', |
| 784 | 'value' => esc_html__( 'Field Visibility', 'everest-forms' ), |
| 785 | 'tooltip' => $tooltip, |
| 786 | ), |
| 787 | false |
| 788 | ); |
| 789 | $readonly = $this->field_element( |
| 790 | 'toggle', |
| 791 | $field, |
| 792 | array( |
| 793 | 'slug' => 'readonly_field_visibility', |
| 794 | 'value' => $readonly_value, |
| 795 | 'class' => 'field_visibility_readonly', |
| 796 | 'desc' => esc_html__( 'Readonly ', 'everest-forms' ), |
| 797 | ), |
| 798 | false |
| 799 | ); |
| 800 | $hidden = $this->field_element( |
| 801 | 'toggle', |
| 802 | $field, |
| 803 | array( |
| 804 | 'slug' => 'hidden_field_visibility', |
| 805 | 'value' => $hidden_value, |
| 806 | 'class' => 'field_visibility_hidden', |
| 807 | 'desc' => esc_html__( 'Hidden', 'everest-forms' ), |
| 808 | ), |
| 809 | false |
| 810 | ); |
| 811 | $output = $this->field_element( |
| 812 | 'row', |
| 813 | $field, |
| 814 | array( |
| 815 | 'slug' => 'field_visiblity', |
| 816 | 'content' => $label . '' . $readonly . ' ' . $hidden, |
| 817 | ), |
| 818 | $echo |
| 819 | ); |
| 820 | break; |
| 821 | |
| 822 | /** |
| 823 | * No Duplicates. |
| 824 | */ |
| 825 | case 'no_duplicates': |
| 826 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 827 | $value = ! empty( $field['no_duplicates'] ) ? esc_attr( $field['no_duplicates'] ) : ''; |
| 828 | $tooltip = esc_html__( 'Select this option to limit user input to unique values only. This will require that a value entered in a field does not currently exist in the entry database for that field..', 'everest-forms' ); |
| 829 | $output = $this->field_element( |
| 830 | 'toggle', |
| 831 | $field, |
| 832 | array( |
| 833 | 'slug' => 'no_duplicates', |
| 834 | 'value' => $value, |
| 835 | 'desc' => esc_html__( 'Validate as unique', 'everest-forms' ), |
| 836 | 'tooltip' => $tooltip, |
| 837 | ), |
| 838 | false |
| 839 | ); |
| 840 | $output = $this->field_element( |
| 841 | 'row', |
| 842 | $field, |
| 843 | array( |
| 844 | 'slug' => 'no_duplicates', |
| 845 | 'content' => $output, |
| 846 | ), |
| 847 | $echo |
| 848 | ); |
| 849 | break; |
| 850 | case 'validate_message': |
| 851 | $toggle = ''; |
| 852 | $tooltip = esc_html__( 'if the form submission failed it will show this message.', 'everest-forms' ); |
| 853 | $value = ! empty( $field['validate_message'] ) ? esc_attr( $field['validate_message'] ) : 'This field value needs to be unique.'; |
| 854 | |
| 855 | // Build output. |
| 856 | $output = $this->field_element( |
| 857 | 'label', |
| 858 | $field, |
| 859 | array( |
| 860 | 'slug' => 'validate_message', |
| 861 | 'value' => esc_html__( 'Validation Message for Duplicate', 'everest-forms' ), |
| 862 | 'tooltip' => $tooltip, |
| 863 | 'after_tooltip' => $toggle, |
| 864 | ), |
| 865 | false |
| 866 | ); |
| 867 | $output .= $this->field_element( |
| 868 | 'text', |
| 869 | $field, |
| 870 | array( |
| 871 | 'slug' => 'validate_message', |
| 872 | 'value' => $value, |
| 873 | ), |
| 874 | false |
| 875 | ); |
| 876 | $output = $this->field_element( |
| 877 | 'row', |
| 878 | $field, |
| 879 | array( |
| 880 | 'slug' => 'validate_message', |
| 881 | 'content' => $output, |
| 882 | 'class' => isset( $field['no_duplicates'] ) ? '' : 'hidden', |
| 883 | ), |
| 884 | $echo |
| 885 | ); |
| 886 | break; |
| 887 | /** |
| 888 | * No Duplicates. |
| 889 | */ |
| 890 | case 'show_tooltip': |
| 891 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 892 | $value = ! empty( $field['show_tooltip'] ) ? esc_attr( $field['show_tooltip'] ) : ''; |
| 893 | $output = $this->field_element( |
| 894 | 'toggle', |
| 895 | $field, |
| 896 | array( |
| 897 | 'slug' => 'show_tooltip', |
| 898 | 'value' => $value, |
| 899 | 'desc' => esc_html__( 'Enable Tooltip', 'everest-forms' ), |
| 900 | 'tooltip' => esc_html__( 'Check this option to show the form field tooltip.', 'everest-forms' ), |
| 901 | ), |
| 902 | false |
| 903 | ); |
| 904 | $output = $this->field_element( |
| 905 | 'row', |
| 906 | $field, |
| 907 | array( |
| 908 | 'slug' => 'show_tooltip', |
| 909 | 'content' => $output, |
| 910 | ), |
| 911 | $echo |
| 912 | ); |
| 913 | $description_value = ! empty( $field['tooltip_description'] ) ? esc_attr( $field['tooltip_description'] ) : ''; |
| 914 | $output = $this->field_element( |
| 915 | 'textarea', |
| 916 | $field, |
| 917 | array( |
| 918 | 'slug' => 'tooltip_description', |
| 919 | 'value' => $description_value, |
| 920 | 'desc' => esc_html__( 'Enable Tooltip', 'everest-forms' ), |
| 921 | 'attrs' => array( |
| 922 | 'placeholder' => esc_html__( 'Enter the text for tooltip description.', 'everest-forms' ), |
| 923 | ), |
| 924 | ), |
| 925 | false |
| 926 | ); |
| 927 | |
| 928 | $output = $this->field_element( |
| 929 | 'row', |
| 930 | $field, |
| 931 | array( |
| 932 | 'slug' => 'tooltip_description', |
| 933 | 'content' => $output, |
| 934 | ), |
| 935 | $echo |
| 936 | ); |
| 937 | break; |
| 938 | /** |
| 939 | * No Duplicates. |
| 940 | */ |
| 941 | case 'autocomplete_address': |
| 942 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 943 | $value = ! empty( $field['autocomplete_address'] ) ? esc_attr( $field['autocomplete_address'] ) : ''; |
| 944 | $tooltip = esc_html__( 'Check this option to autofill address field.', 'everest-forms' ); |
| 945 | $output = $this->field_element( |
| 946 | 'toggle', |
| 947 | $field, |
| 948 | array( |
| 949 | 'slug' => 'autocomplete_address', |
| 950 | 'value' => $value, |
| 951 | 'desc' => esc_html__( 'Enable Autocomplete Address Field', 'everest-forms' ), |
| 952 | 'tooltip' => $tooltip, |
| 953 | ), |
| 954 | false |
| 955 | ); |
| 956 | $output = $this->field_element( |
| 957 | 'row', |
| 958 | $field, |
| 959 | array( |
| 960 | 'slug' => 'autocomplete_address', |
| 961 | 'content' => $output, |
| 962 | ), |
| 963 | $echo |
| 964 | ); |
| 965 | break; |
| 966 | case 'address_style': |
| 967 | $default = ! empty( $args['default'] ) ? $args['default'] : 'none'; |
| 968 | $tooltip = esc_html__( 'Select the style', 'everest-forms' ); |
| 969 | $value = ! empty( $field['address_style'] ) ? esc_attr( $field['address_style'] ) : ''; |
| 970 | $output = $this->field_element( |
| 971 | 'label', |
| 972 | $field, |
| 973 | array( |
| 974 | 'slug' => 'address_style', |
| 975 | 'value' => esc_html__( 'Style', 'everest-forms' ), |
| 976 | 'tooltip' => $tooltip, |
| 977 | ), |
| 978 | false |
| 979 | ); |
| 980 | $output .= $this->field_element( |
| 981 | 'select', |
| 982 | $field, |
| 983 | array( |
| 984 | 'slug' => 'address_style', |
| 985 | 'value' => $value, |
| 986 | 'tooltip' => $tooltip, |
| 987 | 'options' => array( |
| 988 | 'address' => esc_html__( 'Address', 'everest-forms' ), |
| 989 | 'map' => esc_html__( 'Map', 'everest-forms' ), |
| 990 | 'address_with_map' => esc_html( 'Address With Map' ), |
| 991 | ), |
| 992 | ), |
| 993 | false |
| 994 | ); |
| 995 | $output = $this->field_element( |
| 996 | 'row', |
| 997 | $field, |
| 998 | array( |
| 999 | 'slug' => 'address_style', |
| 1000 | 'content' => $output, |
| 1001 | ), |
| 1002 | $echo |
| 1003 | ); |
| 1004 | break; |
| 1005 | |
| 1006 | /* |
| 1007 | * Code Block. |
| 1008 | */ |
| 1009 | case 'code': |
| 1010 | $value = ! empty( $field['code'] ) ? esc_attr( $field['code'] ) : ''; |
| 1011 | $tooltip = esc_html__( 'Enter code for the form field.', 'everest-forms' ); |
| 1012 | $output = $this->field_element( |
| 1013 | 'label', |
| 1014 | $field, |
| 1015 | array( |
| 1016 | 'slug' => 'code', |
| 1017 | 'value' => esc_html__( 'Code', 'everest-forms' ), |
| 1018 | 'tooltip' => $tooltip, |
| 1019 | ), |
| 1020 | false |
| 1021 | ); |
| 1022 | $output .= $this->field_element( |
| 1023 | 'textarea', |
| 1024 | $field, |
| 1025 | array( |
| 1026 | 'slug' => 'code', |
| 1027 | 'value' => $value, |
| 1028 | ), |
| 1029 | false |
| 1030 | ); |
| 1031 | $output = $this->field_element( |
| 1032 | 'row', |
| 1033 | $field, |
| 1034 | array( |
| 1035 | 'slug' => 'code', |
| 1036 | 'content' => $output, |
| 1037 | ), |
| 1038 | $echo |
| 1039 | ); |
| 1040 | break; |
| 1041 | |
| 1042 | /* |
| 1043 | * Choices. |
| 1044 | */ |
| 1045 | case 'choices': |
| 1046 | $class = array(); |
| 1047 | $label = ! empty( $args['label'] ) ? esc_html( $args['label'] ) : esc_html__( 'Choices', 'everest-forms' ); |
| 1048 | $choices = ! empty( $field['choices'] ) ? $field['choices'] : $this->defaults; |
| 1049 | $input_type = in_array( $field['type'], array( 'radio', 'select', 'payment-multiple' ), true ) ? 'radio' : 'checkbox'; |
| 1050 | |
| 1051 | if ( ! empty( $field['show_values'] ) ) { |
| 1052 | $class[] = 'show-values'; |
| 1053 | } |
| 1054 | |
| 1055 | if ( ! empty( $field['choices_images'] ) ) { |
| 1056 | $class[] = 'show-images'; |
| 1057 | } |
| 1058 | |
| 1059 | if ( ! empty( $field['multiple_choices'] ) ) { |
| 1060 | $input_type = 'checkbox'; |
| 1061 | } |
| 1062 | |
| 1063 | // Add bulk options toggle handle. |
| 1064 | $bulk_add_enabled = apply_filters( 'evf_bulk_add_enabled', true ); |
| 1065 | $licensed = ( false === evf_get_license_plan() ) ? false : true; |
| 1066 | $upgradable_feature_class = ( true === $licensed ) ? '' : 'evf-upgradable-feature'; |
| 1067 | $bulk_options_toggle_handle = sprintf( '<a href="#" class="evf-toggle-bulk-options after-label-description %s">%s</a>', esc_attr( $upgradable_feature_class ), esc_html__( 'Bulk Add', 'everest-forms' ) ); |
| 1068 | |
| 1069 | // Field label. |
| 1070 | $field_label = $this->field_element( |
| 1071 | 'label', |
| 1072 | $field, |
| 1073 | array( |
| 1074 | 'slug' => 'choices', |
| 1075 | 'value' => $label, |
| 1076 | 'tooltip' => esc_html__( 'Add choices for the form field.', 'everest-forms' ), |
| 1077 | 'after_tooltip' => $bulk_options_toggle_handle, // @todo Bulk import and export for choices. |
| 1078 | ) |
| 1079 | ); |
| 1080 | $field_content = ''; |
| 1081 | |
| 1082 | if ( true === $bulk_add_enabled && true === $licensed ) { |
| 1083 | $field_content .= $this->field_option( |
| 1084 | 'add_bulk_options', |
| 1085 | $field, |
| 1086 | array( |
| 1087 | 'class' => 'everest-forms-hidden', |
| 1088 | ) |
| 1089 | ); |
| 1090 | } |
| 1091 | |
| 1092 | if ( 'select' === $field['type'] ) { |
| 1093 | $selection_btn = array(); |
| 1094 | $selection_types = array( |
| 1095 | 'single' => array( |
| 1096 | 'type' => 'radio', |
| 1097 | 'label' => esc_html__( 'Single Selection', 'everest-forms' ), |
| 1098 | ), |
| 1099 | 'multiple' => array( |
| 1100 | 'type' => 'checkbox', |
| 1101 | 'label' => esc_html__( 'Multiple Selection', 'everest-forms' ), |
| 1102 | ), |
| 1103 | ); |
| 1104 | |
| 1105 | $active_type = ! empty( $field['multiple_choices'] ) && '1' === $field['multiple_choices'] ? 'multiple' : 'single'; |
| 1106 | foreach ( $selection_types as $key => $selection_type ) { |
| 1107 | $selection_btn[ $key ] = '<span data-selection="' . esc_attr( $key ) . '" data-type="' . esc_attr( $selection_type['type'] ) . '" class="flex everest-forms-btn ' . ( $active_type === $key ? 'is-active' : '' ) . ' ' . ( false === $licensed && 'multiple' === $key ? 'upgrade-modal' : '' ) . '" data-feature="' . esc_html__( 'Multiple selection', 'everest-forms' ) . '">' . esc_html( $selection_type['label'] ) . '</span>'; |
| 1108 | } |
| 1109 | |
| 1110 | $field_content .= sprintf( |
| 1111 | '<div class="flex everest-forms-btn-group everest-forms-btn-group--inline"><input type="hidden" id="everest-forms-field-option-%1$s-multiple_choices" name="form_fields[%1$s][multiple_choices]" value="%2$s" />%3$s</div>', |
| 1112 | esc_attr( $field['id'] ), |
| 1113 | ! empty( $field['multiple_choices'] ) && '1' === $field['multiple_choices'] ? 1 : 0, |
| 1114 | implode( '', $selection_btn ) |
| 1115 | ); |
| 1116 | } |
| 1117 | |
| 1118 | // Field contents. |
| 1119 | $field_content .= sprintf( |
| 1120 | '<ul data-next-id="%s" class="evf-choices-list %s" data-field-id="%s" data-field-type="%s">', |
| 1121 | max( array_keys( $choices ) ) + 1, |
| 1122 | evf_sanitize_classes( $class, true ), |
| 1123 | $field['id'], |
| 1124 | $this->type |
| 1125 | ); |
| 1126 | foreach ( $choices as $key => $choice ) { |
| 1127 | $default = ! empty( $choice['default'] ) ? $choice['default'] : ''; |
| 1128 | $name = sprintf( 'form_fields[%s][choices][%s]', $field['id'], $key ); |
| 1129 | $image = ! empty( $choice['image'] ) ? $choice['image'] : ''; |
| 1130 | |
| 1131 | // BW compatibility for value in payment fields. |
| 1132 | if ( ! empty( $field['amount'][ $key ]['value'] ) ) { |
| 1133 | $choice['value'] = evf_format_amount( evf_sanitize_amount( $field['amount'][ $key ]['value'] ) ); |
| 1134 | } |
| 1135 | |
| 1136 | $field_content .= sprintf( '<li data-key="%1$d">', absint( $key ) ); |
| 1137 | $field_content .= '<span class="sort"><svg width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><path d="M13,8c0.6,0,1-0.4,1-1s-0.4-1-1-1s-1,0.4-1,1S12.4,8,13,8z M5,6C4.4,6,4,6.4,4,7s0.4,1,1,1s1-0.4,1-1S5.6,6,5,6z M5,10 c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S5.6,10,5,10z M13,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S13.6,10,13,10z M9,6 C8.4,6,8,6.4,8,7s0.4,1,1,1s1-0.4,1-1S9.6,6,9,6z M9,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S9.6,10,9,10z"></path></svg></span>'; |
| 1138 | $field_content .= sprintf( '<input type="%1$s" name="%2$s[default]" class="default" value="1" %3$s>', $input_type, $name, checked( '1', $default, false ) ); |
| 1139 | $field_content .= '<div class="evf-choice-list-input">'; |
| 1140 | $field_content .= sprintf( '<input type="text" name="%1$s[label]" value="%2$s" class="label" data-key="%3$s">', $name, esc_attr( $choice['label'] ), absint( $key ) ); |
| 1141 | if ( in_array( $field['type'], array( 'payment-multiple', 'payment-checkbox' ), true ) ) { |
| 1142 | $field_content .= sprintf( '<input type="text" name="%1$s[value]" value="%2$s" class="value evf-money-input" placeholder="%3$s">', $name, esc_attr( $choice['value'] ), evf_format_amount( 0 ) ); |
| 1143 | } else { |
| 1144 | $field_content .= sprintf( '<input type="text" name="%1$s[value]" value="%2$s" class="value">', $name, esc_attr( $choice['value'] ) ); |
| 1145 | } |
| 1146 | $field_content .= '</div>'; |
| 1147 | $field_content .= '<a class="add" href="#"><i class="dashicons dashicons-plus-alt"></i></a>'; |
| 1148 | $field_content .= '<a class="remove" href="#"><i class="dashicons dashicons-dismiss"></i></a>'; |
| 1149 | $field_content .= '<div class="everest-forms-attachment-media-view">'; |
| 1150 | $field_content .= sprintf( '<input type="hidden" class="source" name="%s[image]" value="%s">', $name, esc_url_raw( $image ) ); |
| 1151 | $field_content .= sprintf( '<button type="button" class="upload-button button-add-media"%s>%s</button>', ! empty( $image ) ? ' style="display:none;"' : '', esc_html__( 'Upload Image', 'everest-forms' ) ); |
| 1152 | $field_content .= '<div class="thumbnail thumbnail-image">'; |
| 1153 | if ( ! empty( $image ) ) { |
| 1154 | $field_content .= sprintf( '<img class="attachment-thumb" src="%1$s">', esc_url_raw( $image ) ); |
| 1155 | } |
| 1156 | $field_content .= '</div>'; |
| 1157 | $field_content .= sprintf( '<div class="actions"%s>', empty( $image ) ? ' style="display:none;"' : '' ); |
| 1158 | $field_content .= sprintf( '<button type="button" class="button remove-button">%1$s</button>', esc_html__( 'Remove', 'everest-forms' ) ); |
| 1159 | $field_content .= sprintf( '<button type="button" class="button upload-button">%1$s</button>', esc_html__( 'Change image', 'everest-forms' ) ); |
| 1160 | $field_content .= '</div>'; |
| 1161 | $field_content .= '</div>'; |
| 1162 | $field_content .= '</li>'; |
| 1163 | } |
| 1164 | $field_content .= '</ul>'; |
| 1165 | |
| 1166 | // Final field output. |
| 1167 | $output = $this->field_element( |
| 1168 | 'row', |
| 1169 | $field, |
| 1170 | array( |
| 1171 | 'slug' => 'choices', |
| 1172 | 'content' => $field_label . $field_content, |
| 1173 | ), |
| 1174 | $echo |
| 1175 | ); |
| 1176 | break; |
| 1177 | |
| 1178 | /* |
| 1179 | * Choices Images. |
| 1180 | */ |
| 1181 | case 'choices_images': |
| 1182 | $field_content = sprintf( |
| 1183 | '<div class="notice notice-warning%s"><p>%s</p></div>', |
| 1184 | empty( $field['choices_images'] ) ? ' hidden' : '', |
| 1185 | esc_html__( 'For best results, images should be square and at least 200 × 160 pixels or smaller.', 'everest-forms' ) |
| 1186 | ); |
| 1187 | |
| 1188 | $field_content .= $this->field_element( |
| 1189 | 'toggle', |
| 1190 | $field, |
| 1191 | array( |
| 1192 | 'slug' => 'choices_images', |
| 1193 | 'value' => isset( $field['choices_images'] ) ? '1' : '0', |
| 1194 | 'desc' => esc_html__( 'Use image choices', 'everest-forms' ), |
| 1195 | 'tooltip' => esc_html__( 'Check this option to enable using images with the choices.', 'everest-forms' ), |
| 1196 | ), |
| 1197 | false |
| 1198 | ); |
| 1199 | |
| 1200 | // Final field output. |
| 1201 | $output = $this->field_element( |
| 1202 | 'row', |
| 1203 | $field, |
| 1204 | array( |
| 1205 | 'slug' => 'choices_images', |
| 1206 | 'content' => $field_content, |
| 1207 | ), |
| 1208 | $echo |
| 1209 | ); |
| 1210 | break; |
| 1211 | |
| 1212 | /** |
| 1213 | * Add bulk options. |
| 1214 | */ |
| 1215 | case 'add_bulk_options': |
| 1216 | $class = ! empty( $args['class'] ) ? esc_attr( $args['class'] ) : ''; |
| 1217 | $label = ! empty( $args['label'] ) ? esc_html( $args['label'] ) : esc_html__( 'Add Bulk Options', 'everest-forms' ); |
| 1218 | |
| 1219 | // Field label. |
| 1220 | $field_label = $this->field_element( |
| 1221 | 'label', |
| 1222 | $field, |
| 1223 | array( |
| 1224 | 'slug' => 'add_bulk_options', |
| 1225 | 'value' => $label, |
| 1226 | 'tooltip' => esc_html__( 'Add multiple options at once.', 'everest-forms' ), |
| 1227 | 'after_tooltip' => sprintf( '<a class="evf-toggle-presets-list" href="#">%s</a>', esc_html__( 'Presets', 'everest-forms' ) ), |
| 1228 | ), |
| 1229 | false |
| 1230 | ); |
| 1231 | |
| 1232 | // Preset contents. |
| 1233 | $presets = array( |
| 1234 | array( |
| 1235 | 'label' => esc_html__( 'Months', 'everest-forms' ), |
| 1236 | 'class' => 'evf-options-preset-months', |
| 1237 | 'options' => array( |
| 1238 | esc_html__( 'January', 'everest-forms' ), |
| 1239 | esc_html__( 'February', 'everest-forms' ), |
| 1240 | esc_html__( 'March', 'everest-forms' ), |
| 1241 | esc_html__( 'April', 'everest-forms' ), |
| 1242 | esc_html__( 'May', 'everest-forms' ), |
| 1243 | esc_html__( 'June', 'everest-forms' ), |
| 1244 | esc_html__( 'July', 'everest-forms' ), |
| 1245 | esc_html__( 'August', 'everest-forms' ), |
| 1246 | esc_html__( 'September', 'everest-forms' ), |
| 1247 | esc_html__( 'October', 'everest-forms' ), |
| 1248 | esc_html__( 'November', 'everest-forms' ), |
| 1249 | esc_html__( 'December', 'everest-forms' ), |
| 1250 | ), |
| 1251 | ), |
| 1252 | array( |
| 1253 | 'label' => esc_html__( 'Week Days', 'everest-forms' ), |
| 1254 | 'class' => 'evf-options-preset-week-days', |
| 1255 | 'options' => array( |
| 1256 | esc_html__( 'Sunday', 'everest-forms' ), |
| 1257 | esc_html__( 'Monday', 'everest-forms' ), |
| 1258 | esc_html__( 'Tuesday', 'everest-forms' ), |
| 1259 | esc_html__( 'Wednesday', 'everest-forms' ), |
| 1260 | esc_html__( 'Thursday', 'everest-forms' ), |
| 1261 | esc_html__( 'Friday', 'everest-forms' ), |
| 1262 | esc_html__( 'Saturday', 'everest-forms' ), |
| 1263 | ), |
| 1264 | ), |
| 1265 | array( |
| 1266 | 'label' => esc_html__( 'Countries', 'everest-forms' ), |
| 1267 | 'class' => 'evf-options-preset-countries', |
| 1268 | 'options' => array_values( evf_get_countries() ), |
| 1269 | ), |
| 1270 | array( |
| 1271 | 'label' => esc_html__( 'Countries Postal Code', 'everest-forms' ), |
| 1272 | 'class' => 'evf-options-preset-countries-postal-code', |
| 1273 | 'options' => array_keys( evf_get_countries() ), |
| 1274 | ), |
| 1275 | array( |
| 1276 | 'label' => esc_html__( 'U.S. States', 'everest-forms' ), |
| 1277 | 'class' => 'evf-options-preset-states', |
| 1278 | 'options' => array_values( evf_get_states()['US'] ), |
| 1279 | ), |
| 1280 | array( |
| 1281 | 'label' => esc_html__( 'U.S. States Postal Code', 'everest-forms' ), |
| 1282 | 'class' => 'evf-options-preset-states-postal-code', |
| 1283 | 'options' => array_keys( evf_get_states()['US'] ), |
| 1284 | ), |
| 1285 | array( |
| 1286 | 'label' => esc_html__( 'Age Groups', 'everest-forms' ), |
| 1287 | 'class' => 'evf-options-preset-age-groups', |
| 1288 | 'options' => array( |
| 1289 | esc_html__( 'Under 18', 'everest-forms' ), |
| 1290 | esc_html__( '18-24', 'everest-forms' ), |
| 1291 | esc_html__( '25-34', 'everest-forms' ), |
| 1292 | esc_html__( '35-44', 'everest-forms' ), |
| 1293 | esc_html__( '45-54', 'everest-forms' ), |
| 1294 | esc_html__( '55-64', 'everest-forms' ), |
| 1295 | esc_html__( '65 or Above', 'everest-forms' ), |
| 1296 | esc_html__( 'Prefer Not to Answer', 'everest-forms' ), |
| 1297 | ), |
| 1298 | ), |
| 1299 | array( |
| 1300 | 'label' => esc_html__( 'Satisfaction', 'everest-forms' ), |
| 1301 | 'class' => 'evf-options-preset-satisfaction', |
| 1302 | 'options' => array( |
| 1303 | esc_html__( 'Very Satisfied', 'everest-forms' ), |
| 1304 | esc_html__( 'Satisfied', 'everest-forms' ), |
| 1305 | esc_html__( 'Neutral', 'everest-forms' ), |
| 1306 | esc_html__( 'Unsatisfied', 'everest-forms' ), |
| 1307 | esc_html__( 'Very Unsatisfied', 'everest-forms' ), |
| 1308 | esc_html__( 'N/A', 'everest-forms' ), |
| 1309 | ), |
| 1310 | ), |
| 1311 | array( |
| 1312 | 'label' => esc_html__( 'Importance', 'everest-forms' ), |
| 1313 | 'class' => 'evf-options-preset-importance', |
| 1314 | 'options' => array( |
| 1315 | esc_html__( 'Very Important', 'everest-forms' ), |
| 1316 | esc_html__( 'Important', 'everest-forms' ), |
| 1317 | esc_html__( 'Neutral', 'everest-forms' ), |
| 1318 | esc_html__( 'Somewhat Important', 'everest-forms' ), |
| 1319 | esc_html__( 'Not at all Important', 'everest-forms' ), |
| 1320 | esc_html__( 'N/A', 'everest-forms' ), |
| 1321 | ), |
| 1322 | ), |
| 1323 | array( |
| 1324 | 'label' => esc_html__( 'Agreement', 'everest-forms' ), |
| 1325 | 'class' => 'evf-options-preset-agreement', |
| 1326 | 'options' => array( |
| 1327 | esc_html__( 'Strongly Agree', 'everest-forms' ), |
| 1328 | esc_html__( 'Agree', 'everest-forms' ), |
| 1329 | esc_html__( 'Neutral', 'everest-forms' ), |
| 1330 | esc_html__( 'Disagree', 'everest-forms' ), |
| 1331 | esc_html__( 'Strongly Disagree', 'everest-forms' ), |
| 1332 | esc_html__( 'N/A', 'everest-forms' ), |
| 1333 | ), |
| 1334 | ), |
| 1335 | ); |
| 1336 | $presets_html = '<div class="evf-options-presets" hidden>'; |
| 1337 | foreach ( $presets as $preset ) { |
| 1338 | $presets_html .= sprintf( '<div class="evf-options-preset %s">', esc_attr( $preset['class'] ) ); |
| 1339 | $presets_html .= sprintf( '<a class="evf-options-preset-label" href="#">%s</a>', $preset['label'] ); |
| 1340 | $presets_html .= sprintf( '<textarea hidden class="evf-options-preset-value">%s</textarea>', implode( "\n", $preset['options'] ) ); |
| 1341 | $presets_html .= '</div>'; |
| 1342 | } |
| 1343 | $presets_html .= '</div>'; |
| 1344 | |
| 1345 | // Field contents. |
| 1346 | $field_content = $this->field_element( |
| 1347 | 'textarea', |
| 1348 | $field, |
| 1349 | array( |
| 1350 | 'slug' => 'add_bulk_options', |
| 1351 | 'value' => '', |
| 1352 | ), |
| 1353 | false |
| 1354 | ); |
| 1355 | $field_content .= sprintf( '<a class="button button-small evf-add-bulk-options" href="#">%s</a>', esc_html__( 'Add New Choices', 'everest-forms' ) ); |
| 1356 | |
| 1357 | // Final field output. |
| 1358 | $output = $this->field_element( |
| 1359 | 'row', |
| 1360 | $field, |
| 1361 | array( |
| 1362 | 'slug' => 'add_bulk_options', |
| 1363 | 'content' => $field_label . $presets_html . $field_content, |
| 1364 | 'class' => $class, |
| 1365 | ), |
| 1366 | $echo |
| 1367 | ); |
| 1368 | break; |
| 1369 | |
| 1370 | /** |
| 1371 | * Advanced Fields. |
| 1372 | */ |
| 1373 | |
| 1374 | /* |
| 1375 | * Default value. |
| 1376 | */ |
| 1377 | case 'default_value': |
| 1378 | $value = ! empty( $field['default_value'] ) || ( isset( $field['default_value'] ) && '0' === (string) $field['default_value'] ) ? esc_attr( $field['default_value'] ) : ''; |
| 1379 | $tooltip = esc_html__( 'Enter text for the default form field value.', 'everest-forms' ); |
| 1380 | $toggle = ''; |
| 1381 | $output = $this->field_element( |
| 1382 | 'label', |
| 1383 | $field, |
| 1384 | array( |
| 1385 | 'slug' => 'default_value', |
| 1386 | 'value' => esc_html__( 'Default Value', 'everest-forms' ), |
| 1387 | 'tooltip' => $tooltip, |
| 1388 | 'after_tooltip' => $toggle, |
| 1389 | ), |
| 1390 | false |
| 1391 | ); |
| 1392 | $output .= $this->field_element( |
| 1393 | 'text', |
| 1394 | $field, |
| 1395 | array( |
| 1396 | 'slug' => 'default_value', |
| 1397 | 'value' => $value, |
| 1398 | ), |
| 1399 | false |
| 1400 | ); |
| 1401 | |
| 1402 | // Smart tag for default value. |
| 1403 | $exclude_fields = array( 'rating', 'number', 'range-slider', 'payment-quantity', 'reset' ); |
| 1404 | |
| 1405 | if ( ! in_array( $field['type'], $exclude_fields, true ) ) { |
| 1406 | $output .= '<a href="#" class="evf-toggle-smart-tag-display" data-type="other"><span class="dashicons dashicons-editor-code"></span></a>'; |
| 1407 | $output .= '<div class="evf-smart-tag-lists" style="display: none">'; |
| 1408 | $output .= '<div class="smart-tag-title other-tag-title">Others</div><ul class="evf-others"></ul></div>'; |
| 1409 | } |
| 1410 | |
| 1411 | $output = $this->field_element( |
| 1412 | 'row', |
| 1413 | $field, |
| 1414 | array( |
| 1415 | 'slug' => 'default_value', |
| 1416 | 'content' => $output, |
| 1417 | 'class' => in_array( $field['type'], $exclude_fields, true ) ? '' : 'evf_smart_tag', |
| 1418 | ), |
| 1419 | $echo |
| 1420 | ); |
| 1421 | break; |
| 1422 | |
| 1423 | /* |
| 1424 | * Advanced Options markup. |
| 1425 | */ |
| 1426 | case 'advanced-options': |
| 1427 | $markup = ! empty( $args['markup'] ) ? $args['markup'] : 'open'; |
| 1428 | |
| 1429 | if ( 'open' === $markup ) { |
| 1430 | $override = apply_filters( 'everest_forms_advanced_options_override', false ); |
| 1431 | $override = ! empty( $override ) ? 'style="display:' . $override . ';"' : ''; |
| 1432 | if ( $echo ) { |
| 1433 | echo sprintf( '<div class="everest-forms-field-option-group everest-forms-field-option-group-advanced everest-forms-hide closed" id="everest-forms-field-option-advanced-%s" %s>', esc_attr( $field['id'] ), ( ! empty( $override ) ? 'style="display:' . esc_attr( apply_filters( 'everest_forms_advanced_options_override', false ) ) . ';"' : '' ) ); |
| 1434 | echo sprintf( '<a href="#" class="everest-forms-field-option-group-toggle">%s<i class="handlediv"></i></a>', esc_html__( 'Advanced Options', 'everest-forms' ) ); |
| 1435 | echo '<div class="everest-forms-field-option-group-inner">'; |
| 1436 | } else { |
| 1437 | $output = sprintf( '<div class="everest-forms-field-option-group everest-forms-field-option-group-advanced everest-forms-hide closed" id="everest-forms-field-option-advanced-%s" %s>', $field['id'], $override ); |
| 1438 | $output .= sprintf( '<a href="#" class="everest-forms-field-option-group-toggle">%s<i class="handlediv"></i></a>', __( 'Advanced Options', 'everest-forms' ) ); |
| 1439 | $output .= '<div class="everest-forms-field-option-group-inner">'; |
| 1440 | } |
| 1441 | } else { |
| 1442 | if ( $echo ) { |
| 1443 | echo '</div></div>'; |
| 1444 | } else { |
| 1445 | $output = '</div></div>'; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | break; |
| 1450 | |
| 1451 | /* |
| 1452 | * Placeholder. |
| 1453 | */ |
| 1454 | case 'placeholder': |
| 1455 | $value = ! empty( $field['placeholder'] ) || ( isset( $field['placeholder'] ) && '0' === (string) $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : ''; |
| 1456 | $tooltip = esc_html__( 'Enter text for the form field placeholder.', 'everest-forms' ); |
| 1457 | $output = $this->field_element( |
| 1458 | 'label', |
| 1459 | $field, |
| 1460 | array( |
| 1461 | 'slug' => 'placeholder', |
| 1462 | 'value' => esc_html__( 'Placeholder Text', 'everest-forms' ), |
| 1463 | 'tooltip' => $tooltip, |
| 1464 | ), |
| 1465 | false |
| 1466 | ); |
| 1467 | $output .= $this->field_element( |
| 1468 | 'text', |
| 1469 | $field, |
| 1470 | array( |
| 1471 | 'slug' => 'placeholder', |
| 1472 | 'value' => $value, |
| 1473 | ), |
| 1474 | false |
| 1475 | ); |
| 1476 | $output = $this->field_element( |
| 1477 | 'row', |
| 1478 | $field, |
| 1479 | array( |
| 1480 | 'slug' => 'placeholder', |
| 1481 | 'content' => $output, |
| 1482 | ), |
| 1483 | $echo |
| 1484 | ); |
| 1485 | break; |
| 1486 | case 'enable_prepopulate': |
| 1487 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 1488 | $value = ! empty( $field['enable_prepopulate'] ) ? esc_attr( $field['enable_prepopulate'] ) : ''; |
| 1489 | $tooltip = esc_html__( 'Enable this option to allow field to be populated dynamically', 'everest-forms' ); |
| 1490 | $output = $this->field_element( |
| 1491 | 'toggle', |
| 1492 | $field, |
| 1493 | array( |
| 1494 | 'slug' => 'enable_prepopulate', |
| 1495 | 'value' => $value, |
| 1496 | 'desc' => esc_html__( 'Enable Autopopulate ', 'everest-forms' ), |
| 1497 | 'tooltip' => $tooltip, |
| 1498 | ), |
| 1499 | false |
| 1500 | ); |
| 1501 | $output = $this->field_element( |
| 1502 | 'row', |
| 1503 | $field, |
| 1504 | array( |
| 1505 | 'slug' => 'enable_prepopulate', |
| 1506 | 'content' => $output, |
| 1507 | ), |
| 1508 | $echo |
| 1509 | ); |
| 1510 | break; |
| 1511 | case 'parameter_name': |
| 1512 | $toggle = ''; |
| 1513 | $tooltip = esc_html__( 'Enter name of the parameter to populate the field.', 'everest-forms' ); |
| 1514 | $value = ! empty( $field['parameter_name'] ) ? esc_attr( $field['parameter_name'] ) : ''; |
| 1515 | |
| 1516 | // Build output. |
| 1517 | $output = $this->field_element( |
| 1518 | 'label', |
| 1519 | $field, |
| 1520 | array( |
| 1521 | 'slug' => 'parameter_name', |
| 1522 | 'value' => esc_html__( 'Parameter Name', 'everest-forms' ), |
| 1523 | 'tooltip' => $tooltip, |
| 1524 | 'after_tooltip' => $toggle, |
| 1525 | ), |
| 1526 | false |
| 1527 | ); |
| 1528 | $output .= $this->field_element( |
| 1529 | 'text', |
| 1530 | $field, |
| 1531 | array( |
| 1532 | 'slug' => 'parameter_name', |
| 1533 | 'value' => $value, |
| 1534 | ), |
| 1535 | false |
| 1536 | ); |
| 1537 | $output = $this->field_element( |
| 1538 | 'row', |
| 1539 | $field, |
| 1540 | array( |
| 1541 | 'slug' => 'parameter_name', |
| 1542 | 'content' => $output, |
| 1543 | 'class' => isset( $field['enable_prepopulate'] ) ? '' : 'hidden', |
| 1544 | ), |
| 1545 | $echo |
| 1546 | ); |
| 1547 | break; |
| 1548 | |
| 1549 | /** |
| 1550 | * Regex Validation |
| 1551 | */ |
| 1552 | case 'regex_validation': |
| 1553 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 1554 | $value = ! empty( $field['enable_regex_validation'] ) ? esc_attr( $field['enable_regex_validation'] ) : ''; |
| 1555 | $tooltip = esc_html__( 'Enable this option to allow regex validation for this field.', 'everest-forms' ); |
| 1556 | $output = $this->field_element( |
| 1557 | 'toggle', |
| 1558 | $field, |
| 1559 | array( |
| 1560 | 'slug' => 'enable_regex_validation', |
| 1561 | 'value' => $value, |
| 1562 | 'desc' => esc_html__( 'Enable Regex Validation ', 'everest-forms' ), |
| 1563 | 'tooltip' => $tooltip, |
| 1564 | ), |
| 1565 | false |
| 1566 | ); |
| 1567 | $output = $this->field_element( |
| 1568 | 'row', |
| 1569 | $field, |
| 1570 | array( |
| 1571 | 'slug' => 'enable_regex_validation', |
| 1572 | 'content' => $output, |
| 1573 | ), |
| 1574 | $echo |
| 1575 | ); |
| 1576 | break; |
| 1577 | |
| 1578 | case 'regex_value': |
| 1579 | $toggle = ''; |
| 1580 | $tooltip = esc_html__( 'Regular expression value is checked against.', 'everest-forms' ); |
| 1581 | $value = ! empty( $field['regex_value'] ) ? esc_attr( $field['regex_value'] ) : ''; |
| 1582 | |
| 1583 | // Build output. |
| 1584 | $output = $this->field_element( |
| 1585 | 'label', |
| 1586 | $field, |
| 1587 | array( |
| 1588 | 'slug' => 'regex_value', |
| 1589 | 'value' => esc_html__( 'Regex Value', 'everest-forms' ), |
| 1590 | 'tooltip' => $tooltip, |
| 1591 | 'after_tooltip' => $toggle, |
| 1592 | ), |
| 1593 | false |
| 1594 | ); |
| 1595 | $output .= $this->field_element( |
| 1596 | 'text', |
| 1597 | $field, |
| 1598 | array( |
| 1599 | 'slug' => 'regex_value', |
| 1600 | 'value' => $value, |
| 1601 | ), |
| 1602 | false |
| 1603 | ); |
| 1604 | // Smart tag for default value. |
| 1605 | $include_fields = array( 'email', 'first-name', 'last-name', 'number', 'text', 'url' ); |
| 1606 | |
| 1607 | if ( in_array( $field['type'], $include_fields, true ) ) { |
| 1608 | $output .= '<a href="#" class="evf-toggle-smart-tag-display" data-type="regex"><span class="dashicons dashicons-editor-code"></span></a>'; |
| 1609 | $output .= '<div class="evf-smart-tag-lists" style="display: none">'; |
| 1610 | $output .= '<div class="smart-tag-title other-tag-title">Regular Expression</div><ul class="evf-regex"></ul></div>'; |
| 1611 | } |
| 1612 | |
| 1613 | $output = $this->field_element( |
| 1614 | 'row', |
| 1615 | $field, |
| 1616 | array( |
| 1617 | 'slug' => 'regex_value', |
| 1618 | 'content' => $output, |
| 1619 | 'class' => ! in_array( $field['type'], $include_fields, true ) && isset( $field['enable_regex_validation'] ) ? '' : ' hidden evf_smart_tag', |
| 1620 | ), |
| 1621 | $echo |
| 1622 | ); |
| 1623 | |
| 1624 | break; |
| 1625 | |
| 1626 | case 'regex_message': |
| 1627 | $toggle = ''; |
| 1628 | $tooltip = esc_html__( 'if the regular expression value does not match it will show this message.', 'everest-forms' ); |
| 1629 | $value = ! empty( $field['regex_message'] ) ? esc_attr( $field['regex_message'] ) : 'Please provide a valid value for this field.'; |
| 1630 | |
| 1631 | // Build output. |
| 1632 | $output = $this->field_element( |
| 1633 | 'label', |
| 1634 | $field, |
| 1635 | array( |
| 1636 | 'slug' => 'regex_message', |
| 1637 | 'value' => esc_html__( 'Validation Message for Regular expression', 'everest-forms' ), |
| 1638 | 'tooltip' => $tooltip, |
| 1639 | 'after_tooltip' => $toggle, |
| 1640 | ), |
| 1641 | false |
| 1642 | ); |
| 1643 | $output .= $this->field_element( |
| 1644 | 'text', |
| 1645 | $field, |
| 1646 | array( |
| 1647 | 'slug' => 'regex_message', |
| 1648 | 'value' => $value, |
| 1649 | ), |
| 1650 | false |
| 1651 | ); |
| 1652 | $output = $this->field_element( |
| 1653 | 'row', |
| 1654 | $field, |
| 1655 | array( |
| 1656 | 'slug' => 'regex_message', |
| 1657 | 'content' => $output, |
| 1658 | 'class' => isset( $field['enable_regex_validation'] ) ? '' : 'hidden', |
| 1659 | ), |
| 1660 | $echo |
| 1661 | ); |
| 1662 | break; |
| 1663 | |
| 1664 | /* |
| 1665 | * CSS classes. |
| 1666 | */ |
| 1667 | case 'css': |
| 1668 | $toggle = ''; |
| 1669 | $tooltip = esc_html__( 'Enter CSS class names for this field container. Multiple class names should be separated with spaces.', 'everest-forms' ); |
| 1670 | $value = ! empty( $field['css'] ) ? esc_attr( $field['css'] ) : ''; |
| 1671 | |
| 1672 | // Build output. |
| 1673 | $output = $this->field_element( |
| 1674 | 'label', |
| 1675 | $field, |
| 1676 | array( |
| 1677 | 'slug' => 'css', |
| 1678 | 'value' => esc_html__( 'CSS Classes', 'everest-forms' ), |
| 1679 | 'tooltip' => $tooltip, |
| 1680 | 'after_tooltip' => $toggle, |
| 1681 | ), |
| 1682 | false |
| 1683 | ); |
| 1684 | $output .= $this->field_element( |
| 1685 | 'text', |
| 1686 | $field, |
| 1687 | array( |
| 1688 | 'slug' => 'css', |
| 1689 | 'value' => $value, |
| 1690 | ), |
| 1691 | false |
| 1692 | ); |
| 1693 | $output = $this->field_element( |
| 1694 | 'row', |
| 1695 | $field, |
| 1696 | array( |
| 1697 | 'slug' => 'css', |
| 1698 | 'content' => $output, |
| 1699 | ), |
| 1700 | $echo |
| 1701 | ); |
| 1702 | break; |
| 1703 | |
| 1704 | /* |
| 1705 | * Hide Label. |
| 1706 | */ |
| 1707 | case 'label_hide': |
| 1708 | $value = isset( $field['label_hide'] ) ? $field['label_hide'] : '0'; |
| 1709 | $tooltip = esc_html__( 'Check this option to hide the form field label.', 'everest-forms' ); |
| 1710 | |
| 1711 | // Build output. |
| 1712 | $output = $this->field_element( |
| 1713 | 'toggle', |
| 1714 | $field, |
| 1715 | array( |
| 1716 | 'slug' => 'label_hide', |
| 1717 | 'value' => $value, |
| 1718 | 'desc' => esc_html__( 'Hide Label', 'everest-forms' ), |
| 1719 | 'tooltip' => $tooltip, |
| 1720 | ), |
| 1721 | false |
| 1722 | ); |
| 1723 | $output = $this->field_element( |
| 1724 | 'row', |
| 1725 | $field, |
| 1726 | array( |
| 1727 | 'slug' => 'label_hide', |
| 1728 | 'content' => $output, |
| 1729 | ), |
| 1730 | $echo |
| 1731 | ); |
| 1732 | break; |
| 1733 | |
| 1734 | /* |
| 1735 | * Hide Sub-Labels. |
| 1736 | */ |
| 1737 | case 'sublabel_hide': |
| 1738 | $value = isset( $field['sublabel_hide'] ) ? $field['sublabel_hide'] : '0'; |
| 1739 | $tooltip = esc_html__( 'Check this option to hide the form field sub-label.', 'everest-forms' ); |
| 1740 | |
| 1741 | // Build output. |
| 1742 | $output = $this->field_element( |
| 1743 | 'toggle', |
| 1744 | $field, |
| 1745 | array( |
| 1746 | 'slug' => 'sublabel_hide', |
| 1747 | 'value' => $value, |
| 1748 | 'desc' => esc_html__( 'Hide Sub-Labels', 'everest-forms' ), |
| 1749 | 'tooltip' => $tooltip, |
| 1750 | ), |
| 1751 | false |
| 1752 | ); |
| 1753 | $output = $this->field_element( |
| 1754 | 'row', |
| 1755 | $field, |
| 1756 | array( |
| 1757 | 'slug' => 'sublabel_hide', |
| 1758 | 'content' => $output, |
| 1759 | ), |
| 1760 | $echo |
| 1761 | ); |
| 1762 | break; |
| 1763 | |
| 1764 | /* |
| 1765 | * Input columns. |
| 1766 | */ |
| 1767 | case 'input_columns': |
| 1768 | $value = ! empty( $field['input_columns'] ) ? esc_attr( $field['input_columns'] ) : ''; |
| 1769 | $tooltip = esc_html__( 'Select the column layout for displaying field choices.', 'everest-forms' ); |
| 1770 | $options = array( |
| 1771 | '' => esc_html__( 'One Column', 'everest-forms' ), |
| 1772 | '2' => esc_html__( 'Two Columns', 'everest-forms' ), |
| 1773 | '3' => esc_html__( 'Three Columns', 'everest-forms' ), |
| 1774 | 'inline' => esc_html__( 'Inline', 'everest-forms' ), |
| 1775 | ); |
| 1776 | |
| 1777 | // Build output. |
| 1778 | $output = $this->field_element( |
| 1779 | 'label', |
| 1780 | $field, |
| 1781 | array( |
| 1782 | 'slug' => 'input_columns', |
| 1783 | 'value' => esc_html__( 'Layout', 'everest-forms' ), |
| 1784 | 'tooltip' => $tooltip, |
| 1785 | ), |
| 1786 | false |
| 1787 | ); |
| 1788 | $output .= $this->field_element( |
| 1789 | 'select', |
| 1790 | $field, |
| 1791 | array( |
| 1792 | 'slug' => 'input_columns', |
| 1793 | 'value' => $value, |
| 1794 | 'options' => $options, |
| 1795 | ), |
| 1796 | false |
| 1797 | ); |
| 1798 | $output = $this->field_element( |
| 1799 | 'row', |
| 1800 | $field, |
| 1801 | array( |
| 1802 | 'slug' => 'input_columns', |
| 1803 | 'content' => $output, |
| 1804 | ), |
| 1805 | $echo |
| 1806 | ); |
| 1807 | break; |
| 1808 | |
| 1809 | /** |
| 1810 | * Whitelisted Domain. |
| 1811 | */ |
| 1812 | case 'whitelist_domain': |
| 1813 | $default = ! empty( $args['default'] ) ? $args['default'] : '0'; |
| 1814 | // $value for just backward compatibility. |
| 1815 | $value = ( isset( $field['whitelist_domain'] ) && ! empty( $field['whitelist_domain'] ) ) ? esc_attr( $field['whitelist_domain'] ) : ''; |
| 1816 | $allowed_domains = ( isset( $field['allowed_domains'] ) && ! empty( $field['allowed_domains'] ) ) ? esc_attr( $field['allowed_domains'] ) : ( ( isset( $field['select_whitelist'] ) && 'allow' === $field['select_whitelist'] ) ? $value : '' ); |
| 1817 | $denied_domains = ( isset( $field['denied_domains'] ) && ! empty( $field['denied_domains'] ) ) ? esc_attr( $field['denied_domains'] ) : ( ( isset( $field['select_whitelist'] ) && 'deny' === $field['select_whitelist'] ) ? $value : '' ); |
| 1818 | $style = ( isset( $field['select_whitelist'] ) && ! empty( $field['select_whitelist'] ) ) ? esc_attr( $field['select_whitelist'] ) : 'allow'; |
| 1819 | $tooltip = esc_html__( 'Please enter valid allowed or denied domains, separated by commas. For example: google.com, yahoo.com', 'everest-forms' ); |
| 1820 | $output = $this->field_element( |
| 1821 | 'label', |
| 1822 | $field, |
| 1823 | array( |
| 1824 | 'slug' => 'whitelist_domain', |
| 1825 | 'value' => esc_html__( 'Whitelisted Domains', 'everest-forms' ), |
| 1826 | 'tooltip' => $tooltip, |
| 1827 | ), |
| 1828 | false |
| 1829 | ); |
| 1830 | $output .= $this->field_element( |
| 1831 | 'select', |
| 1832 | $field, |
| 1833 | array( |
| 1834 | 'slug' => 'select_whitelist', |
| 1835 | 'value' => $style, |
| 1836 | 'options' => array( |
| 1837 | 'allow' => esc_html__( 'Allowed Domains', 'everest-forms' ), |
| 1838 | 'deny' => esc_html__( 'Denied Domains', 'everest-forms' ), |
| 1839 | ), |
| 1840 | ), |
| 1841 | false |
| 1842 | ); |
| 1843 | $output = $this->field_element( |
| 1844 | 'row', |
| 1845 | $field, |
| 1846 | array( |
| 1847 | 'slug' => 'whitelist_domain', |
| 1848 | 'content' => $output, |
| 1849 | ), |
| 1850 | $echo |
| 1851 | ); |
| 1852 | |
| 1853 | $output .= $this->field_element( |
| 1854 | 'row', |
| 1855 | $field, |
| 1856 | array( |
| 1857 | 'slug' => 'allowed_domains', |
| 1858 | 'content' => $this->field_element( |
| 1859 | 'text', |
| 1860 | $field, |
| 1861 | array( |
| 1862 | 'slug' => 'allowed_domains', |
| 1863 | 'value' => esc_attr( $allowed_domains ), |
| 1864 | 'placeholder' => esc_attr__( 'Allowed Domain(s)', 'everest-forms' ), |
| 1865 | ), |
| 1866 | false |
| 1867 | ), |
| 1868 | ), |
| 1869 | $echo |
| 1870 | ); |
| 1871 | $output .= $this->field_element( |
| 1872 | 'row', |
| 1873 | $field, |
| 1874 | array( |
| 1875 | 'slug' => 'denied_domains', |
| 1876 | 'content' => $this->field_element( |
| 1877 | 'text', |
| 1878 | $field, |
| 1879 | array( |
| 1880 | 'slug' => 'denied_domains', |
| 1881 | 'value' => esc_attr( $denied_domains ), |
| 1882 | 'placeholder' => esc_attr__( 'Denied Domain(s)', 'everest-forms' ), |
| 1883 | ), |
| 1884 | false |
| 1885 | ), |
| 1886 | ), |
| 1887 | $echo |
| 1888 | ); |
| 1889 | break; |
| 1890 | |
| 1891 | /** |
| 1892 | * Select All. |
| 1893 | */ |
| 1894 | case 'select_all': |
| 1895 | $value = isset( $field['select_all'] ) ? '1' : '0'; |
| 1896 | $tooltip = esc_html__( 'Check this option to hide the form field label.', 'everest-forms' ); |
| 1897 | |
| 1898 | $output = $this->field_element( |
| 1899 | 'toggle', |
| 1900 | $field, |
| 1901 | array( |
| 1902 | 'slug' => 'select_all', |
| 1903 | 'value' => $value, |
| 1904 | 'class' => 'evf-select-all-chk', |
| 1905 | 'desc' => esc_html__( 'Select All', 'everest-forms' ), |
| 1906 | 'tooltip' => esc_html__( 'Check this option to select all the options.', 'everest-forms' ), |
| 1907 | ), |
| 1908 | false |
| 1909 | ); |
| 1910 | $output = $this->field_element( |
| 1911 | 'row', |
| 1912 | $field, |
| 1913 | array( |
| 1914 | 'slug' => 'select_all', |
| 1915 | 'content' => $output, |
| 1916 | ), |
| 1917 | $echo |
| 1918 | ); |
| 1919 | break; |
| 1920 | |
| 1921 | /* |
| 1922 | * Default. |
| 1923 | */ |
| 1924 | default: |
| 1925 | if ( is_callable( array( $this, $option ) ) ) { |
| 1926 | $this->{$option}( $field ); |
| 1927 | } |
| 1928 | do_action( 'everest_forms_field_options_' . $option, $this, $field, $args ); |
| 1929 | break; |
| 1930 | |
| 1931 | } |
| 1932 | |
| 1933 | if ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'open' === $markup ) { |
| 1934 | do_action( "everest_forms_field_options_top_{$option}", $field, $this ); |
| 1935 | } elseif ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'close' === $markup ) { |
| 1936 | do_action( "everest_forms_field_options_after_{$option}", $field, $this ); |
| 1937 | } |
| 1938 | |
| 1939 | if ( ! $echo ) { |
| 1940 | return $output; |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Helper function to create common field options that are used frequently |
| 1946 | * in the field preview. |
| 1947 | * |
| 1948 | * @since 1.0.0 |
| 1949 | * |
| 1950 | * @param string $option Field option to render. |
| 1951 | * @param array $field Field data and settings. |
| 1952 | * @param array $args Field preview arguments. |
| 1953 | * @param boolean $echo Print or return the value. Print by default. |
| 1954 | * |
| 1955 | * @return mixed Print or return a string. |
| 1956 | */ |
| 1957 | public function field_preview_option( $option, $field, $args = array(), $echo = true ) { |
| 1958 | $output = ''; |
| 1959 | $class = ! empty( $args['class'] ) ? evf_sanitize_classes( $args['class'] ) : ''; |
| 1960 | $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification |
| 1961 | $form_data = evf()->form->get( absint( $form_id ), array( 'content_only' => true ) ); |
| 1962 | $markup = ''; |
| 1963 | |
| 1964 | if ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'open' === $markup ) { |
| 1965 | do_action( "everest_forms_field_options_before_{$option}", $field, $this ); |
| 1966 | } elseif ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'close' === $markup ) { |
| 1967 | do_action( "everest_forms_field_options_bottom_{$option}", $field, $this ); |
| 1968 | } |
| 1969 | |
| 1970 | switch ( $option ) { |
| 1971 | case 'label': |
| 1972 | $label = isset( $field['label'] ) && ! empty( $field['label'] ) ? $field['label'] : ''; |
| 1973 | if ( $echo ) { |
| 1974 | echo sprintf( '<label class="label-title %s"><span class="text">%s</span><span class="required">%s</span></label>', esc_attr( $class ), esc_html( $label ), esc_html( apply_filters( 'everest_form_get_required_type', '*', $field, $form_data ) ) ); |
| 1975 | } else { |
| 1976 | $output = sprintf( '<label class="label-title %s"><span class="text">%s</span><span class="required">%s</span></label>', $class, $label, apply_filters( 'everest_form_get_required_type', '*', $field, $form_data ) ); |
| 1977 | } |
| 1978 | break; |
| 1979 | |
| 1980 | case 'description': |
| 1981 | $description = isset( $field['description'] ) && ! empty( $field['description'] ) ? $field['description'] : ''; |
| 1982 | $description = false !== strpos( $class, 'nl2br' ) ? nl2br( $description ) : $description; |
| 1983 | if ( $echo ) { |
| 1984 | echo sprintf( '<div class="description %s">%s</div>', esc_attr( $class ), esc_html( $description ) ); |
| 1985 | } else { |
| 1986 | $output = sprintf( '<div class="description %s">%s</div>', $class, $description ); |
| 1987 | } |
| 1988 | break; |
| 1989 | |
| 1990 | case 'repeater_fields': |
| 1991 | $repeater_fields = isset( $field['repeater_fields'] ) && ! empty( $field['repeater_fields'] ) ? $field['repeater_fields'] : ''; |
| 1992 | if ( $echo ) { |
| 1993 | echo sprintf( '<div>%s</div>', esc_html( $repeater_fields ) ); |
| 1994 | } else { |
| 1995 | $output = sprintf( '<div>%s</div>', $repeater_fields ); |
| 1996 | } |
| 1997 | break; |
| 1998 | |
| 1999 | case 'repeater_button_add_remove_label': |
| 2000 | $add_new_label = isset( $field['repeater_button_add_new_label'] ) && ! empty( $field['repeater_button_add_new_label'] ) ? $field['repeater_button_add_new_label'] : 'Add'; |
| 2001 | $remove_label = isset( $field['repeater_button_remove_label'] ) && ! empty( $field['repeater_button_remove_label'] ) ? $field['repeater_button_remove_label'] : 'Remove'; |
| 2002 | if ( $echo ) { |
| 2003 | echo sprintf( '<div style="margin-right: %s" class="evf-add-row repeater_button_add_remove_label %s"><span class="everest-forms-btn everest-forms-btn-primary dashicons dashicons-plus">%s</span> <span class="everest-forms-btn everest-forms-btn-primary dashicons dashicons-minus">%s</span></div>', '65%', esc_attr( $class ), esc_html( $add_new_label ), esc_html( $remove_label ) ); |
| 2004 | } else { |
| 2005 | $output = sprintf( '<div style="margin-right: %s" class="evf-add-row repeater_button_add_remove_label %s"><span class="everest-forms-btn everest-forms-btn-primary dashicons dashicons-plus">%s</span> <span class="everest-forms-btn everest-forms-btn-primary dashicons dashicons-minus">%s</span></div>', '65%', $class, $add_new_label, $remove_label ); |
| 2006 | } |
| 2007 | break; |
| 2008 | |
| 2009 | case 'choices': |
| 2010 | $values = ! empty( $field['choices'] ) ? $field['choices'] : $this->defaults; |
| 2011 | $choices_fields = array( 'select', 'radio', 'checkbox', 'payment-multiple', 'payment-checkbox' ); |
| 2012 | |
| 2013 | // Notify if choices source is currently empty. |
| 2014 | if ( empty( $values ) ) { |
| 2015 | $values = array( |
| 2016 | 'label' => esc_html__( '(empty)', 'everest-forms' ), |
| 2017 | ); |
| 2018 | } |
| 2019 | |
| 2020 | // Build output. |
| 2021 | if ( ! in_array( $field['type'], $choices_fields, true ) ) { |
| 2022 | break; |
| 2023 | } |
| 2024 | |
| 2025 | switch ( $field['type'] ) { |
| 2026 | case 'checkbox': |
| 2027 | case 'payment-checkbox': |
| 2028 | $type = 'checkbox'; |
| 2029 | break; |
| 2030 | |
| 2031 | case 'select': |
| 2032 | $type = 'select'; |
| 2033 | break; |
| 2034 | |
| 2035 | default: |
| 2036 | $type = 'radio'; |
| 2037 | break; |
| 2038 | } |
| 2039 | |
| 2040 | $list_class = array( 'widefat', 'primary-input' ); |
| 2041 | $choices_images = ! empty( $field['choices_images'] ); |
| 2042 | |
| 2043 | if ( $choices_images ) { |
| 2044 | $list_class[] = 'everest-forms-image-choices'; |
| 2045 | } |
| 2046 | |
| 2047 | if ( ! empty( $class ) ) { |
| 2048 | $list_class[] = $class; |
| 2049 | } |
| 2050 | |
| 2051 | if ( 'select' === $type ) { |
| 2052 | $multiple = ! empty( $field['multiple_choices'] ) ? ' multiple' : ''; |
| 2053 | $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : ''; |
| 2054 | |
| 2055 | if ( $echo ) { |
| 2056 | echo sprintf( '<select class="%s" %s data-placeholder="%s" disabled>', esc_attr( evf_sanitize_classes( $list_class, true ) ), esc_attr( $multiple ), esc_attr( $placeholder ) ); |
| 2057 | |
| 2058 | // Optional placeholder. |
| 2059 | if ( ! empty( $placeholder ) ) { |
| 2060 | echo sprintf( '<option value="" class="placeholder">%s</option>', esc_html( $placeholder ) ); |
| 2061 | } |
| 2062 | |
| 2063 | // Build the select options (even though user can only see 1st option). |
| 2064 | foreach ( $values as $value ) { |
| 2065 | $default = isset( $value['default'] ) ? (bool) $value['default'] : false; |
| 2066 | $selected = ! empty( $placeholder ) && empty( $multiple ) ? '' : selected( true, $default, false ); |
| 2067 | echo sprintf( '<option %s>%s</option>', esc_attr( $selected ), esc_html( $value['label'] ) ); |
| 2068 | } |
| 2069 | |
| 2070 | echo '</select>'; |
| 2071 | } else { |
| 2072 | $output = sprintf( '<select class="%s" %s data-placeholder="%s" disabled>', evf_sanitize_classes( $list_class, true ), esc_attr( $multiple ), esc_attr( $placeholder ) ); |
| 2073 | |
| 2074 | // Optional placeholder. |
| 2075 | if ( ! empty( $placeholder ) ) { |
| 2076 | $output .= sprintf( '<option value="" class="placeholder">%s</option>', esc_html( $placeholder ) ); |
| 2077 | } |
| 2078 | |
| 2079 | // Build the select options (even though user can only see 1st option). |
| 2080 | foreach ( $values as $value ) { |
| 2081 | $default = isset( $value['default'] ) ? (bool) $value['default'] : false; |
| 2082 | $selected = ! empty( $placeholder ) && empty( $multiple ) ? '' : selected( true, $default, false ); |
| 2083 | $output .= sprintf( '<option %s>%s</option>', $selected, esc_html( $value['label'] ) ); |
| 2084 | } |
| 2085 | |
| 2086 | $output .= '</select>'; |
| 2087 | } |
| 2088 | } else { |
| 2089 | |
| 2090 | if ( $echo ) { |
| 2091 | echo sprintf( '<ul class="%s">', esc_attr( evf_sanitize_classes( $list_class, true ) ) ); |
| 2092 | |
| 2093 | // Individual checkbox/radio options. |
| 2094 | foreach ( $values as $value ) { |
| 2095 | $default = isset( $value['default'] ) ? $value['default'] : ''; |
| 2096 | $selected = checked( '1', $default, false ); |
| 2097 | $placeholder = evf()->plugin_url( 'assets/images/everest-forms-placeholder.png' ); |
| 2098 | $image_src = ! empty( $value['image'] ) ? esc_url( $value['image'] ) : $placeholder; |
| 2099 | $item_class = array(); |
| 2100 | |
| 2101 | if ( ! empty( $value['default'] ) ) { |
| 2102 | $item_class[] = 'everest-forms-selected'; |
| 2103 | } |
| 2104 | |
| 2105 | if ( $choices_images ) { |
| 2106 | $item_class[] = 'everest-forms-image-choices-item'; |
| 2107 | } |
| 2108 | |
| 2109 | echo sprintf( '<li class="%s">', esc_attr( evf_sanitize_classes( $item_class, true ) ) ); |
| 2110 | |
| 2111 | if ( $choices_images ) { |
| 2112 | echo '<label>'; |
| 2113 | echo sprintf( '<span class="everest-forms-image-choices-image"><img src="%s" alt="%s"%s></span>', esc_url( $image_src ), esc_attr( $value['label'] ), ( ! empty( $value['label'] ) ? ' title="' . esc_attr( $value['label'] ) . '"' : '' ) ); |
| 2114 | echo sprintf( '<input type="%s" %s disabled>', esc_attr( $type ), esc_attr( $selected ) ); |
| 2115 | if ( ( 'payment-checkbox' === $field['type'] ) || ( 'payment-multiple' === $field['type'] ) ) { |
| 2116 | echo '<span class="everest-forms-image-choices-label">' . esc_html( $value['label'] . '-' . evf_format_amount( evf_sanitize_amount( $value['value'] ), true ) ) . '</span>'; |
| 2117 | } else { |
| 2118 | echo '<span class="everest-forms-image-choices-label">' . esc_html( $value['label'] ) . '</span>'; |
| 2119 | } |
| 2120 | echo '</label>'; |
| 2121 | } else { |
| 2122 | if ( ( 'payment-checkbox' === $field['type'] ) || ( 'payment-multiple' === $field['type'] ) ) { |
| 2123 | echo sprintf( '<input type="%s" %s disabled>%s - %s', esc_attr( $type ), esc_attr( $selected ), esc_html( $value['label'] ), esc_attr( evf_format_amount( evf_sanitize_amount( $value['value'] ) ), true ) ); |
| 2124 | } else { |
| 2125 | echo sprintf( '<input type="%s" %s disabled>%s', esc_attr( $type ), esc_attr( $selected ), esc_html( $value['label'] ) ); |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | echo '</li>'; |
| 2130 | } |
| 2131 | |
| 2132 | echo '</ul>'; |
| 2133 | |
| 2134 | } else { |
| 2135 | $output = sprintf( '<ul class="%s">', evf_sanitize_classes( $list_class, true ) ); |
| 2136 | |
| 2137 | // Individual checkbox/radio options. |
| 2138 | foreach ( $values as $value ) { |
| 2139 | $default = isset( $value['default'] ) ? $value['default'] : ''; |
| 2140 | $selected = checked( '1', $default, false ); |
| 2141 | $placeholder = wp_remote_get( evf()->plugin_url( 'assets/images/everest-forms-placeholder.png' ), array( 'sslverify' => false ) ); |
| 2142 | $image_src = ! empty( $value['image'] ) ? esc_url( $value['image'] ) : $placeholder; |
| 2143 | $item_class = array(); |
| 2144 | |
| 2145 | if ( ! empty( $value['default'] ) ) { |
| 2146 | $item_class[] = 'everest-forms-selected'; |
| 2147 | } |
| 2148 | |
| 2149 | if ( $choices_images ) { |
| 2150 | $item_class[] = 'everest-forms-image-choices-item'; |
| 2151 | } |
| 2152 | |
| 2153 | $output .= sprintf( '<li class="%s">', evf_sanitize_classes( $item_class, true ) ); |
| 2154 | |
| 2155 | if ( $choices_images ) { |
| 2156 | $output .= '<label>'; |
| 2157 | $output .= sprintf( '<span class="everest-forms-image-choices-image"><img src="%s" alt="%s"%s></span>', $image_src, esc_attr( $value['label'] ), ! empty( $value['label'] ) ? ' title="' . esc_attr( $value['label'] ) . '"' : '' ); |
| 2158 | $output .= sprintf( '<input type="%s" %s disabled>', $type, $selected ); |
| 2159 | if ( ( 'payment-checkbox' === $field['type'] ) || ( 'payment-multiple' === $field['type'] ) ) { |
| 2160 | $output .= '<span class="everest-forms-image-choices-label">' . wp_kses_post( $value['label'] ) . '-' . evf_format_amount( evf_sanitize_amount( $value['value'] ), true ) . '</span>'; |
| 2161 | } else { |
| 2162 | $output .= '<span class="everest-forms-image-choices-label">' . wp_kses_post( $value['label'] ) . '</span>'; |
| 2163 | } |
| 2164 | $output .= '</label>'; |
| 2165 | } else { |
| 2166 | if ( ( 'payment-checkbox' === $field['type'] ) || ( 'payment-multiple' === $field['type'] ) ) { |
| 2167 | $output .= sprintf( '<input type="%s" %s disabled>%s - %s', $type, $selected, $value['label'], evf_format_amount( evf_sanitize_amount( $value['value'] ), true ) ); |
| 2168 | } else { |
| 2169 | $output .= sprintf( '<input type="%s" %s disabled>%s', $type, $selected, $value['label'] ); |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | $output .= '</li>'; |
| 2174 | } |
| 2175 | |
| 2176 | $output .= '</ul>'; |
| 2177 | } |
| 2178 | } |
| 2179 | break; |
| 2180 | } |
| 2181 | |
| 2182 | if ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'open' === $markup ) { |
| 2183 | do_action( "everest_forms_field_options_top_{$option}", $field, $this ); |
| 2184 | } elseif ( $echo && in_array( $option, array( 'basic-options', 'advanced-options' ), true ) && 'close' === $markup ) { |
| 2185 | do_action( "everest_forms_field_options_after_{$option}", $field, $this ); |
| 2186 | } |
| 2187 | |
| 2188 | if ( ! $echo ) { |
| 2189 | return $output; |
| 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * Create a new field in the admin AJAX editor. |
| 2195 | * |
| 2196 | * @since 1.0.0 |
| 2197 | */ |
| 2198 | public function field_new() { |
| 2199 | // Run a security check. |
| 2200 | check_ajax_referer( 'everest_forms_field_drop', 'security' ); |
| 2201 | |
| 2202 | // Check for form ID. |
| 2203 | if ( ! isset( $_POST['form_id'] ) || empty( $_POST['form_id'] ) ) { |
| 2204 | die( esc_html__( 'No form ID found', 'everest-forms' ) ); |
| 2205 | } |
| 2206 | |
| 2207 | // Check for permissions. |
| 2208 | if ( ! current_user_can( 'everest_forms_edit_form', (int) $_POST['form_id'] ) ) { |
| 2209 | die( esc_html__( 'You don\'t have permission.', 'everest-forms' ) ); |
| 2210 | } |
| 2211 | |
| 2212 | // Check for field type to add. |
| 2213 | if ( ! isset( $_POST['field_type'] ) || empty( $_POST['field_type'] ) ) { |
| 2214 | die( esc_html__( 'No field type found', 'everest-forms' ) ); |
| 2215 | } |
| 2216 | |
| 2217 | // Grab field data. |
| 2218 | $field_args = ! empty( $_POST['defaults'] ) && is_array( $_POST['defaults'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['defaults'] ) ) : array(); |
| 2219 | $field_type = esc_attr( sanitize_text_field( wp_unslash( $_POST['field_type'] ) ) ); |
| 2220 | $field_id = evf()->form->field_unique_key( sanitize_text_field( wp_unslash( $_POST['form_id'] ) ) ); |
| 2221 | $field = array( |
| 2222 | 'id' => $field_id, |
| 2223 | 'type' => $field_type, |
| 2224 | 'label' => $this->name, |
| 2225 | 'description' => '', |
| 2226 | ); |
| 2227 | $field = wp_parse_args( $field_args, $field ); |
| 2228 | $field = apply_filters( 'everest_forms_field_new_default', $field ); |
| 2229 | $field_required = apply_filters( 'everest_forms_field_new_required', '', $field ); |
| 2230 | $field_class = apply_filters( 'everest_forms_field_new_class', '', $field ); |
| 2231 | |
| 2232 | // Field types that default to required. |
| 2233 | if ( ! empty( $field_required ) ) { |
| 2234 | $field_required = 'required'; |
| 2235 | $field['required'] = '1'; |
| 2236 | } |
| 2237 | |
| 2238 | // Build Preview. |
| 2239 | ob_start(); |
| 2240 | $this->field_preview( $field ); |
| 2241 | $preview = sprintf( '<div class="everest-forms-field everest-forms-field-%s %s %s" id="everest-forms-field-%s" data-field-id="%s" data-field-type="%s">', $field_type, $field_required, $field_class, $field['id'], $field['id'], $field_type ); |
| 2242 | $preview .= sprintf( '<div class="evf-field-action">' ); |
| 2243 | if ( 'repeater-fields' !== $field_type ) { |
| 2244 | $preview .= sprintf( '<a href="#" class="everest-forms-field-duplicate" title="%s"><span class="dashicons dashicons-media-default"></span></a>', __( 'Duplicate Field', 'everest-forms' ) ); |
| 2245 | $preview .= sprintf( '<a href="#" class="everest-forms-field-delete" title="%s"><span class="dashicons dashicons-trash"></span></a>', __( 'Delete Field', 'everest-forms' ) ); |
| 2246 | $preview .= sprintf( '<a href="#" class="everest-forms-field-setting" title="%s"><span class="dashicons dashicons-admin-generic"></span></a>', __( 'Settings', 'everest-forms' ) ); |
| 2247 | } else { |
| 2248 | $preview .= sprintf( '<a href="#" class="evf-duplicate-row" title="%s"><span class="dashicons dashicons-media-default"></span></a>', esc_html__( 'Duplicate Field', 'everest-forms' ) ); |
| 2249 | $preview .= sprintf( '<a href="#" class="evf-delete-row" title="%s"><span class="dashicons dashicons-trash"></span></a>', esc_html__( 'Delete Field', 'everest-forms' ) ); |
| 2250 | } |
| 2251 | $preview .= sprintf( '</div>' ); |
| 2252 | $preview .= ob_get_clean(); |
| 2253 | $preview .= '</div>'; |
| 2254 | |
| 2255 | // Build Options. |
| 2256 | $options = sprintf( '<div class="everest-forms-field-option everest-forms-field-option-%s" id="everest-forms-field-option-%s" data-field-id="%s">', esc_attr( $field['type'] ), $field['id'], $field['id'] ); |
| 2257 | $options .= sprintf( '<input type="hidden" name="form_fields[%s][id]" value="%s" class="everest-forms-field-option-hidden-id">', $field['id'], $field['id'] ); |
| 2258 | $options .= sprintf( '<input type="hidden" name="form_fields[%s][type]" value="%s" class="everest-forms-field-option-hidden-type">', $field['id'], esc_attr( $field['type'] ) ); |
| 2259 | ob_start(); |
| 2260 | $this->field_options( $field ); |
| 2261 | $options .= ob_get_clean(); |
| 2262 | $options .= '</div>'; |
| 2263 | |
| 2264 | $form_field_array = explode( '-', $field_id ); |
| 2265 | $field_id_int = absint( $form_field_array[ count( $form_field_array ) - 1 ] ); |
| 2266 | |
| 2267 | // Prepare to return compiled results. |
| 2268 | wp_send_json_success( |
| 2269 | array( |
| 2270 | 'form_id' => (int) $_POST['form_id'], |
| 2271 | 'field' => $field, |
| 2272 | 'preview' => $preview, |
| 2273 | 'options' => $options, |
| 2274 | 'form_field_id' => ( $field_id_int + 1 ), |
| 2275 | ) |
| 2276 | ); |
| 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * Field display on the form front-end. |
| 2281 | * |
| 2282 | * @since 1.0.0 |
| 2283 | * |
| 2284 | * @param array $field Field Data. |
| 2285 | * @param array $field_atts Field attributes. |
| 2286 | * @param array $form_data All Form Data. |
| 2287 | */ |
| 2288 | public function field_display( $field, $field_atts, $form_data ) {} |
| 2289 | |
| 2290 | /** |
| 2291 | * Edit form field display on the entry back-end. |
| 2292 | * |
| 2293 | * @since 1.7.0 |
| 2294 | * |
| 2295 | * @param array $entry_field Entry field data. |
| 2296 | * @param array $field Field data. |
| 2297 | * @param array $form_data Form data and settings. |
| 2298 | */ |
| 2299 | public function edit_form_field_display( $entry_field, $field, $form_data ) { |
| 2300 | |
| 2301 | if ( 'repeater_fields' === $field['type'] ) { |
| 2302 | return; |
| 2303 | } |
| 2304 | |
| 2305 | $value = isset( $entry_field['value'] ) ? $entry_field['value'] : ''; |
| 2306 | |
| 2307 | if ( '' !== $value ) { |
| 2308 | $field['properties'] = $this->get_single_field_property_value( $value, 'primary', $field['properties'], $field ); |
| 2309 | } |
| 2310 | |
| 2311 | $this->field_display( $field, null, $form_data ); |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * Get the value to prefill, based on field data and current properties. |
| 2316 | * |
| 2317 | * @since 1.7.0 |
| 2318 | * |
| 2319 | * @param string $raw_value Raw Value, always a string. |
| 2320 | * @param string $input Subfield inside the field. |
| 2321 | * @param array $properties Field properties. |
| 2322 | * @param array $field Field specific data. |
| 2323 | * |
| 2324 | * @return array Modified field properties. |
| 2325 | */ |
| 2326 | public function get_single_field_property_value( $raw_value, $input, $properties, $field ) { |
| 2327 | if ( ! is_string( $raw_value ) ) { |
| 2328 | return $properties; |
| 2329 | } |
| 2330 | |
| 2331 | $get_value = wp_unslash( sanitize_text_field( $raw_value ) ); |
| 2332 | |
| 2333 | if ( ! empty( $field['choices'] ) && is_array( $field['choices'] ) ) { |
| 2334 | $properties = $this->get_single_field_property_value_choices( $get_value, $properties, $field ); |
| 2335 | } else { |
| 2336 | if ( |
| 2337 | ! empty( $input ) && |
| 2338 | isset( $properties['inputs'][ $input ] ) |
| 2339 | ) { |
| 2340 | $properties['inputs'][ $input ]['attr']['value'] = $get_value; |
| 2341 | |
| 2342 | // Update data attributes depending on the field type. |
| 2343 | if ( isset( $field['type'] ) && 'range-slider' === $field['type'] ) { |
| 2344 | $properties['inputs'][ $input ]['data']['from'] = $get_value; |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | return $properties; |
| 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * Get the value to prefill for choices section, based on field data and current properties. |
| 2354 | * |
| 2355 | * @since 1.7.0 |
| 2356 | * |
| 2357 | * @param string $get_value Requested value. |
| 2358 | * @param array $properties Field properties. |
| 2359 | * @param array $field Field specific data. |
| 2360 | * |
| 2361 | * @return array Modified field properties. |
| 2362 | */ |
| 2363 | protected function get_single_field_property_value_choices( $get_value, $properties, $field ) { |
| 2364 | $default_key = null; |
| 2365 | |
| 2366 | // For fields with normal choices, we need dafault key. |
| 2367 | foreach ( $field['choices'] as $choice_key => $choice_arr ) { |
| 2368 | $choice_value_key = isset( $field['show_values'] ) ? 'value' : 'label'; |
| 2369 | if ( |
| 2370 | isset( $choice_arr[ $choice_value_key ] ) && |
| 2371 | strtoupper( sanitize_text_field( $choice_arr[ $choice_value_key ] ) ) === strtoupper( $get_value ) |
| 2372 | ) { |
| 2373 | $default_key = $choice_key; |
| 2374 | break; |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | // Redefine selected choice. |
| 2379 | if ( null !== $default_key ) { |
| 2380 | foreach ( $field['choices'] as $choice_key => $choice_arr ) { |
| 2381 | if ( $choice_key === $default_key ) { |
| 2382 | $properties['inputs'][ $choice_key ]['default'] = true; |
| 2383 | $properties['inputs'][ $choice_key ]['container']['class'][] = 'everest-forms-selected'; |
| 2384 | break; |
| 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | return $properties; |
| 2390 | } |
| 2391 | |
| 2392 | /** |
| 2393 | * Remove all admin-defined defaults from choices-related fields only. |
| 2394 | * |
| 2395 | * @since 1.7.0 |
| 2396 | * |
| 2397 | * @param array $field Field data and settings. |
| 2398 | * @param array $properties Field Properties to be modified. |
| 2399 | */ |
| 2400 | protected function remove_field_choices_defaults( $field, &$properties ) { |
| 2401 | if ( ! empty( $field['choices'] ) ) { |
| 2402 | array_walk_recursive( |
| 2403 | $properties['inputs'], |
| 2404 | function ( &$value, $key ) { |
| 2405 | if ( 'default' === $key ) { |
| 2406 | $value = false; |
| 2407 | } |
| 2408 | if ( 'everest-forms-selected' === $value ) { |
| 2409 | $value = ''; |
| 2410 | } |
| 2411 | } |
| 2412 | ); |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | /** |
| 2417 | * Display field input errors if present. |
| 2418 | * |
| 2419 | * @since 1.0.0 |
| 2420 | * |
| 2421 | * @param string $key Input key. |
| 2422 | * @param array $field Field data and settings. |
| 2423 | */ |
| 2424 | public function field_display_error( $key, $field ) { |
| 2425 | // Need an error. |
| 2426 | if ( empty( $field['properties']['error']['value'][ $key ] ) ) { |
| 2427 | return; |
| 2428 | } |
| 2429 | |
| 2430 | printf( |
| 2431 | '<label class="everest-forms-error evf-error" for="%s">%s</label>', |
| 2432 | esc_attr( $field['properties']['inputs'][ $key ]['id'] ), |
| 2433 | esc_html( $field['properties']['error']['value'][ $key ] ) |
| 2434 | ); |
| 2435 | } |
| 2436 | |
| 2437 | /** |
| 2438 | * Display field input sublabel if present. |
| 2439 | * |
| 2440 | * @since 1.0.0 |
| 2441 | * |
| 2442 | * @param string $key Input key. |
| 2443 | * @param string $position Sublabel position. |
| 2444 | * @param array $field Field data and settings. |
| 2445 | */ |
| 2446 | public function field_display_sublabel( $key, $position, $field ) { |
| 2447 | // Need a sublabel value. |
| 2448 | if ( empty( $field['properties']['inputs'][ $key ]['sublabel']['value'] ) ) { |
| 2449 | return; |
| 2450 | } |
| 2451 | |
| 2452 | $pos = ! empty( $field['properties']['inputs'][ $key ]['sublabel']['position'] ) ? $field['properties']['inputs'][ $key ]['sublabel']['position'] : 'after'; |
| 2453 | $hidden = ! empty( $field['properties']['inputs'][ $key ]['sublabel']['hidden'] ) ? 'everest-forms-sublabel-hide' : ''; |
| 2454 | |
| 2455 | if ( $pos !== $position ) { |
| 2456 | return; |
| 2457 | } |
| 2458 | |
| 2459 | printf( |
| 2460 | '<label for="%s" class="everest-forms-field-sublabel %s %s">%s</label>', |
| 2461 | esc_attr( $field['properties']['inputs'][ $key ]['id'] ), |
| 2462 | sanitize_html_class( $pos ), |
| 2463 | esc_html( $hidden ), |
| 2464 | esc_html( evf_string_translation( (int) $this->form_data['id'], $field['id'], $field['properties']['inputs'][ $key ]['sublabel']['value'], '-sublabel-' . $key ) ) |
| 2465 | ); |
| 2466 | } |
| 2467 | |
| 2468 | /** |
| 2469 | * Validates field on form submit. |
| 2470 | * |
| 2471 | * @since 1.0.0 |
| 2472 | * |
| 2473 | * @param string $field_id Field Id. |
| 2474 | * @param string|array $field_submit Submitted Data. |
| 2475 | * @param array $form_data All Form Data. |
| 2476 | */ |
| 2477 | public function validate( $field_id, $field_submit, $form_data ) { |
| 2478 | $field_type = isset( $form_data['form_fields'][ $field_id ]['type'] ) ? $form_data['form_fields'][ $field_id ]['type'] : ''; |
| 2479 | $required_field = isset( $form_data['form_fields'][ $field_id ]['required'] ) ? $form_data['form_fields'][ $field_id ]['required'] : false; |
| 2480 | $field = isset( $form_data['form_fields'][ $field_id ] ) ? $form_data['form_fields'][ $field_id ] : ''; |
| 2481 | $required_validation = get_option( 'everest_forms_required_validation' ); |
| 2482 | if ( in_array( $field_type, array( 'number', 'email', 'url', 'phone' ), true ) ) { |
| 2483 | $required_validation = get_option( 'everest_forms_' . $field['type'] . '_validation' ); |
| 2484 | } |
| 2485 | $required_message = isset( $form_data['form_fields'][ $field_id ]['required-field-message'], $form_data['form_fields'][ $field_id ]['required_field_message_setting'] ) && ! empty( $form_data['form_fields'][ $field_id ]['required-field-message'] ) && 'individual' == $form_data['form_fields'][ $field_id ]['required_field_message_setting'] ? $form_data['form_fields'][ $field_id ]['required-field-message'] : $required_validation; |
| 2486 | $entry = $form_data['entry']; |
| 2487 | $visible = apply_filters( 'everest_forms_visible_fields', true, $form_data['form_fields'][ $field_id ], $entry, $form_data ); |
| 2488 | |
| 2489 | if ( false === $visible ) { |
| 2490 | return; |
| 2491 | } |
| 2492 | // Basic required check - If field is marked as required, check for entry data. |
| 2493 | if ( false !== $required_field && ( empty( $field_submit ) && '0' !== $field_submit ) ) { |
| 2494 | evf()->task->errors[ $form_data['id'] ][ $field_id ] = $required_message; |
| 2495 | update_option( 'evf_validation_error', 'yes' ); |
| 2496 | } |
| 2497 | |
| 2498 | // validate regex validation. |
| 2499 | if ( isset( $form_data['form_fields'][ $field_id ]['enable_regex_validation'] ) && '1' === $form_data['form_fields'][ $field_id ]['enable_regex_validation'] ) { |
| 2500 | $regex_value = ! empty( $form_data['form_fields'][ $field_id ]['regex_value'] ) ? $form_data['form_fields'][ $field_id ]['regex_value'] : ''; |
| 2501 | $regex_message = ! empty( $form_data['form_fields'][ $field_id ]['regex_message'] ) ? $form_data['form_fields'][ $field_id ]['regex_message'] : esc_html__( 'Please provide a valid value for this field', 'everest-forms' ); |
| 2502 | $value = ''; |
| 2503 | if ( is_array( $field_submit ) ) { |
| 2504 | $value = ! empty( $field_submit['primary'] ) ? $field_submit['primary'] : ''; |
| 2505 | } else { |
| 2506 | $value = ! empty( $field_submit ) ? $field_submit : ''; |
| 2507 | } |
| 2508 | if ( ! preg_match( '/' . $regex_value . '/', $value ) ) { |
| 2509 | evf()->task->errors[ $form_data['id'] ][ $field_id ] = $regex_message; |
| 2510 | update_option( 'evf_validation_error', 'yes' ); |
| 2511 | } |
| 2512 | } |
| 2513 | // Type validations. |
| 2514 | switch ( $field_type ) { |
| 2515 | case 'url': |
| 2516 | if ( ! empty( $_POST['everest_forms']['form_fields'][ $field_id ] ) && filter_var( $field_submit, FILTER_VALIDATE_URL ) === false ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 2517 | $validation_text = get_option( 'evf_' . $field_type . '_validation', esc_html__( 'Please enter a valid url', 'everest-forms' ) ); |
| 2518 | } |
| 2519 | |
| 2520 | break; |
| 2521 | case 'email': |
| 2522 | if ( is_array( $field_submit ) ) { |
| 2523 | $value = ! empty( $field_submit['primary'] ) ? $field_submit['primary'] : ''; |
| 2524 | } else { |
| 2525 | $value = ! empty( $field_submit ) ? $field_submit : ''; |
| 2526 | } |
| 2527 | if ( ! empty( $_POST['everest_forms']['form_fields'][ $field_id ] ) && ! is_email( $value ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 2528 | $validation_text = get_option( 'evf_' . $field_type . '_validation', esc_html__( 'Please enter a valid email address', 'everest-forms' ) ); |
| 2529 | } |
| 2530 | break; |
| 2531 | case 'number': |
| 2532 | if ( ! empty( $_POST['everest_forms']['form_fields'][ $field_id ] ) && ! is_numeric( $field_submit ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 2533 | $validation_text = get_option( 'evf_' . $field_type . '_validation', esc_html__( 'Please enter a valid number', 'everest-forms' ) ); |
| 2534 | } |
| 2535 | break; |
| 2536 | case 'textarea': |
| 2537 | case 'text': |
| 2538 | if ( ! empty( $_POST['everest_forms']['form_fields'][ $field_id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 2539 | |
| 2540 | // Limit Length. |
| 2541 | if ( isset( $field['limit_enabled'], $field['limit_mode'], $field['limit_count'] ) && '1' === $field['limit_enabled'] && in_array( $field['limit_mode'], array( 'characters', 'words' ), true ) && ! empty( $field['limit_count'] ) ) { |
| 2542 | if ( 'words' === $field['limit_mode'] && $field['limit_count'] < evf_word_count( $field_submit ) ) { |
| 2543 | /* translators: %s Number of max words. */ |
| 2544 | $validation_text = sprintf( esc_html__( 'This field contains at most %s words', 'everest-forms' ), $field['limit_count'] ); |
| 2545 | } elseif ( 'characters' === $field['limit_mode'] && $field['limit_count'] < mb_strlen( $field_submit ) ) { //phpcs:ignore PHPCompatibility.ParameterValues.NewIconvMbstringCharsetDefault.NotSet |
| 2546 | /* translators: %s Number of max characters. */ |
| 2547 | $validation_text = sprintf( esc_html__( 'This field contains at most %s characters', 'everest-forms' ), $field['limit_count'] ); |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | // Min Length. |
| 2552 | if ( isset( $field['min_length_enabled'], $field['min_length_mode'], $field['min_length_count'] ) && '1' === $field['min_length_enabled'] && in_array( $field['min_length_mode'], array( 'characters', 'words' ), true ) && ! empty( $field['min_length_count'] ) ) { |
| 2553 | |
| 2554 | if ( 'words' === $field['min_length_mode'] && $field['min_length_count'] > evf_word_count( $field_submit ) ) { |
| 2555 | /* translators: %s Number of minimum words. */ |
| 2556 | $validation_text = sprintf( esc_html__( 'This field contains at least %s words', 'everest-forms' ), $field['min_length_count'] ); |
| 2557 | } elseif ( 'characters' === $field['min_length_mode'] && $field['min_length_count'] > mb_strlen( $field_submit ) ) { //phpcs:ignore PHPCompatibility.ParameterValues.NewIconvMbstringCharsetDefault.NotSet |
| 2558 | /* translators: %s Number of minimum characters. */ |
| 2559 | $validation_text = sprintf( esc_html__( 'This field contains at least %s characters', 'everest-forms' ), $field['min_length_count'] ); |
| 2560 | } |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | break; |
| 2565 | case 'date-time': |
| 2566 | $slot_booking = isset( $form_data['form_fields'][ $field_id ]['slot_booking_advanced'] ) ? $form_data['form_fields'][ $field_id ]['slot_booking_advanced'] : ''; |
| 2567 | if ( $slot_booking ) { |
| 2568 | $datetime_format = isset( $form_data['form_fields'][ $field_id ]['datetime_format'] ) ? $form_data['form_fields'][ $field_id ]['datetime_format'] : ''; |
| 2569 | $date_format = isset( $form_data['form_fields'][ $field_id ]['date_format'] ) ? $form_data['form_fields'][ $field_id ]['date_format'] : ''; |
| 2570 | $mode = isset( $form_data['form_fields'][ $field_id ]['date_mode'] ) ? $form_data['form_fields'][ $field_id ]['date_mode'] : ''; |
| 2571 | $time_interval = isset( $form_data['form_fields'][ $field_id ]['time_interval'] ) ? $form_data['form_fields'][ $field_id ]['time_interval'] : ''; |
| 2572 | $datetime_arr = parse_datetime_values( $field_submit, $datetime_format, $date_format, $mode, $time_interval ); |
| 2573 | $booked_slot = maybe_unserialize( get_option( 'evf_booked_slot', '' ) ); |
| 2574 | $form_id = $form_data['id']; |
| 2575 | $is_booked = false; |
| 2576 | if ( ! empty( $booked_slot ) && array_key_exists( $form_id, $booked_slot ) ) { |
| 2577 | foreach ( $datetime_arr as $arr ) { |
| 2578 | |
| 2579 | foreach ( $booked_slot[ $form_id ] as $slot ) { |
| 2580 | if ( $arr[0] >= $slot[0] && $arr[1] <= $slot[1] ) { |
| 2581 | $is_booked = true; |
| 2582 | break; |
| 2583 | } elseif ( $arr[0] >= $slot[0] && $arr[0] < $slot[1] && $arr[1] >= $slot[1] ) { |
| 2584 | $is_booked = true; |
| 2585 | break; |
| 2586 | } |
| 2587 | } |
| 2588 | } |
| 2589 | } |
| 2590 | if ( $is_booked ) { |
| 2591 | $validation_text = get_option( 'evf_' . $field_type . '_validation', esc_html__( 'This slot is already booked. Please choose other slot.', 'everest-forms' ) ); |
| 2592 | } |
| 2593 | } |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | if ( isset( $validation_text ) ) { |
| 2598 | evf()->task->errors[ $form_data['id'] ][ $field_id ] = apply_filters( 'everest_forms_type_validation', $validation_text ); |
| 2599 | update_option( 'evf_validation_error', 'yes' ); |
| 2600 | } |
| 2601 | } |
| 2602 | |
| 2603 | /** |
| 2604 | * Formats and sanitizes field. |
| 2605 | * |
| 2606 | * @since 1.0.0 |
| 2607 | * |
| 2608 | * @param int $field_id Field ID. |
| 2609 | * @param mixed $field_submit Submitted field value. |
| 2610 | * @param array $form_data Form data and settings. |
| 2611 | * @param string $meta_key Field meta key. |
| 2612 | */ |
| 2613 | public function format( $field_id, $field_submit, $form_data, $meta_key ) { |
| 2614 | if ( is_array( $field_submit ) ) { |
| 2615 | $field_submit = array_filter( $field_submit ); |
| 2616 | $field_submit = implode( "\r\n", $field_submit ); |
| 2617 | } |
| 2618 | |
| 2619 | $name = ! empty( $form_data['form_fields'][ $field_id ]['label'] ) ? make_clickable( $form_data['form_fields'][ $field_id ]['label'] ) : ''; |
| 2620 | |
| 2621 | // Sanitize but keep line breaks. |
| 2622 | $value = evf_sanitize_textarea_field( $field_submit ); |
| 2623 | |
| 2624 | evf()->task->form_fields[ $field_id ] = array( |
| 2625 | 'name' => $name, |
| 2626 | 'value' => $value, |
| 2627 | 'id' => $field_id, |
| 2628 | 'type' => $this->type, |
| 2629 | 'meta_key' => $meta_key, |
| 2630 | ); |
| 2631 | } |
| 2632 | |
| 2633 | /** |
| 2634 | * Field with limit. |
| 2635 | * |
| 2636 | * @param array $field Field to check. |
| 2637 | * @return boolean |
| 2638 | */ |
| 2639 | protected function field_is_limit( $field ) { |
| 2640 | if ( in_array( $field['type'], array( 'text', 'textarea' ), true ) ) { |
| 2641 | return ( isset( $field['limit_enabled'] ) && ! empty( $field['limit_count'] ) ) || ( isset( $field['min_length_enabled'] ) && ! empty( $field['min_length_count'] ) ); |
| 2642 | } |
| 2643 | } |
| 2644 | |
| 2645 | /** |
| 2646 | * Filter callback for outputting formatted data. |
| 2647 | * |
| 2648 | * @param array $field Field Data. |
| 2649 | */ |
| 2650 | public function field_exporter( $field ) { |
| 2651 | $export = array(); |
| 2652 | |
| 2653 | switch ( $this->type ) { |
| 2654 | case 'radio': |
| 2655 | case 'signature': |
| 2656 | case 'payment-multiple': |
| 2657 | $value = ''; |
| 2658 | $image = ! empty( $field['value']['image'] ) ? sprintf( '<img src="%s" style="width:75px;height:75px;max-height:75px;max-width:75px;" /><br>', $field['value']['image'] ) : ''; |
| 2659 | $filtered_choice = apply_filters( 'evf_custom_choice', false ); |
| 2660 | if ( $filtered_choice ) { |
| 2661 | $value = ! empty( $field['value']['label'] ) ? $field['value']['label'] : ''; |
| 2662 | } else { |
| 2663 | $value = ! empty( $field['value']['label'] ) ? $image . $field['value']['label'] : ''; |
| 2664 | } |
| 2665 | $export = array( |
| 2666 | 'label' => ! empty( $field['value']['name'] ) ? $field['value']['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}", |
| 2667 | 'value' => ! empty( $value ) ? $value : false, |
| 2668 | ); |
| 2669 | break; |
| 2670 | case 'checkbox': |
| 2671 | case 'payment-checkbox': |
| 2672 | $value = array(); |
| 2673 | |
| 2674 | if ( count( $field['value'] ) ) { |
| 2675 | foreach ( $field['value']['label'] as $key => $choice ) { |
| 2676 | $image = ! empty( $field['value']['images'][ $key ] ) ? sprintf( '<img src="%s" style="width:75px;height:75px;max-height:75px;max-width:75px;" /><br>', $field['value']['images'][ $key ] ) : ''; |
| 2677 | |
| 2678 | if ( ! empty( $choice ) ) { |
| 2679 | $filtered_choice = apply_filters( 'evf_custom_choice', false ); |
| 2680 | if ( $filtered_choice ) { |
| 2681 | $value[ $key ] = $choice; |
| 2682 | } else { |
| 2683 | $value[ $key ] = $image . $choice; |
| 2684 | } |
| 2685 | } |
| 2686 | } |
| 2687 | } |
| 2688 | $export = array( |
| 2689 | 'label' => ! empty( $field['value']['name'] ) ? $field['value']['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}", |
| 2690 | 'value' => is_array( $value ) ? implode( '<br>', array_values( $value ) ) : false, |
| 2691 | ); |
| 2692 | break; |
| 2693 | default: |
| 2694 | $export = array( |
| 2695 | 'label' => ! empty( $field['name'] ) ? $field['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}", |
| 2696 | 'value' => ! empty( $field['value'] ) ? ( is_array( $field['value'] ) ? $this->implode_recursive( $field['value'] ) : $field['value'] ) : false, |
| 2697 | ); |
| 2698 | } |
| 2699 | |
| 2700 | return $export; |
| 2701 | } |
| 2702 | |
| 2703 | /** |
| 2704 | * Recursively process an array with an implosion. |
| 2705 | * |
| 2706 | * @since 1.6.6 |
| 2707 | * |
| 2708 | * @param array $array Array that needs to be recursively imploded. |
| 2709 | * @param string $delimiter Delimiter for the implosion - defaults to <br>. |
| 2710 | * |
| 2711 | * @return string $output Imploded array. |
| 2712 | */ |
| 2713 | protected function implode_recursive( $array, $delimiter = '<br>' ) { |
| 2714 | $output = ''; |
| 2715 | |
| 2716 | foreach ( $array as $tuple ) { |
| 2717 | if ( is_array( $tuple ) ) { |
| 2718 | $output .= $this->implode_recursive( $tuple, ' ' ); |
| 2719 | } elseif ( ! empty( $tuple ) ) { |
| 2720 | $output .= $delimiter . $tuple; |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | return $output; |
| 2725 | } |
| 2726 | } |
| 2727 |