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