| @@ -18,10 +18,9 @@ | ||
| 18 | 18 | |
| 19 | 19 | // Javascript may be included in some field settings. |
| 20 | 20 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 21 | 21 | $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array(); |
| 22 | - | |
| 23 | - if ( ! $fields ) { | |
| 22 | + if ( empty( $fields ) ) { | |
| 24 | 23 | wp_die(); |
| 25 | 24 | } |
| 26 | 25 | |
| 27 | 26 | $_GET['page'] = 'formidable'; |
| @@ -34,11 +33,10 @@ | ||
| 34 | 33 | |
| 35 | 34 | foreach ( $fields as $field ) { |
| 36 | 35 | $field = htmlspecialchars_decode( nl2br( $field ) ); |
| 37 | 36 | $field = json_decode( $field ); |
| 38 | - | |
| 39 | 37 | if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) { |
| 40 | - // This field may have already been loaded | |
| 38 | + // this field may have already been loaded | |
| 41 | 39 | continue; |
| 42 | 40 | } |
| 43 | 41 | |
| 44 | 42 | if ( ! isset( $field->value ) ) { |
| @@ -49,10 +47,11 @@ | ||
| 49 | 47 | $field->default_value = json_decode( json_encode( $field->default_value ), true ); |
| 50 | 48 | |
| 51 | 49 | ob_start(); |
| 52 | 50 | self::load_single_field( $field, $values ); |
| 53 | - $field_html[ absint( $field->id ) ] = ob_get_clean(); | |
| 54 | - }//end foreach | |
| 51 | + $field_html[ absint( $field->id ) ] = ob_get_contents(); | |
| 52 | + ob_end_clean(); | |
| 53 | + } | |
| 55 | 54 | |
| 56 | 55 | echo json_encode( $field_html ); |
| 57 | 56 | |
| 58 | 57 | wp_die(); |
| @@ -64,17 +63,16 @@ | ||
| 64 | 63 | public static function create() { |
| 65 | 64 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 66 | 65 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 67 | 66 | |
| 68 | - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 69 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 70 | - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' ); | |
| 67 | + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 68 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 71 | 69 | |
| 72 | 70 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 73 | 71 | |
| 74 | - $field = self::include_new_field( $field_type, $form_id, $field_options ); | |
| 72 | + $field = self::include_new_field( $field_type, $form_id ); | |
| 75 | 73 | |
| 76 | - // This hook will allow for multiple fields to be added at once | |
| 74 | + // this hook will allow for multiple fields to be added at once | |
| 77 | 75 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 78 | 76 | |
| 79 | 77 | wp_die(); |
| 80 | 78 | } |
| @@ -83,19 +81,14 @@ | ||
| 83 | 81 | * Set up and create a new field |
| 84 | 82 | * |
| 85 | 83 | * @param string $field_type |
| 86 | 84 | * @param int $form_id |
| 87 | - * @param array $field_options | |
| 88 | 85 | * |
| 89 | 86 | * @return array|false |
| 90 | 87 | */ |
| 91 | - public static function include_new_field( $field_type, $form_id, $field_options = array() ) { | |
| 88 | + public static function include_new_field( $field_type, $form_id ) { | |
| 92 | 89 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 93 | 90 | |
| 94 | - if ( $field_options ) { | |
| 95 | - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); | |
| 96 | - } | |
| 97 | - | |
| 98 | 91 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| 99 | 92 | $field_values['field_options']['draft'] = 1; |
| 100 | 93 | |
| 101 | 94 | /** |
| @@ -107,15 +100,15 @@ | ||
| 107 | 100 | if ( ! $field_id ) { |
| 108 | 101 | return false; |
| 109 | 102 | } |
| 110 | 103 | |
| 111 | - $field = self::get_field_array_from_id( $field_id ); | |
| 104 | + $field = self::get_field_array_from_id( $field_id ); | |
| 105 | + | |
| 112 | 106 | $values = array(); |
| 113 | - | |
| 114 | 107 | if ( FrmAppHelper::pro_is_installed() ) { |
| 115 | 108 | $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
| 116 | - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 117 | 109 | |
| 110 | + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 118 | 111 | if ( $parent_form_id ) { |
| 119 | 112 | $field['parent_form_id'] = $parent_form_id; |
| 120 | 113 | } |
| 121 | 114 | } |
| @@ -128,10 +121,11 @@ | ||
| 128 | 121 | public static function duplicate() { |
| 129 | 122 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 130 | 123 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 131 | 124 | |
| 132 | - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 133 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 125 | + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 126 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 127 | + | |
| 134 | 128 | $new_field = FrmField::duplicate_single_field( $field_id, $form_id ); |
| 135 | 129 | |
| 136 | 130 | if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) { |
| 137 | 131 | self::load_single_field( $new_field['field_id'], $new_field['values'] ); |
| @@ -148,8 +142,9 @@ | ||
| 148 | 142 | * @return array |
| 149 | 143 | */ |
| 150 | 144 | public static function get_field_array_from_id( $field_id ) { |
| 151 | 145 | $field = FrmField::getOne( $field_id ); |
| 146 | + | |
| 152 | 147 | return FrmFieldsHelper::setup_edit_vars( $field ); |
| 153 | 148 | } |
| 154 | 149 | |
| 155 | 150 | /** |
| @@ -154,13 +149,11 @@ | ||
| 154 | 149 | |
| 155 | 150 | /** |
| 156 | 151 | * @since 3.0 |
| 157 | 152 | * |
| 158 | - * @param array|int|object|string $field_object | |
| 159 | - * @param array $values | |
| 160 | - * @param int $form_id | |
| 161 | - * | |
| 162 | - * @return void | |
| 153 | + * @param array|int|object $field_object | |
| 154 | + * @param array $values | |
| 155 | + * @param int $form_id | |
| 163 | 156 | */ |
| 164 | 157 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 165 | 158 | global $frm_vars; |
| 166 | 159 | $frm_vars['is_admin'] = true; |
| @@ -171,10 +164,11 @@ | ||
| 171 | 164 | $field = $field_object; |
| 172 | 165 | $field_object = FrmField::getOne( $field['id'] ); |
| 173 | 166 | } |
| 174 | 167 | |
| 175 | - $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 176 | - $display = self::display_field_options( array(), $field_obj ); | |
| 168 | + $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 169 | + $display = self::display_field_options( array(), $field_obj ); | |
| 170 | + | |
| 177 | 171 | $ajax_loading = ! empty( $values['ajax_load'] ); |
| 178 | 172 | $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true ); |
| 179 | 173 | |
| 180 | 174 | if ( $ajax_loading && $ajax_this_field ) { |
| @@ -183,23 +177,12 @@ | ||
| 183 | 177 | return; |
| 184 | 178 | } |
| 185 | 179 | |
| 186 | 180 | if ( ! isset( $field ) && is_object( $field_object ) ) { |
| 187 | - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id; | |
| 181 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 188 | 182 | $field = FrmFieldsHelper::setup_edit_vars( $field_object ); |
| 189 | 183 | } |
| 190 | 184 | |
| 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 ); | |
| 201 | - | |
| 202 | 185 | $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); |
| 203 | 186 | $li_classes .= ' ui-state-default widgets-holder-wrap'; |
| 204 | 187 | |
| 205 | 188 | require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; |
| @@ -210,9 +193,8 @@ | ||
| 210 | 193 | * |
| 211 | 194 | * @param array $field |
| 212 | 195 | * @param array $display |
| 213 | 196 | * @param FrmFieldType $field_info |
| 214 | - * | |
| 215 | 197 | * @return string |
| 216 | 198 | */ |
| 217 | 199 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 218 | 200 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| @@ -224,9 +206,9 @@ | ||
| 224 | 206 | |
| 225 | 207 | $li_classes .= 'frmend'; |
| 226 | 208 | |
| 227 | 209 | if ( $field ) { |
| 228 | - return apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 210 | + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 229 | 211 | } |
| 230 | 212 | |
| 231 | 213 | return $li_classes; |
| 232 | 214 | } |
| @@ -260,9 +242,8 @@ | ||
| 260 | 242 | * |
| 261 | 243 | * @since 6.8.4 |
| 262 | 244 | * |
| 263 | 245 | * @param array $bulk_edit_types |
| 264 | - * | |
| 265 | 246 | * @return array |
| 266 | 247 | */ |
| 267 | 248 | $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); |
| 268 | 249 | |
| @@ -270,19 +251,18 @@ | ||
| 270 | 251 | return; |
| 271 | 252 | } |
| 272 | 253 | |
| 273 | 254 | $field = FrmFieldsHelper::setup_edit_vars( $field ); |
| 255 | + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 256 | + $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 257 | + $opts = array_map( 'trim', $opts ); | |
| 274 | 258 | |
| 275 | - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 276 | - $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 277 | - $opts = array_map( 'trim', $opts ); | |
| 278 | - | |
| 279 | 259 | $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); |
| 280 | 260 | $field['separate_value'] = $separate === 'true'; |
| 281 | 261 | |
| 282 | 262 | if ( $field['separate_value'] ) { |
| 283 | 263 | foreach ( $opts as $opt_key => $opt ) { |
| 284 | - if ( str_contains( $opt, '|' ) ) { | |
| 264 | + if ( strpos( $opt, '|' ) !== false ) { | |
| 285 | 265 | $vals = explode( '|', $opt ); |
| 286 | 266 | $opts[ $opt_key ] = array( |
| 287 | 267 | 'label' => trim( $vals[0] ), |
| 288 | 268 | 'value' => trim( $vals[1] ), |
| @@ -293,11 +273,10 @@ | ||
| 293 | 273 | } |
| 294 | 274 | } |
| 295 | 275 | |
| 296 | 276 | // Keep other options after bulk update. |
| 297 | - if ( ! empty( $field['field_options']['other'] ) ) { | |
| 277 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { | |
| 298 | 278 | $other_array = array(); |
| 299 | - | |
| 300 | 279 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 301 | 280 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 302 | 281 | $other_array[ $opt_key ] = $opt; |
| 303 | 282 | } |
| @@ -302,10 +281,9 @@ | ||
| 302 | 281 | $other_array[ $opt_key ] = $opt; |
| 303 | 282 | } |
| 304 | 283 | unset( $opt_key, $opt ); |
| 305 | 284 | } |
| 306 | - | |
| 307 | - if ( $other_array ) { | |
| 285 | + if ( ! empty( $other_array ) ) { | |
| 308 | 286 | $opts = array_merge( $opts, $other_array ); |
| 309 | 287 | } |
| 310 | 288 | } |
| 311 | 289 | |
| @@ -319,9 +297,8 @@ | ||
| 319 | 297 | /** |
| 320 | 298 | * @since 4.0 |
| 321 | 299 | * |
| 322 | 300 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 323 | - * | |
| 324 | 301 | * @return void |
| 325 | 302 | */ |
| 326 | 303 | public static function load_single_field_settings( $atts ) { |
| 327 | 304 | $field = $atts['field']; |
| @@ -347,9 +324,9 @@ | ||
| 347 | 324 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 348 | 325 | // Add fallback for an add-on field type that has been deactivated. |
| 349 | 326 | $all_field_types[ $field['type'] ] = array( |
| 350 | 327 | 'name' => ucfirst( $field['type'] ), |
| 351 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 328 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 352 | 329 | ); |
| 353 | 330 | } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) { |
| 354 | 331 | // Fallback for fields added in a more basic way. |
| 355 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| @@ -355,9 +332,8 @@ | ||
| 355 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 356 | 333 | } |
| 357 | 334 | |
| 358 | 335 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 359 | - | |
| 360 | 336 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 361 | 337 | $type_name = $all_field_types['divider|repeat']['name']; |
| 362 | 338 | } |
| 363 | 339 | |
| @@ -390,9 +366,8 @@ | ||
| 390 | 366 | * @since 4.0 |
| 391 | 367 | * |
| 392 | 368 | * @param array $field |
| 393 | 369 | * @param array $atts |
| 394 | - * | |
| 395 | 370 | * @return array |
| 396 | 371 | */ |
| 397 | 372 | private static function default_value_types( $field, $atts ) { |
| 398 | 373 | $types = array( |
| @@ -397,33 +372,31 @@ | ||
| 397 | 372 | private static function default_value_types( $field, $atts ) { |
| 398 | 373 | $types = array( |
| 399 | 374 | 'default_value' => array( |
| 400 | 375 | 'class' => '', |
| 401 | - 'icon' => 'frmfont frm_text2_icon', | |
| 402 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 376 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 377 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 403 | 378 | 'data' => array( |
| 404 | 379 | 'frmshow' => '#default-value-for-', |
| 405 | 380 | ), |
| 406 | 381 | ), |
| 407 | 382 | 'calc' => array( |
| 408 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 409 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 410 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 411 | - 'data' => array( | |
| 383 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 384 | + 'title' => __( 'Default Value (Calculation)', 'formidable' ), | |
| 385 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 386 | + 'data' => array( | |
| 412 | 387 | 'medium' => 'calculations', |
| 413 | 388 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 414 | 389 | ), |
| 415 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 416 | 390 | ), |
| 417 | 391 | 'get_values_field' => array( |
| 418 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 419 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 420 | - 'icon' => 'frmfont frm_search_icon', | |
| 421 | - 'data' => array( | |
| 392 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 393 | + 'title' => __( 'Default Value (Lookup)', 'formidable' ), | |
| 394 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 395 | + 'data' => array( | |
| 422 | 396 | 'medium' => 'lookup', |
| 423 | 397 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 424 | 398 | ), |
| 425 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 426 | 399 | ), |
| 427 | 400 | ); |
| 428 | 401 | |
| 429 | 402 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| @@ -431,13 +404,11 @@ | ||
| 431 | 404 | // Set active class. |
| 432 | 405 | $settings = array_keys( $types ); |
| 433 | 406 | $active = 'default_value'; |
| 434 | 407 | |
| 435 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 436 | - foreach ( $settings as $type ) { | |
| 437 | - if ( ! empty( $field[ $type ] ) ) { | |
| 438 | - $active = $type; | |
| 439 | - } | |
| 408 | + foreach ( $settings as $type ) { | |
| 409 | + if ( ! empty( $field[ $type ] ) ) { | |
| 410 | + $active = $type; | |
| 440 | 411 | } |
| 441 | 412 | } |
| 442 | 413 | |
| 443 | 414 | $types[ $active ]['class'] .= ' current'; |
| @@ -447,9 +418,8 @@ | ||
| 447 | 418 | } |
| 448 | 419 | |
| 449 | 420 | /** |
| 450 | 421 | * @param string $type |
| 451 | - * | |
| 452 | 422 | * @return string |
| 453 | 423 | */ |
| 454 | 424 | public static function change_type( $type ) { |
| 455 | 425 | $type_switch = array( |
| @@ -459,9 +429,8 @@ | ||
| 459 | 429 | 'rte' => 'textarea', |
| 460 | 430 | 'website' => 'url', |
| 461 | 431 | 'image' => 'url', |
| 462 | 432 | ); |
| 463 | - | |
| 464 | 433 | if ( isset( $type_switch[ $type ] ) ) { |
| 465 | 434 | $type = $type_switch[ $type ]; |
| 466 | 435 | } |
| 467 | 436 | |
| @@ -469,22 +438,24 @@ | ||
| 469 | 438 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 470 | 439 | // The credit_card key is set for backward compatibility. |
| 471 | 440 | unset( $pro_fields['credit_card'] ); |
| 472 | 441 | |
| 473 | - return array_key_exists( $type, $pro_fields ) ? 'text' : $type; | |
| 442 | + if ( array_key_exists( $type, $pro_fields ) ) { | |
| 443 | + $type = 'text'; | |
| 444 | + } | |
| 445 | + | |
| 446 | + return $type; | |
| 474 | 447 | } |
| 475 | 448 | |
| 476 | 449 | /** |
| 477 | - * @param array $settings | |
| 478 | - * @param FrmFieldType|null $field_info | |
| 450 | + * @param array $settings | |
| 451 | + * @param object|null $field_info | |
| 479 | 452 | * |
| 480 | 453 | * @return array |
| 481 | 454 | */ |
| 482 | 455 | public static function display_field_options( $settings, $field_info = null ) { |
| 483 | 456 | if ( $field_info ) { |
| 484 | - $settings = $field_info->display_field_settings(); | |
| 485 | - | |
| 486 | - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public. | |
| 457 | + $settings = $field_info->display_field_settings(); | |
| 487 | 458 | $settings['field_data'] = $field_info->field; |
| 488 | 459 | } |
| 489 | 460 | |
| 490 | 461 | return apply_filters( 'frm_display_field_options', $settings ); |
| @@ -494,20 +465,17 @@ | ||
| 494 | 465 | * Display the format option |
| 495 | 466 | * |
| 496 | 467 | * @since 3.0 |
| 497 | 468 | * |
| 498 | - * @param array $field Field data. | |
| 499 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 500 | - * | |
| 469 | + * @param array $field | |
| 501 | 470 | * @return void |
| 502 | 471 | */ |
| 503 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 504 | - $attributes = array( | |
| 505 | - 'class' => 'frm-has-modal', | |
| 506 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 507 | - ); | |
| 472 | + public static function show_format_option( $field ) { | |
| 473 | + $attributes = array(); | |
| 474 | + $attributes['class'] = 'frm-has-modal'; | |
| 508 | 475 | |
| 509 | - if ( $is_hidden ) { | |
| 476 | + if ( 'phone' === $field['type'] ) { | |
| 477 | + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id']; | |
| 510 | 478 | $attributes['class'] .= ' frm_hidden'; |
| 511 | 479 | } |
| 512 | 480 | |
| 513 | 481 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| @@ -512,14 +480,8 @@ | ||
| 512 | 480 | |
| 513 | 481 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 514 | 482 | } |
| 515 | 483 | |
| 516 | - /** | |
| 517 | - * @param array $field | |
| 518 | - * @param bool $echo | |
| 519 | - * | |
| 520 | - * @return string | |
| 521 | - */ | |
| 522 | 484 | public static function input_html( $field, $echo = true ) { |
| 523 | 485 | $class = array(); |
| 524 | 486 | self::add_input_classes( $field, $class ); |
| 525 | 487 | |
| @@ -548,9 +510,8 @@ | ||
| 548 | 510 | |
| 549 | 511 | /** |
| 550 | 512 | * @param array $field |
| 551 | 513 | * @param array $class |
| 552 | - * | |
| 553 | 514 | * @return void |
| 554 | 515 | */ |
| 555 | 516 | private static function add_input_classes( $field, array &$class ) { |
| 556 | 517 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -568,9 +529,8 @@ | ||
| 568 | 529 | |
| 569 | 530 | /** |
| 570 | 531 | * @param array $field |
| 571 | 532 | * @param array $add_html |
| 572 | - * | |
| 573 | 533 | * @return void |
| 574 | 534 | */ |
| 575 | 535 | private static function add_html_size( $field, array &$add_html ) { |
| 576 | 536 | $size_fields = array( |
| @@ -603,9 +563,8 @@ | ||
| 603 | 563 | |
| 604 | 564 | /** |
| 605 | 565 | * @param array $field |
| 606 | 566 | * @param array $add_html |
| 607 | - * | |
| 608 | 567 | * @return void |
| 609 | 568 | */ |
| 610 | 569 | private static function add_html_cols( $field, array &$add_html ) { |
| 611 | 570 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -619,9 +578,9 @@ | ||
| 619 | 578 | 'rem' => 0.444, |
| 620 | 579 | 'em' => 0.544, |
| 621 | 580 | ); |
| 622 | 581 | |
| 623 | - // Include "col" for valid html | |
| 582 | + // include "col" for valid html | |
| 624 | 583 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 625 | 584 | |
| 626 | 585 | if ( ! isset( $calc[ $unit ] ) ) { |
| 627 | 586 | return; |
| @@ -626,9 +585,10 @@ | ||
| 626 | 585 | if ( ! isset( $calc[ $unit ] ) ) { |
| 627 | 586 | return; |
| 628 | 587 | } |
| 629 | 588 | |
| 630 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 589 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 590 | + | |
| 631 | 591 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 632 | 592 | } |
| 633 | 593 | |
| 634 | 594 | /** |
| @@ -633,9 +593,8 @@ | ||
| 633 | 593 | |
| 634 | 594 | /** |
| 635 | 595 | * @param array $field |
| 636 | 596 | * @param array $add_html |
| 637 | - * | |
| 638 | 597 | * @return void |
| 639 | 598 | */ |
| 640 | 599 | private static function add_html_length( $field, array &$add_html ) { |
| 641 | 600 | // Check for max setting and if this field accepts maxlength. |
| @@ -661,13 +620,11 @@ | ||
| 661 | 620 | /** |
| 662 | 621 | * @param array $field |
| 663 | 622 | * @param array $add_html |
| 664 | 623 | * @param array $class |
| 665 | - * | |
| 666 | 624 | * @return void |
| 667 | 625 | */ |
| 668 | 626 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 669 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 670 | 627 | if ( $field['default_value'] != '' ) { |
| 671 | 628 | if ( is_array( $field['default_value'] ) ) { |
| 672 | 629 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 673 | 630 | } else { |
| @@ -675,12 +632,10 @@ | ||
| 675 | 632 | } |
| 676 | 633 | } |
| 677 | 634 | |
| 678 | 635 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 679 | - | |
| 680 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 681 | 636 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 682 | - // Don't include a json placeholder | |
| 637 | + // don't include a json placeholder | |
| 683 | 638 | return; |
| 684 | 639 | } |
| 685 | 640 | |
| 686 | 641 | self::add_placeholder_to_input( $field, $add_html ); |
| @@ -691,13 +646,14 @@ | ||
| 691 | 646 | * |
| 692 | 647 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 693 | 648 | * |
| 694 | 649 | * @param array $field Field array. |
| 695 | - * | |
| 696 | 650 | * @return string |
| 697 | 651 | */ |
| 698 | 652 | private static function prepare_placeholder( $field ) { |
| 699 | - return $field['placeholder'] ?? ''; | |
| 653 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 654 | + | |
| 655 | + return $placeholder; | |
| 700 | 656 | } |
| 701 | 657 | |
| 702 | 658 | /** |
| 703 | 659 | * If the label position is "inside", |
| @@ -718,17 +674,13 @@ | ||
| 718 | 674 | * Maybe add a blank placeholder option before any options |
| 719 | 675 | * in a dropdown. |
| 720 | 676 | * |
| 721 | 677 | * @since 4.04 |
| 722 | - * | |
| 723 | - * @param array|object $field | |
| 724 | - * | |
| 725 | 678 | * @return bool True if placeholder was added. |
| 726 | 679 | */ |
| 727 | 680 | public static function add_placeholder_to_select( $field ) { |
| 728 | 681 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 729 | - | |
| 730 | - if ( ! $placeholder ) { | |
| 682 | + if ( empty( $placeholder ) ) { | |
| 731 | 683 | $placeholder = self::get_default_value_from_name( $field ); |
| 732 | 684 | } |
| 733 | 685 | |
| 734 | 686 | $use_placeholder = $placeholder; |
| @@ -735,9 +687,8 @@ | ||
| 735 | 687 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 736 | 688 | |
| 737 | 689 | if ( $autocomplete ) { |
| 738 | 690 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 739 | - | |
| 740 | 691 | if ( $use_chosen ) { |
| 741 | 692 | $use_placeholder = ''; |
| 742 | 693 | } |
| 743 | 694 | } |
| @@ -748,8 +699,13 @@ | ||
| 748 | 699 | 'value' => '', |
| 749 | 700 | 'data-placeholder' => 'true', |
| 750 | 701 | ); |
| 751 | 702 | |
| 703 | + if ( $autocomplete && empty( $use_chosen ) ) { | |
| 704 | + // This is required for Slim Select. | |
| 705 | + $placeholder_attributes['data-placeholder'] = 'true'; | |
| 706 | + } | |
| 707 | + | |
| 752 | 708 | FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); |
| 753 | 709 | return true; |
| 754 | 710 | } |
| 755 | 711 | |
| @@ -760,9 +716,8 @@ | ||
| 760 | 716 | * Use HTML5 placeholder with js fallback. |
| 761 | 717 | * |
| 762 | 718 | * @param array $field |
| 763 | 719 | * @param array $add_html |
| 764 | - * | |
| 765 | 720 | * @return void |
| 766 | 721 | */ |
| 767 | 722 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 768 | 723 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -772,13 +727,11 @@ | ||
| 772 | 727 | |
| 773 | 728 | /** |
| 774 | 729 | * @param array $field |
| 775 | 730 | * @param array $add_html |
| 776 | - * | |
| 777 | 731 | * @return void |
| 778 | 732 | */ |
| 779 | 733 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 780 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 781 | 734 | if ( $field['placeholder'] != '' ) { |
| 782 | 735 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 783 | 736 | |
| 784 | 737 | if ( 'select' === $field['type'] ) { |
| @@ -785,20 +738,13 @@ | ||
| 785 | 738 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 786 | 739 | } |
| 787 | 740 | } |
| 788 | 741 | |
| 789 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 790 | 742 | if ( $field['default_value'] != '' ) { |
| 791 | 743 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 792 | 744 | } |
| 793 | 745 | } |
| 794 | 746 | |
| 795 | - /** | |
| 796 | - * @param array $field | |
| 797 | - * @param array $add_html | |
| 798 | - * | |
| 799 | - * @return void | |
| 800 | - */ | |
| 801 | 747 | private static function add_validation_messages( $field, array &$add_html ) { |
| 802 | 748 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 803 | 749 | |
| 804 | 750 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -822,9 +768,8 @@ | ||
| 822 | 768 | * |
| 823 | 769 | * @since 6.9 |
| 824 | 770 | * |
| 825 | 771 | * @param array|object $field |
| 826 | - * | |
| 827 | 772 | * @return array |
| 828 | 773 | */ |
| 829 | 774 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 830 | 775 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -854,26 +799,21 @@ | ||
| 854 | 799 | * @since 5.0.03 |
| 855 | 800 | * |
| 856 | 801 | * @param array $field |
| 857 | 802 | * @param array $add_html |
| 858 | - * | |
| 859 | 803 | * @return void |
| 860 | 804 | */ |
| 861 | 805 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 862 | 806 | $form = self::get_form_for_js_validation( $field ); |
| 863 | - | |
| 864 | 807 | if ( false === $form ) { |
| 865 | 808 | return; |
| 866 | 809 | } |
| 867 | 810 | |
| 868 | 811 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 869 | - | |
| 870 | - if ( false === $error_body ) { | |
| 871 | - return; | |
| 812 | + if ( false !== $error_body ) { | |
| 813 | + $error_body = urlencode( $error_body ); | |
| 814 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 872 | 815 | } |
| 873 | - | |
| 874 | - $error_body = urlencode( $error_body ); | |
| 875 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 876 | 816 | } |
| 877 | 817 | |
| 878 | 818 | /** |
| 879 | 819 | * @since 5.0.03 |
| @@ -878,24 +818,20 @@ | ||
| 878 | 818 | /** |
| 879 | 819 | * @since 5.0.03 |
| 880 | 820 | * |
| 881 | 821 | * @param array $field |
| 882 | - * | |
| 883 | 822 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 884 | 823 | */ |
| 885 | 824 | private static function get_form_for_js_validation( $field ) { |
| 886 | 825 | global $frm_vars; |
| 887 | - | |
| 888 | 826 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 889 | 827 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 890 | 828 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 891 | 829 | } |
| 892 | - | |
| 893 | 830 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 894 | 831 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 895 | 832 | } |
| 896 | 833 | } |
| 897 | - | |
| 898 | 834 | return false; |
| 899 | 835 | } |
| 900 | 836 | |
| 901 | 837 | /** |
| @@ -901,9 +837,8 @@ | ||
| 901 | 837 | /** |
| 902 | 838 | * @param stdClass $form |
| 903 | 839 | * @param array $field |
| 904 | 840 | * @param array $errors |
| 905 | - * | |
| 906 | 841 | * @return false|string |
| 907 | 842 | */ |
| 908 | 843 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 909 | 844 | if ( empty( $field['custom_html'] ) ) { |
| @@ -911,16 +846,15 @@ | ||
| 911 | 846 | } |
| 912 | 847 | |
| 913 | 848 | $custom_html = $field['custom_html']; |
| 914 | 849 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 915 | - $start = strpos( $custom_html, '[if error]' ); | |
| 916 | 850 | |
| 851 | + $start = strpos( $custom_html, '[if error]' ); | |
| 917 | 852 | if ( false === $start ) { |
| 918 | 853 | return false; |
| 919 | 854 | } |
| 920 | 855 | |
| 921 | 856 | $end = strpos( $custom_html, '[/if error]' ); |
| 922 | - | |
| 923 | 857 | if ( false === $end || $end < $start ) { |
| 924 | 858 | return false; |
| 925 | 859 | } |
| 926 | 860 | |
| @@ -931,9 +865,13 @@ | ||
| 931 | 865 | '<div class="frm_error">[error]</div>', |
| 932 | 866 | '<div class="frm_error" role="alert">[error]</div>', |
| 933 | 867 | ); |
| 934 | 868 | |
| 935 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 869 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 870 | + return false; | |
| 871 | + } | |
| 872 | + | |
| 873 | + return $error_body; | |
| 936 | 874 | } |
| 937 | 875 | |
| 938 | 876 | /** |
| 939 | 877 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -940,16 +878,13 @@ | ||
| 940 | 878 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 941 | 879 | * remove it is present if needed. |
| 942 | 880 | * |
| 943 | 881 | * @since 3.06.01 |
| 944 | - * | |
| 945 | 882 | * @param array $field |
| 946 | 883 | * @param array $add_html |
| 947 | - * | |
| 948 | 884 | * @return void |
| 949 | 885 | */ |
| 950 | 886 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 951 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 952 | 887 | $excluded_field_types = |
| 953 | 888 | FrmField::is_radio( $field ) || |
| 954 | 889 | FrmField::is_checkbox( $field ) || |
| 955 | 890 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -954,9 +889,8 @@ | ||
| 954 | 889 | FrmField::is_checkbox( $field ) || |
| 955 | 890 | FrmField::is_field_type( $field, 'file' ) || |
| 956 | 891 | FrmField::is_field_type( $field, 'nps' ) || |
| 957 | 892 | FrmField::is_field_type( $field, 'scale' ); |
| 958 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 959 | 893 | |
| 960 | 894 | if ( $excluded_field_types ) { |
| 961 | 895 | return; |
| 962 | 896 | } |
| @@ -966,9 +900,8 @@ | ||
| 966 | 900 | |
| 967 | 901 | /** |
| 968 | 902 | * @param array $field |
| 969 | 903 | * @param array $add_html |
| 970 | - * | |
| 971 | 904 | * @return void |
| 972 | 905 | */ |
| 973 | 906 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 974 | 907 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -979,25 +912,13 @@ | ||
| 979 | 912 | unset( $field['shortcodes']['autocomplete'] ); |
| 980 | 913 | } |
| 981 | 914 | |
| 982 | 915 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 983 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 984 | - $subfield_name = $field['subfield_name']; | |
| 985 | - | |
| 986 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 987 | - continue; | |
| 988 | - } | |
| 989 | - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. | |
| 990 | - $k = 'aria-invalid'; | |
| 991 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 992 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 993 | - } | |
| 994 | - | |
| 995 | 916 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 996 | 917 | continue; |
| 997 | 918 | } |
| 998 | 919 | |
| 999 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 920 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1000 | 921 | $add_html[] = $v; |
| 1001 | 922 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1002 | 923 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1003 | 924 | } else { |
| @@ -1004,9 +925,9 @@ | ||
| 1004 | 925 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 1005 | 926 | } |
| 1006 | 927 | |
| 1007 | 928 | unset( $k, $v ); |
| 1008 | - }//end foreach | |
| 929 | + } | |
| 1009 | 930 | } |
| 1010 | 931 | |
| 1011 | 932 | /** |
| 1012 | 933 | * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. |
| @@ -1013,9 +934,8 @@ | ||
| 1013 | 934 | * |
| 1014 | 935 | * @since 6.11.2 |
| 1015 | 936 | * |
| 1016 | 937 | * @param string $key The option key. |
| 1017 | - * | |
| 1018 | 938 | * @return bool |
| 1019 | 939 | */ |
| 1020 | 940 | private static function should_allow_input_attribute( $key ) { |
| 1021 | 941 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1030,39 +950,28 @@ | ||
| 1030 | 950 | * @since 3.0 |
| 1031 | 951 | * |
| 1032 | 952 | * @param array $field |
| 1033 | 953 | * @param array $add_html |
| 1034 | - * | |
| 1035 | 954 | * @return void |
| 1036 | 955 | */ |
| 1037 | 956 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1038 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 1039 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 957 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 1040 | 958 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1041 | 959 | |
| 1042 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1043 | - return; | |
| 960 | + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 961 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 962 | + $format = substr( $format, 2, - 1 ); | |
| 963 | + | |
| 964 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1044 | 965 | } |
| 1045 | - | |
| 1046 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1047 | - $format = substr( $format, 2, - 1 ); | |
| 1048 | - | |
| 1049 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1050 | 966 | } |
| 1051 | 967 | |
| 1052 | - /** | |
| 1053 | - * @param mixed $opt | |
| 1054 | - * @param mixed $opt_key | |
| 1055 | - * @param array|object $field | |
| 1056 | - * | |
| 1057 | - * @return mixed | |
| 1058 | - */ | |
| 1059 | 968 | public static function check_value( $opt, $opt_key, $field ) { |
| 1060 | 969 | if ( is_array( $opt ) ) { |
| 1061 | 970 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1062 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 971 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1063 | 972 | } else { |
| 1064 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 973 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1065 | 974 | } |
| 1066 | 975 | } |
| 1067 | 976 | |
| 1068 | 977 | return $opt; |
| @@ -1067,13 +976,12 @@ | ||
| 1067 | 976 | |
| 1068 | 977 | return $opt; |
| 1069 | 978 | } |
| 1070 | 979 | |
| 1071 | - /** | |
| 1072 | - * @param mixed $opt | |
| 1073 | - * | |
| 1074 | - * @return mixed | |
| 1075 | - */ | |
| 1076 | 980 | public static function check_label( $opt ) { |
| 1077 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 981 | + if ( is_array( $opt ) ) { | |
| 982 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 983 | + } | |
| 984 | + | |
| 985 | + return $opt; | |
| 1078 | 986 | } |
| 1079 | 987 | } |