| @@ -4,15 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFieldsController { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * This is stored statically so we can re-use this data for every field. | |
| 10 | - * | |
| 11 | - * @var FrmFieldSelectionData|null | |
| 12 | - */ | |
| 13 | - private static $field_selection_data; | |
| 14 | - | |
| 15 | 8 | public static function load_field() { |
| 16 | 9 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 17 | 10 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 18 | 11 | |
| @@ -63,15 +56,14 @@ | ||
| 63 | 56 | public static function create() { |
| 64 | 57 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 65 | 58 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 66 | 59 | |
| 67 | - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 68 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 69 | - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' ); | |
| 60 | + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 61 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 70 | 62 | |
| 71 | 63 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 72 | 64 | |
| 73 | - $field = self::include_new_field( $field_type, $form_id, $field_options ); | |
| 65 | + $field = self::include_new_field( $field_type, $form_id ); | |
| 74 | 66 | |
| 75 | 67 | // this hook will allow for multiple fields to be added at once |
| 76 | 68 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 77 | 69 | |
| @@ -81,29 +73,18 @@ | ||
| 81 | 73 | /** |
| 82 | 74 | * Set up and create a new field |
| 83 | 75 | * |
| 84 | 76 | * @param string $field_type |
| 85 | - * @param int $form_id | |
| 86 | - * @param array $field_options | |
| 77 | + * @param integer $form_id | |
| 87 | 78 | * |
| 88 | - * @return array|false | |
| 79 | + * @return array|bool | |
| 89 | 80 | */ |
| 90 | - public static function include_new_field( $field_type, $form_id, $field_options = array() ) { | |
| 81 | + public static function include_new_field( $field_type, $form_id ) { | |
| 91 | 82 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 83 | + $field_values = apply_filters( 'frm_before_field_created', $field_values ); | |
| 92 | 84 | |
| 93 | - if ( ! empty( $field_options ) ) { | |
| 94 | - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); | |
| 95 | - } | |
| 85 | + $field_id = FrmField::create( $field_values ); | |
| 96 | 86 | |
| 97 | - // When a new field is added to the form, flag it as draft and hide it from the front-end. | |
| 98 | - $field_values['field_options']['draft'] = 1; | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * @param array $field_values | |
| 102 | - */ | |
| 103 | - $field_values = apply_filters( 'frm_before_field_created', $field_values ); | |
| 104 | - $field_id = FrmField::create( $field_values ); | |
| 105 | - | |
| 106 | 87 | if ( ! $field_id ) { |
| 107 | 88 | return false; |
| 108 | 89 | } |
| 109 | 90 | |
| @@ -155,11 +136,11 @@ | ||
| 155 | 136 | |
| 156 | 137 | /** |
| 157 | 138 | * @since 3.0 |
| 158 | 139 | * |
| 159 | - * @param array|int|object $field_object | |
| 160 | - * @param array $values | |
| 161 | - * @param int $form_id | |
| 140 | + * @param int|array|object $field_object | |
| 141 | + * @param array $values | |
| 142 | + * @param int $form_id | |
| 162 | 143 | */ |
| 163 | 144 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 164 | 145 | global $frm_vars; |
| 165 | 146 | $frm_vars['is_admin'] = true; |
| @@ -173,46 +154,30 @@ | ||
| 173 | 154 | |
| 174 | 155 | $field_obj = FrmFieldFactory::get_field_factory( $field_object ); |
| 175 | 156 | $display = self::display_field_options( array(), $field_obj ); |
| 176 | 157 | |
| 177 | - $ajax_loading = ! empty( $values['ajax_load'] ); | |
| 178 | - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true ); | |
| 158 | + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load']; | |
| 159 | + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) ); | |
| 179 | 160 | |
| 180 | 161 | if ( $ajax_loading && $ajax_this_field ) { |
| 181 | 162 | $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj ); |
| 182 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php'; | |
| 183 | - return; | |
| 184 | - } | |
| 163 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' ); | |
| 164 | + } else { | |
| 165 | + if ( ! isset( $field ) && is_object( $field_object ) ) { | |
| 166 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 185 | 167 | |
| 186 | - if ( ! isset( $field ) && is_object( $field_object ) ) { | |
| 187 | - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id; | |
| 188 | - $field = FrmFieldsHelper::setup_edit_vars( $field_object ); | |
| 189 | - } | |
| 168 | + $field = FrmFieldsHelper::setup_edit_vars( $field_object ); | |
| 169 | + } | |
| 190 | 170 | |
| 191 | - /** | |
| 192 | - * Filter for adding extra attributes to the field container. | |
| 193 | - * | |
| 194 | - * @since 6.23 | |
| 195 | - * | |
| 196 | - * @param array $extra_field_attributes | |
| 197 | - * @param array $field | |
| 198 | - * @param array $display | |
| 199 | - */ | |
| 200 | - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display ); | |
| 171 | + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); | |
| 172 | + $li_classes .= ' ui-state-default widgets-holder-wrap'; | |
| 201 | 173 | |
| 202 | - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); | |
| 203 | - $li_classes .= ' ui-state-default widgets-holder-wrap'; | |
| 204 | - | |
| 205 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; | |
| 174 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); | |
| 175 | + } | |
| 206 | 176 | } |
| 207 | 177 | |
| 208 | 178 | /** |
| 209 | 179 | * @since 3.0 |
| 210 | - * | |
| 211 | - * @param array $field | |
| 212 | - * @param array $display | |
| 213 | - * @param FrmFieldType $field_info | |
| 214 | - * @return string | |
| 215 | 180 | */ |
| 216 | 181 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 217 | 182 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| 218 | 183 | $li_classes .= ' frm_form_field frmstart '; |
| @@ -238,11 +203,10 @@ | ||
| 238 | 203 | FrmField::destroy( $field_id ); |
| 239 | 204 | wp_die(); |
| 240 | 205 | } |
| 241 | 206 | |
| 242 | - /** | |
| 243 | - * Field Options. | |
| 244 | - */ | |
| 207 | + /* Field Options */ | |
| 208 | + | |
| 245 | 209 | public static function import_options() { |
| 246 | 210 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 247 | 211 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 248 | 212 | |
| @@ -249,23 +213,12 @@ | ||
| 249 | 213 | if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 250 | 214 | return; |
| 251 | 215 | } |
| 252 | 216 | |
| 253 | - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' ); | |
| 254 | - $field = FrmField::getOne( $field_id ); | |
| 255 | - $bulk_edit_types = array( 'radio', 'checkbox', 'select' ); | |
| 217 | + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' ); | |
| 218 | + $field = FrmField::getOne( $field_id ); | |
| 256 | 219 | |
| 257 | - /** | |
| 258 | - * Filter to add new fields that will support import_options/Bulk Edit Options. | |
| 259 | - * | |
| 260 | - * @since 6.8.4 | |
| 261 | - * | |
| 262 | - * @param array $bulk_edit_types | |
| 263 | - * @return array | |
| 264 | - */ | |
| 265 | - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); | |
| 266 | - | |
| 267 | - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) { | |
| 220 | + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { | |
| 268 | 221 | return; |
| 269 | 222 | } |
| 270 | 223 | |
| 271 | 224 | $field = FrmFieldsHelper::setup_edit_vars( $field ); |
| @@ -272,15 +225,15 @@ | ||
| 272 | 225 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
| 273 | 226 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
| 274 | 227 | $opts = array_map( 'trim', $opts ); |
| 275 | 228 | |
| 276 | - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); | |
| 277 | - $field['separate_value'] = $separate === 'true'; | |
| 229 | + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); | |
| 230 | + $field['separate_value'] = ( $separate === 'true' ); | |
| 278 | 231 | |
| 279 | 232 | if ( $field['separate_value'] ) { |
| 280 | 233 | foreach ( $opts as $opt_key => $opt ) { |
| 281 | 234 | if ( strpos( $opt, '|' ) !== false ) { |
| 282 | - $vals = explode( '|', $opt ); | |
| 235 | + $vals = explode( '|', $opt ); | |
| 283 | 236 | $opts[ $opt_key ] = array( |
| 284 | 237 | 'label' => trim( $vals[0] ), |
| 285 | 238 | 'value' => trim( $vals[1] ), |
| 286 | 239 | ); |
| @@ -314,9 +267,8 @@ | ||
| 314 | 267 | /** |
| 315 | 268 | * @since 4.0 |
| 316 | 269 | * |
| 317 | 270 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 318 | - * @return void | |
| 319 | 271 | */ |
| 320 | 272 | public static function load_single_field_settings( $atts ) { |
| 321 | 273 | $field = $atts['field']; |
| 322 | 274 | $field_obj = $atts['field_obj']; |
| @@ -331,13 +283,13 @@ | ||
| 331 | 283 | if ( ! isset( $field['read_only'] ) ) { |
| 332 | 284 | $field['read_only'] = false; |
| 333 | 285 | } |
| 334 | 286 | |
| 335 | - $field_selection_data = self::maybe_define_field_selection_data(); | |
| 336 | - $all_field_types = $field_selection_data->all_field_types; | |
| 337 | - $disabled_fields = $field_selection_data->disabled_fields; | |
| 338 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 339 | - $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] ); | |
| 287 | + $field_types = FrmFieldsHelper::get_field_types( $field['type'] ); | |
| 288 | + $pro_field_selection = FrmField::pro_field_selection(); | |
| 289 | + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() ); | |
| 290 | + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection; | |
| 291 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 340 | 292 | |
| 341 | 293 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 342 | 294 | // Add fallback for an add-on field type that has been deactivated. |
| 343 | 295 | $all_field_types[ $field['type'] ] = array( |
| @@ -360,76 +312,61 @@ | ||
| 360 | 312 | |
| 361 | 313 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 362 | 314 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 363 | 315 | } |
| 364 | - | |
| 365 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; | |
| 316 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' ); | |
| 366 | 317 | } |
| 367 | 318 | |
| 368 | 319 | /** |
| 369 | - * @since 6.9.1 | |
| 370 | - * | |
| 371 | - * @return FrmFieldSelectionData | |
| 372 | - */ | |
| 373 | - private static function maybe_define_field_selection_data() { | |
| 374 | - if ( ! isset( self::$field_selection_data ) ) { | |
| 375 | - self::$field_selection_data = new FrmFieldSelectionData(); | |
| 376 | - } | |
| 377 | - return self::$field_selection_data; | |
| 378 | - } | |
| 379 | - | |
| 380 | - /** | |
| 381 | 320 | * Get the list of default value types that can be toggled in the builder. |
| 382 | 321 | * |
| 383 | 322 | * @since 4.0 |
| 384 | - * | |
| 385 | - * @param array $field | |
| 386 | - * @param array $atts | |
| 387 | 323 | * @return array |
| 388 | 324 | */ |
| 389 | 325 | private static function default_value_types( $field, $atts ) { |
| 390 | 326 | $types = array( |
| 391 | - 'default_value' => array( | |
| 327 | + 'default_value' => array( | |
| 392 | 328 | 'class' => '', |
| 393 | 329 | 'icon' => 'frm_icon_font frm_text2_icon', |
| 394 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 330 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 395 | 331 | 'data' => array( |
| 396 | 332 | 'frmshow' => '#default-value-for-', |
| 397 | 333 | ), |
| 398 | 334 | ), |
| 399 | - 'calc' => array( | |
| 400 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 401 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 402 | - 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 403 | - 'data' => array( | |
| 335 | + 'calc' => array( | |
| 336 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 337 | + 'title' => __( 'Default Value (Calculation)', 'formidable' ), | |
| 338 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 339 | + 'data' => array( | |
| 404 | 340 | 'medium' => 'calculations', |
| 405 | 341 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 406 | 342 | ), |
| 407 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 408 | 343 | ), |
| 409 | 344 | 'get_values_field' => array( |
| 410 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 411 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 412 | - 'icon' => 'frm_icon_font frm_search_icon', | |
| 413 | - 'data' => array( | |
| 345 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 346 | + 'title' => __( 'Default Value (Lookup)', 'formidable' ), | |
| 347 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 348 | + 'data' => array( | |
| 414 | 349 | 'medium' => 'lookup', |
| 415 | 350 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 416 | 351 | ), |
| 417 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 418 | 352 | ), |
| 419 | 353 | ); |
| 420 | 354 | |
| 421 | 355 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| 422 | 356 | |
| 357 | + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) { | |
| 358 | + // Prevent settings from showing in 2 spots. | |
| 359 | + unset( $types['calc'], $types['get_values_field'] ); | |
| 360 | + } | |
| 361 | + | |
| 423 | 362 | // Set active class. |
| 424 | 363 | $settings = array_keys( $types ); |
| 425 | 364 | $active = 'default_value'; |
| 426 | 365 | |
| 427 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 428 | - foreach ( $settings as $type ) { | |
| 429 | - if ( ! empty( $field[ $type ] ) ) { | |
| 430 | - $active = $type; | |
| 431 | - } | |
| 366 | + foreach ( $settings as $type ) { | |
| 367 | + if ( ! empty( $field[ $type ] ) ) { | |
| 368 | + $active = $type; | |
| 432 | 369 | } |
| 433 | 370 | } |
| 434 | 371 | |
| 435 | 372 | $types[ $active ]['class'] .= ' current'; |
| @@ -437,12 +374,8 @@ | ||
| 437 | 374 | |
| 438 | 375 | return $types; |
| 439 | 376 | } |
| 440 | 377 | |
| 441 | - /** | |
| 442 | - * @param string $type | |
| 443 | - * @return string | |
| 444 | - */ | |
| 445 | 378 | public static function change_type( $type ) { |
| 446 | 379 | $type_switch = array( |
| 447 | 380 | 'scale' => 'radio', |
| 448 | 381 | 'star' => 'radio', |
| @@ -455,13 +388,10 @@ | ||
| 455 | 388 | $type = $type_switch[ $type ]; |
| 456 | 389 | } |
| 457 | 390 | |
| 458 | 391 | $pro_fields = FrmField::pro_field_selection(); |
| 459 | - // We want to keep credit_card types as credit card types for Stripe Lite. | |
| 460 | - // The credit_card key is set for backward compatibility. | |
| 461 | - unset( $pro_fields['credit_card'] ); | |
| 462 | - | |
| 463 | - if ( array_key_exists( $type, $pro_fields ) ) { | |
| 392 | + $types = array_keys( $pro_fields ); | |
| 393 | + if ( in_array( $type, $types ) ) { | |
| 464 | 394 | $type = 'text'; |
| 465 | 395 | } |
| 466 | 396 | |
| 467 | 397 | return $type; |
| @@ -467,18 +397,16 @@ | ||
| 467 | 397 | return $type; |
| 468 | 398 | } |
| 469 | 399 | |
| 470 | 400 | /** |
| 471 | - * @param array $settings | |
| 472 | - * @param FrmFieldType|null $field_info | |
| 401 | + * @param array $settings | |
| 402 | + * @param object $field_info | |
| 473 | 403 | * |
| 474 | 404 | * @return array |
| 475 | 405 | */ |
| 476 | 406 | public static function display_field_options( $settings, $field_info = null ) { |
| 477 | 407 | if ( $field_info ) { |
| 478 | - $settings = $field_info->display_field_settings(); | |
| 479 | - | |
| 480 | - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public. | |
| 408 | + $settings = $field_info->display_field_settings(); | |
| 481 | 409 | $settings['field_data'] = $field_info->field; |
| 482 | 410 | } |
| 483 | 411 | |
| 484 | 412 | return apply_filters( 'frm_display_field_options', $settings ); |
| @@ -488,23 +416,12 @@ | ||
| 488 | 416 | * Display the format option |
| 489 | 417 | * |
| 490 | 418 | * @since 3.0 |
| 491 | 419 | * |
| 492 | - * @param array $field Field data. | |
| 493 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 494 | - * @return void | |
| 420 | + * @param array $field | |
| 495 | 421 | */ |
| 496 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 497 | - $attributes = array( | |
| 498 | - 'class' => 'frm-has-modal', | |
| 499 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 500 | - ); | |
| 501 | - | |
| 502 | - if ( $is_hidden ) { | |
| 503 | - $attributes['class'] .= ' frm_hidden'; | |
| 504 | - } | |
| 505 | - | |
| 506 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; | |
| 422 | + public static function show_format_option( $field ) { | |
| 423 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' ); | |
| 507 | 424 | } |
| 508 | 425 | |
| 509 | 426 | public static function input_html( $field, $echo = true ) { |
| 510 | 427 | $class = array(); |
| @@ -532,19 +449,14 @@ | ||
| 532 | 449 | |
| 533 | 450 | return $add_html; |
| 534 | 451 | } |
| 535 | 452 | |
| 536 | - /** | |
| 537 | - * @param array $field | |
| 538 | - * @param array $class | |
| 539 | - * @return void | |
| 540 | - */ | |
| 541 | 453 | private static function add_input_classes( $field, array &$class ) { |
| 542 | - if ( ! empty( $field['input_class'] ) ) { | |
| 454 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { | |
| 543 | 455 | $class[] = $field['input_class']; |
| 544 | 456 | } |
| 545 | 457 | |
| 546 | - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) { | |
| 458 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { | |
| 547 | 459 | return; |
| 548 | 460 | } |
| 549 | 461 | |
| 550 | 462 | if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
| @@ -551,13 +463,8 @@ | ||
| 551 | 463 | $class[] = 'auto_width'; |
| 552 | 464 | } |
| 553 | 465 | } |
| 554 | 466 | |
| 555 | - /** | |
| 556 | - * @param array $field | |
| 557 | - * @param array $add_html | |
| 558 | - * @return void | |
| 559 | - */ | |
| 560 | 467 | private static function add_html_size( $field, array &$add_html ) { |
| 561 | 468 | $size_fields = array( |
| 562 | 469 | 'select', |
| 563 | 470 | 'data', |
| @@ -566,9 +473,9 @@ | ||
| 566 | 473 | 'file', |
| 567 | 474 | 'lookup', |
| 568 | 475 | ); |
| 569 | 476 | |
| 570 | - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) { | |
| 477 | + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) { | |
| 571 | 478 | return; |
| 572 | 479 | } |
| 573 | 480 | |
| 574 | 481 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| @@ -585,15 +492,10 @@ | ||
| 585 | 492 | |
| 586 | 493 | self::add_html_cols( $field, $add_html ); |
| 587 | 494 | } |
| 588 | 495 | |
| 589 | - /** | |
| 590 | - * @param array $field | |
| 591 | - * @param array $add_html | |
| 592 | - * @return void | |
| 593 | - */ | |
| 594 | 496 | private static function add_html_cols( $field, array &$add_html ) { |
| 595 | - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { | |
| 497 | + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { | |
| 596 | 498 | return; |
| 597 | 499 | } |
| 598 | 500 | |
| 599 | 501 | // Convert to cols for textareas. |
| @@ -615,13 +517,8 @@ | ||
| 615 | 517 | |
| 616 | 518 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 617 | 519 | } |
| 618 | 520 | |
| 619 | - /** | |
| 620 | - * @param array $field | |
| 621 | - * @param array $add_html | |
| 622 | - * @return void | |
| 623 | - */ | |
| 624 | 521 | private static function add_html_length( $field, array &$add_html ) { |
| 625 | 522 | // Check for max setting and if this field accepts maxlength. |
| 626 | 523 | $fields = array( |
| 627 | 524 | 'textarea', |
| @@ -629,9 +526,9 @@ | ||
| 629 | 526 | 'hidden', |
| 630 | 527 | 'file', |
| 631 | 528 | ); |
| 632 | 529 | |
| 633 | - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) { | |
| 530 | + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) { | |
| 634 | 531 | return; |
| 635 | 532 | } |
| 636 | 533 | |
| 637 | 534 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| @@ -641,14 +538,8 @@ | ||
| 641 | 538 | |
| 642 | 539 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
| 643 | 540 | } |
| 644 | 541 | |
| 645 | - /** | |
| 646 | - * @param array $field | |
| 647 | - * @param array $add_html | |
| 648 | - * @param array $class | |
| 649 | - * @return void | |
| 650 | - */ | |
| 651 | 542 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 652 | 543 | if ( $field['default_value'] != '' ) { |
| 653 | 544 | if ( is_array( $field['default_value'] ) ) { |
| 654 | 545 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| @@ -662,9 +553,21 @@ | ||
| 662 | 553 | // don't include a json placeholder |
| 663 | 554 | return; |
| 664 | 555 | } |
| 665 | 556 | |
| 666 | - self::add_placeholder_to_input( $field, $add_html ); | |
| 557 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 558 | + | |
| 559 | + if ( $frm_settings->use_html ) { | |
| 560 | + self::add_placeholder_to_input( $field, $add_html ); | |
| 561 | + } else { | |
| 562 | + self::add_frmval_to_input( $field, $add_html ); | |
| 563 | + | |
| 564 | + $class[] = 'frm_toggle_default'; | |
| 565 | + | |
| 566 | + if ( $field['value'] == $field['placeholder'] ) { | |
| 567 | + $class[] = 'frm_default'; | |
| 568 | + } | |
| 569 | + } | |
| 667 | 570 | } |
| 668 | 571 | |
| 669 | 572 | /** |
| 670 | 573 | * Prepares field placeholder. |
| @@ -674,9 +577,9 @@ | ||
| 674 | 577 | * @param array $field Field array. |
| 675 | 578 | * @return string |
| 676 | 579 | */ |
| 677 | 580 | private static function prepare_placeholder( $field ) { |
| 678 | - $placeholder = $field['placeholder'] ?? ''; | |
| 581 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 679 | 582 | |
| 680 | 583 | return $placeholder; |
| 681 | 584 | } |
| 682 | 585 | |
| @@ -707,26 +610,14 @@ | ||
| 707 | 610 | if ( empty( $placeholder ) ) { |
| 708 | 611 | $placeholder = self::get_default_value_from_name( $field ); |
| 709 | 612 | } |
| 710 | 613 | |
| 711 | - $use_placeholder = $placeholder; | |
| 712 | - $autocomplete = FrmField::get_option( $field, 'autocom' ); | |
| 713 | - | |
| 714 | - if ( $autocomplete ) { | |
| 715 | - $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); | |
| 716 | - if ( $use_chosen ) { | |
| 717 | - $use_placeholder = ''; | |
| 718 | - } | |
| 719 | - } | |
| 720 | - | |
| 721 | 614 | if ( $placeholder !== '' ) { |
| 722 | - $placeholder_attributes = array( | |
| 723 | - 'class' => 'frm-select-placeholder', | |
| 724 | - 'value' => '', | |
| 725 | - 'data-placeholder' => 'true', | |
| 726 | - ); | |
| 727 | - | |
| 728 | - FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); | |
| 615 | + ?> | |
| 616 | + <option value=""> | |
| 617 | + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?> | |
| 618 | + </option> | |
| 619 | + <?php | |
| 729 | 620 | return true; |
| 730 | 621 | } |
| 731 | 622 | |
| 732 | 623 | return false; |
| @@ -732,13 +623,12 @@ | ||
| 732 | 623 | return false; |
| 733 | 624 | } |
| 734 | 625 | |
| 735 | 626 | /** |
| 736 | - * Use HTML5 placeholder with js fallback. | |
| 627 | + * Use HMTL5 placeholder with js fallback | |
| 737 | 628 | * |
| 738 | 629 | * @param array $field |
| 739 | 630 | * @param array $add_html |
| 740 | - * @return void | |
| 741 | 631 | */ |
| 742 | 632 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 743 | 633 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| 744 | 634 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| @@ -744,13 +634,8 @@ | ||
| 744 | 634 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 745 | 635 | } |
| 746 | 636 | } |
| 747 | 637 | |
| 748 | - /** | |
| 749 | - * @param array $field | |
| 750 | - * @param array $add_html | |
| 751 | - * @return void | |
| 752 | - */ | |
| 753 | 638 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 754 | 639 | if ( $field['placeholder'] != '' ) { |
| 755 | 640 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 756 | 641 | |
| @@ -764,17 +649,15 @@ | ||
| 764 | 649 | } |
| 765 | 650 | } |
| 766 | 651 | |
| 767 | 652 | private static function add_validation_messages( $field, array &$add_html ) { |
| 768 | - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); | |
| 769 | - | |
| 770 | - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { | |
| 653 | + if ( FrmField::is_required( $field ) ) { | |
| 771 | 654 | $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' ); |
| 772 | 655 | $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"'; |
| 773 | 656 | self::maybe_add_html_required( $field, $add_html ); |
| 774 | 657 | } |
| 775 | 658 | |
| 776 | - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) { | |
| 659 | + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) { | |
| 777 | 660 | $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| 778 | 661 | $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"'; |
| 779 | 662 | } |
| 780 | 663 | |
| @@ -783,45 +666,12 @@ | ||
| 783 | 666 | } |
| 784 | 667 | } |
| 785 | 668 | |
| 786 | 669 | /** |
| 787 | - * Returns an array that contains field validation messages status. | |
| 788 | - * | |
| 789 | - * @since 6.9 | |
| 790 | - * | |
| 791 | - * @param array|object $field | |
| 792 | - * @return array | |
| 793 | - */ | |
| 794 | - private static function get_validation_data_attribute_visibility_info( $field ) { | |
| 795 | - if ( FrmField::get_field_type( $field ) === 'hidden' ) { | |
| 796 | - $field_validation_data_attributes = array( | |
| 797 | - 'data-invmsg' => false, | |
| 798 | - 'data-reqmsg' => false, | |
| 799 | - ); | |
| 800 | - } else { | |
| 801 | - $field_validation_data_attributes = array( | |
| 802 | - 'data-invmsg' => true, | |
| 803 | - 'data-reqmsg' => true, | |
| 804 | - ); | |
| 805 | - } | |
| 806 | - | |
| 807 | - /** | |
| 808 | - * Allows controlling which field validation messages would be included in the field html. | |
| 809 | - * | |
| 810 | - * @since 6.9 | |
| 811 | - * | |
| 812 | - * @param array $field_validation_messages_status | |
| 813 | - * @param array|object $field | |
| 814 | - */ | |
| 815 | - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field ); | |
| 816 | - } | |
| 817 | - | |
| 818 | - /** | |
| 819 | 670 | * @since 5.0.03 |
| 820 | 671 | * |
| 821 | 672 | * @param array $field |
| 822 | 673 | * @param array $add_html |
| 823 | - * @return void | |
| 824 | 674 | */ |
| 825 | 675 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 826 | 676 | $form = self::get_form_for_js_validation( $field ); |
| 827 | 677 | if ( false === $form ) { |
| @@ -838,9 +688,9 @@ | ||
| 838 | 688 | /** |
| 839 | 689 | * @since 5.0.03 |
| 840 | 690 | * |
| 841 | 691 | * @param array $field |
| 842 | - * @return false|stdClass false if there is no form object found with JS validation active. | |
| 692 | + * @return stdClass|false false if there is no form object found with JS validation active. | |
| 843 | 693 | */ |
| 844 | 694 | private static function get_form_for_js_validation( $field ) { |
| 845 | 695 | global $frm_vars; |
| 846 | 696 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| @@ -857,9 +707,9 @@ | ||
| 857 | 707 | /** |
| 858 | 708 | * @param stdClass $form |
| 859 | 709 | * @param array $field |
| 860 | 710 | * @param array $errors |
| 861 | - * @return false|string | |
| 711 | + * @return string|false | |
| 862 | 712 | */ |
| 863 | 713 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 864 | 714 | if ( empty( $field['custom_html'] ) ) { |
| 865 | 715 | return false; |
| @@ -900,30 +750,20 @@ | ||
| 900 | 750 | * |
| 901 | 751 | * @since 3.06.01 |
| 902 | 752 | * @param array $field |
| 903 | 753 | * @param array $add_html |
| 904 | - * @return void | |
| 905 | 754 | */ |
| 906 | 755 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 907 | - $excluded_field_types = | |
| 908 | - FrmField::is_radio( $field ) || | |
| 909 | - FrmField::is_checkbox( $field ) || | |
| 910 | - FrmField::is_field_type( $field, 'file' ) || | |
| 911 | - FrmField::is_field_type( $field, 'nps' ) || | |
| 912 | - FrmField::is_field_type( $field, 'scale' ); | |
| 913 | - | |
| 914 | - if ( $excluded_field_types ) { | |
| 756 | + if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) { | |
| 915 | 757 | return; |
| 916 | 758 | } |
| 917 | 759 | |
| 918 | - $add_html['aria-required'] = 'aria-required="true"'; | |
| 760 | + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' ); | |
| 761 | + if ( $include_html ) { | |
| 762 | + $add_html['aria-required'] = 'aria-required="true"'; | |
| 763 | + } | |
| 919 | 764 | } |
| 920 | 765 | |
| 921 | - /** | |
| 922 | - * @param array $field | |
| 923 | - * @param array $add_html | |
| 924 | - * @return void | |
| 925 | - */ | |
| 926 | 766 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 927 | 767 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| 928 | 768 | return; |
| 929 | 769 | } |
| @@ -932,19 +772,9 @@ | ||
| 932 | 772 | unset( $field['shortcodes']['autocomplete'] ); |
| 933 | 773 | } |
| 934 | 774 | |
| 935 | 775 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 936 | - if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) { | |
| 937 | - $subfield_name = $field['subfield_name']; | |
| 938 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 939 | - continue; | |
| 940 | - } | |
| 941 | - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. | |
| 942 | - $k = 'aria-invalid'; | |
| 943 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 944 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 945 | - } | |
| 946 | - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { | |
| 776 | + if ( 'opt' === $k ) { | |
| 947 | 777 | continue; |
| 948 | 778 | } |
| 949 | 779 | |
| 950 | 780 | if ( is_numeric( $k ) && strpos( $v, '=' ) ) { |
| @@ -955,45 +785,32 @@ | ||
| 955 | 785 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 956 | 786 | } |
| 957 | 787 | |
| 958 | 788 | unset( $k, $v ); |
| 959 | - }//end foreach | |
| 960 | - } | |
| 961 | - | |
| 962 | - /** | |
| 963 | - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. | |
| 964 | - * | |
| 965 | - * @since 6.11.2 | |
| 966 | - * | |
| 967 | - * @param string $key The option key. | |
| 968 | - * @return bool | |
| 969 | - */ | |
| 970 | - private static function should_allow_input_attribute( $key ) { | |
| 971 | - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { | |
| 972 | - return true; | |
| 973 | 789 | } |
| 974 | - return FrmAppHelper::input_key_is_safe( $key ); | |
| 975 | 790 | } |
| 976 | 791 | |
| 977 | 792 | /** |
| 978 | - * Add pattern attribute. | |
| 793 | + * Add pattern attribute | |
| 979 | 794 | * |
| 980 | 795 | * @since 3.0 |
| 981 | 796 | * |
| 982 | 797 | * @param array $field |
| 983 | 798 | * @param array $add_html |
| 984 | - * @return void | |
| 985 | 799 | */ |
| 986 | 800 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 987 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 988 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 801 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 989 | 802 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 990 | 803 | |
| 991 | - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 992 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 993 | - $format = substr( $format, 2, - 1 ); | |
| 804 | + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) { | |
| 805 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 994 | 806 | |
| 995 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 807 | + if ( $frm_settings->use_html ) { | |
| 808 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 809 | + $format = substr( $format, 2, - 1 ); | |
| 810 | + | |
| 811 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 812 | + } | |
| 996 | 813 | } |
| 997 | 814 | } |
| 998 | 815 | |
| 999 | 816 | public static function check_value( $opt, $opt_key, $field ) { |
| @@ -998,11 +815,11 @@ | ||
| 998 | 815 | |
| 999 | 816 | public static function check_value( $opt, $opt_key, $field ) { |
| 1000 | 817 | if ( is_array( $opt ) ) { |
| 1001 | 818 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1002 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 819 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1003 | 820 | } else { |
| 1004 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 821 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1005 | 822 | } |
| 1006 | 823 | } |
| 1007 | 824 | |
| 1008 | 825 | return $opt; |
| @@ -1009,10 +826,104 @@ | ||
| 1009 | 826 | } |
| 1010 | 827 | |
| 1011 | 828 | public static function check_label( $opt ) { |
| 1012 | 829 | if ( is_array( $opt ) ) { |
| 1013 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 830 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1014 | 831 | } |
| 1015 | 832 | |
| 1016 | 833 | return $opt; |
| 834 | + } | |
| 835 | + | |
| 836 | + /** | |
| 837 | + * @deprecated 4.0 | |
| 838 | + */ | |
| 839 | + public static function update_ajax_option() { | |
| 840 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 841 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 842 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 843 | + | |
| 844 | + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); | |
| 845 | + if ( ! $field_id ) { | |
| 846 | + wp_die(); | |
| 847 | + } | |
| 848 | + | |
| 849 | + $field = FrmField::getOne( $field_id ); | |
| 850 | + | |
| 851 | + if ( isset( $_POST['separate_value'] ) ) { | |
| 852 | + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1; | |
| 853 | + | |
| 854 | + $field->field_options['separate_value'] = $new_val; | |
| 855 | + unset( $new_val ); | |
| 856 | + } | |
| 857 | + | |
| 858 | + FrmField::update( | |
| 859 | + $field_id, | |
| 860 | + array( | |
| 861 | + 'field_options' => $field->field_options, | |
| 862 | + 'form_id' => $field->form_id, | |
| 863 | + ) | |
| 864 | + ); | |
| 865 | + wp_die(); | |
| 866 | + } | |
| 867 | + | |
| 868 | + /** | |
| 869 | + * @deprecated 4.0 | |
| 870 | + */ | |
| 871 | + public static function import_choices() { | |
| 872 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 873 | + wp_die(); | |
| 874 | + } | |
| 875 | + | |
| 876 | + /** | |
| 877 | + * Add Single Option or Other Option. | |
| 878 | + * | |
| 879 | + * @deprecated 4.0 Moved to Pro for Other option only. | |
| 880 | + */ | |
| 881 | + public static function add_option() { | |
| 882 | + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' ); | |
| 883 | + } | |
| 884 | + | |
| 885 | + /** | |
| 886 | + * @deprecated 4.0 | |
| 887 | + */ | |
| 888 | + public static function update_order() { | |
| 889 | + FrmDeprecated::update_order(); | |
| 890 | + } | |
| 891 | + | |
| 892 | + /** | |
| 893 | + * @deprecated 3.0 | |
| 894 | + * @codeCoverageIgnore | |
| 895 | + */ | |
| 896 | + public static function edit_name( $field = 'name', $id = '' ) { | |
| 897 | + FrmDeprecated::edit_name( $field, $id ); | |
| 898 | + } | |
| 899 | + | |
| 900 | + /** | |
| 901 | + * @deprecated 3.0 | |
| 902 | + * @codeCoverageIgnore | |
| 903 | + * | |
| 904 | + * @param int $field_id | |
| 905 | + * @param array $values | |
| 906 | + * @param int $form_id | |
| 907 | + * | |
| 908 | + * @return array | |
| 909 | + */ | |
| 910 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { | |
| 911 | + return FrmDeprecated::include_single_field( $field_id, $values, $form_id ); | |
| 912 | + } | |
| 913 | + | |
| 914 | + /** | |
| 915 | + * @deprecated 2.3 | |
| 916 | + * @codeCoverageIgnore | |
| 917 | + */ | |
| 918 | + public static function edit_option() { | |
| 919 | + FrmDeprecated::deprecated( __METHOD__, '2.3' ); | |
| 920 | + } | |
| 921 | + | |
| 922 | + /** | |
| 923 | + * @deprecated 2.3 | |
| 924 | + * @codeCoverageIgnore | |
| 925 | + */ | |
| 926 | + public static function delete_option() { | |
| 927 | + FrmDeprecated::deprecated( __METHOD__, '2.3' ); | |
| 1017 | 928 | } |
| 1018 | 929 | } |