| @@ -11,55 +11,48 @@ | ||
| 11 | 11 | * @var FrmFieldSelectionData|null |
| 12 | 12 | */ |
| 13 | 13 | private static $field_selection_data; |
| 14 | 14 | |
| 15 | - /** | |
| 16 | - * Render the fields the form builder asked for over ajax. | |
| 17 | - * | |
| 18 | - * The browser sends field ids only. The fields themselves are read from the form, which is one | |
| 19 | - * indexed query shared with the rest of the request through the field cache, and cheaper than | |
| 20 | - * shipping every field's data down to the page and straight back up again. | |
| 21 | - * | |
| 22 | - * @return void | |
| 23 | - */ | |
| 24 | 15 | public static function load_field() { |
| 25 | 16 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 26 | 17 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 27 | 18 | |
| 28 | - $field_ids = FrmAppHelper::get_post_param( 'field_ids', array(), 'absint' ); | |
| 29 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 30 | - | |
| 31 | - if ( ! $form_id || ! is_array( $field_ids ) || ! $field_ids ) { | |
| 19 | + // Javascript may be included in some field settings. | |
| 20 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 21 | + $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array(); | |
| 22 | + if ( empty( $fields ) ) { | |
| 32 | 23 | wp_die(); |
| 33 | 24 | } |
| 34 | 25 | |
| 35 | 26 | $_GET['page'] = 'formidable'; |
| 36 | - $fields = self::get_builder_fields_by_id( $form_id ); | |
| 37 | - $values = array( | |
| 38 | - 'id' => $form_id, | |
| 27 | + | |
| 28 | + $values = array( | |
| 29 | + 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), | |
| 39 | 30 | 'doing_ajax' => true, |
| 40 | 31 | ); |
| 41 | - $field_html = array(); | |
| 32 | + $field_html = array(); | |
| 42 | 33 | |
| 43 | - foreach ( $field_ids as $field_id ) { | |
| 44 | - if ( ! isset( $fields[ $field_id ] ) ) { | |
| 45 | - // This field may have already been loaded, or is no longer in the form. | |
| 34 | + foreach ( $fields as $field ) { | |
| 35 | + $field = htmlspecialchars_decode( nl2br( $field ) ); | |
| 36 | + $field = json_decode( $field ); | |
| 37 | + if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) { | |
| 38 | + // this field may have already been loaded | |
| 46 | 39 | continue; |
| 47 | 40 | } |
| 48 | 41 | |
| 49 | - $field = $fields[ $field_id ]; | |
| 42 | + if ( ! isset( $field->value ) ) { | |
| 43 | + $field->value = ''; | |
| 44 | + } | |
| 45 | + $field->field_options = json_decode( json_encode( $field->field_options ), true ); | |
| 46 | + $field->options = json_decode( json_encode( $field->options ), true ); | |
| 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 ); |
| 51 | + $field_html[ absint( $field->id ) ] = ob_get_contents(); | |
| 52 | + ob_end_clean(); | |
| 53 | + } | |
| 53 | 54 | |
| 54 | - $field_html[ $field_id ] = array( | |
| 55 | - // The type travels with the html so the js can report it to frm_ajax_loaded_field | |
| 56 | - // listeners without a copy of the field. | |
| 57 | - 'type' => $field->type, | |
| 58 | - 'html' => ob_get_clean(), | |
| 59 | - ); | |
| 60 | - }//end foreach | |
| 61 | - | |
| 62 | 55 | echo json_encode( $field_html ); |
| 63 | 56 | |
| 64 | 57 | wp_die(); |
| 65 | 58 | } |
| @@ -64,40 +57,8 @@ | ||
| 64 | 57 | wp_die(); |
| 65 | 58 | } |
| 66 | 59 | |
| 67 | 60 | /** |
| 68 | - * Get a form's fields, as the form builder sees them, indexed by field id. | |
| 69 | - * | |
| 70 | - * @since 6.35 | |
| 71 | - * | |
| 72 | - * @param int $form_id | |
| 73 | - * | |
| 74 | - * @return array Field objects keyed by field id. Empty if the form is gone. | |
| 75 | - */ | |
| 76 | - private static function get_builder_fields_by_id( $form_id ) { | |
| 77 | - $form = FrmForm::getOne( $form_id ); | |
| 78 | - | |
| 79 | - if ( ! $form ) { | |
| 80 | - return array(); | |
| 81 | - } | |
| 82 | - | |
| 83 | - $fields = FrmField::get_all_for_form( $form_id ); | |
| 84 | - | |
| 85 | - /** This filter is documented in classes/controllers/FrmFormsController.php */ | |
| 86 | - $fields = apply_filters( 'frm_fields_in_form_builder', $fields, compact( 'form' ) ); | |
| 87 | - | |
| 88 | - $fields_by_id = array(); | |
| 89 | - | |
| 90 | - foreach ( (array) $fields as $field ) { | |
| 91 | - if ( is_object( $field ) && ! empty( $field->id ) ) { | |
| 92 | - $fields_by_id[ (int) $field->id ] = $field; | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - return $fields_by_id; | |
| 97 | - } | |
| 98 | - | |
| 99 | - /** | |
| 100 | 61 | * Create a new field with ajax |
| 101 | 62 | */ |
| 102 | 63 | public static function create() { |
| 103 | 64 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| @@ -110,9 +71,9 @@ | ||
| 110 | 71 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 111 | 72 | |
| 112 | 73 | $field = self::include_new_field( $field_type, $form_id, $field_options ); |
| 113 | 74 | |
| 114 | - // This hook will allow for multiple fields to be added at once | |
| 75 | + // this hook will allow for multiple fields to be added at once | |
| 115 | 76 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 116 | 77 | |
| 117 | 78 | wp_die(); |
| 118 | 79 | } |
| @@ -128,9 +89,9 @@ | ||
| 128 | 89 | */ |
| 129 | 90 | public static function include_new_field( $field_type, $form_id, $field_options = array() ) { |
| 130 | 91 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 131 | 92 | |
| 132 | - if ( $field_options ) { | |
| 93 | + if ( ! empty( $field_options ) ) { | |
| 133 | 94 | $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); |
| 134 | 95 | } |
| 135 | 96 | |
| 136 | 97 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| @@ -145,15 +106,15 @@ | ||
| 145 | 106 | if ( ! $field_id ) { |
| 146 | 107 | return false; |
| 147 | 108 | } |
| 148 | 109 | |
| 149 | - $field = self::get_field_array_from_id( $field_id ); | |
| 110 | + $field = self::get_field_array_from_id( $field_id ); | |
| 111 | + | |
| 150 | 112 | $values = array(); |
| 151 | - | |
| 152 | 113 | if ( FrmAppHelper::pro_is_installed() ) { |
| 153 | 114 | $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
| 154 | - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 155 | 115 | |
| 116 | + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 156 | 117 | if ( $parent_form_id ) { |
| 157 | 118 | $field['parent_form_id'] = $parent_form_id; |
| 158 | 119 | } |
| 159 | 120 | } |
| @@ -166,14 +127,15 @@ | ||
| 166 | 127 | public static function duplicate() { |
| 167 | 128 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 168 | 129 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 169 | 130 | |
| 170 | - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 171 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 131 | + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 132 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 133 | + | |
| 172 | 134 | $new_field = FrmField::duplicate_single_field( $field_id, $form_id ); |
| 173 | 135 | |
| 174 | 136 | if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) { |
| 175 | - self::load_single_field( $new_field['field_id'], $new_field['values'], $form_id ); | |
| 137 | + self::load_single_field( $new_field['field_id'], $new_field['values'] ); | |
| 176 | 138 | } |
| 177 | 139 | |
| 178 | 140 | wp_die(); |
| 179 | 141 | } |
| @@ -186,8 +148,9 @@ | ||
| 186 | 148 | * @return array |
| 187 | 149 | */ |
| 188 | 150 | public static function get_field_array_from_id( $field_id ) { |
| 189 | 151 | $field = FrmField::getOne( $field_id ); |
| 152 | + | |
| 190 | 153 | return FrmFieldsHelper::setup_edit_vars( $field ); |
| 191 | 154 | } |
| 192 | 155 | |
| 193 | 156 | /** |
| @@ -192,13 +155,11 @@ | ||
| 192 | 155 | |
| 193 | 156 | /** |
| 194 | 157 | * @since 3.0 |
| 195 | 158 | * |
| 196 | - * @param array|int|object|string $field_object | |
| 197 | - * @param array $values | |
| 198 | - * @param int $form_id | |
| 199 | - * | |
| 200 | - * @return void | |
| 159 | + * @param array|int|object $field_object | |
| 160 | + * @param array $values | |
| 161 | + * @param int $form_id | |
| 201 | 162 | */ |
| 202 | 163 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 203 | 164 | global $frm_vars; |
| 204 | 165 | $frm_vars['is_admin'] = true; |
| @@ -209,10 +170,11 @@ | ||
| 209 | 170 | $field = $field_object; |
| 210 | 171 | $field_object = FrmField::getOne( $field['id'] ); |
| 211 | 172 | } |
| 212 | 173 | |
| 213 | - $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 214 | - $display = self::display_field_options( array(), $field_obj ); | |
| 174 | + $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 175 | + $display = self::display_field_options( array(), $field_obj ); | |
| 176 | + | |
| 215 | 177 | $ajax_loading = ! empty( $values['ajax_load'] ); |
| 216 | 178 | $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true ); |
| 217 | 179 | |
| 218 | 180 | if ( $ajax_loading && $ajax_this_field ) { |
| @@ -221,12 +183,9 @@ | ||
| 221 | 183 | return; |
| 222 | 184 | } |
| 223 | 185 | |
| 224 | 186 | if ( ! isset( $field ) && is_object( $field_object ) ) { |
| 225 | - // Prefer the explicit form id. $values['id'] is not always a form id (for example when | |
| 226 | - // duplicating a field it is the copied field's id), so trusting it would set parent_form_id | |
| 227 | - // to a field id and break settings that resolve fields against the parent form. | |
| 228 | - $field_object->parent_form_id = $form_id ? $form_id : ( $values['id'] ?? $field_object->form_id ); | |
| 187 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 229 | 188 | $field = FrmFieldsHelper::setup_edit_vars( $field_object ); |
| 230 | 189 | } |
| 231 | 190 | |
| 232 | 191 | /** |
| @@ -251,9 +210,8 @@ | ||
| 251 | 210 | * |
| 252 | 211 | * @param array $field |
| 253 | 212 | * @param array $display |
| 254 | 213 | * @param FrmFieldType $field_info |
| 255 | - * | |
| 256 | 214 | * @return string |
| 257 | 215 | */ |
| 258 | 216 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 259 | 217 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| @@ -258,14 +216,8 @@ | ||
| 258 | 216 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 259 | 217 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| 260 | 218 | $li_classes .= ' frm_form_field frmstart '; |
| 261 | 219 | |
| 262 | - $style_align_class = self::get_builder_field_style_align_class( $field, $field_info ); | |
| 263 | - | |
| 264 | - if ( $style_align_class ) { | |
| 265 | - $li_classes .= $style_align_class . ' '; | |
| 266 | - } | |
| 267 | - | |
| 268 | 220 | if ( isset( $field['classes'] ) ) { |
| 269 | 221 | $li_classes .= trim( $field['classes'] ) . ' '; |
| 270 | 222 | } |
| 271 | 223 | |
| @@ -271,45 +223,14 @@ | ||
| 271 | 223 | |
| 272 | 224 | $li_classes .= 'frmend'; |
| 273 | 225 | |
| 274 | 226 | if ( $field ) { |
| 275 | - return apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 227 | + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 276 | 228 | } |
| 277 | 229 | |
| 278 | 230 | return $li_classes; |
| 279 | 231 | } |
| 280 | 232 | |
| 281 | - /** | |
| 282 | - * Apply the active style alignment to a radio or checkbox builder preview on load. | |
| 283 | - * | |
| 284 | - * The per-field alignment setting only exists in Pro, so on load the style setting is | |
| 285 | - * used. When the field has an explicit alignment (Pro), the frm_build_field_class filter | |
| 286 | - * applies it instead. When Pro is not installed, any saved alignment is treated as empty. | |
| 287 | - * | |
| 288 | - * @since 6.32 | |
| 289 | - * | |
| 290 | - * @param array $field | |
| 291 | - * @param FrmFieldType $field_info | |
| 292 | - * | |
| 293 | - * @return string | |
| 294 | - */ | |
| 295 | - private static function get_builder_field_style_align_class( $field, $field_info ) { | |
| 296 | - if ( ! $field || ! is_array( $field ) || ( ! FrmField::is_radio( $field ) && ! FrmField::is_checkbox( $field ) ) ) { | |
| 297 | - return ''; | |
| 298 | - } | |
| 299 | - | |
| 300 | - $align = FrmAppHelper::pro_is_installed() ? FrmField::get_option( $field, 'align' ) : ''; | |
| 301 | - | |
| 302 | - if ( $align ) { | |
| 303 | - return ''; | |
| 304 | - } | |
| 305 | - | |
| 306 | - $align = FrmStylesHelper::get_align_from_active_style( $field ); | |
| 307 | - $field_info->prepare_align_class( $align ); | |
| 308 | - | |
| 309 | - return $align; | |
| 310 | - } | |
| 311 | - | |
| 312 | 233 | public static function destroy() { |
| 313 | 234 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 314 | 235 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 315 | 236 | |
| @@ -338,9 +259,8 @@ | ||
| 338 | 259 | * |
| 339 | 260 | * @since 6.8.4 |
| 340 | 261 | * |
| 341 | 262 | * @param array $bulk_edit_types |
| 342 | - * | |
| 343 | 263 | * @return array |
| 344 | 264 | */ |
| 345 | 265 | $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); |
| 346 | 266 | |
| @@ -348,19 +268,18 @@ | ||
| 348 | 268 | return; |
| 349 | 269 | } |
| 350 | 270 | |
| 351 | 271 | $field = FrmFieldsHelper::setup_edit_vars( $field ); |
| 272 | + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 273 | + $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 274 | + $opts = array_map( 'trim', $opts ); | |
| 352 | 275 | |
| 353 | - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 354 | - $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 355 | - $opts = array_map( 'trim', $opts ); | |
| 356 | - | |
| 357 | 276 | $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); |
| 358 | 277 | $field['separate_value'] = $separate === 'true'; |
| 359 | 278 | |
| 360 | 279 | if ( $field['separate_value'] ) { |
| 361 | 280 | foreach ( $opts as $opt_key => $opt ) { |
| 362 | - if ( str_contains( $opt, '|' ) ) { | |
| 281 | + if ( strpos( $opt, '|' ) !== false ) { | |
| 363 | 282 | $vals = explode( '|', $opt ); |
| 364 | 283 | $opts[ $opt_key ] = array( |
| 365 | 284 | 'label' => trim( $vals[0] ), |
| 366 | 285 | 'value' => trim( $vals[1] ), |
| @@ -371,11 +290,10 @@ | ||
| 371 | 290 | } |
| 372 | 291 | } |
| 373 | 292 | |
| 374 | 293 | // Keep other options after bulk update. |
| 375 | - if ( ! empty( $field['field_options']['other'] ) ) { | |
| 294 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { | |
| 376 | 295 | $other_array = array(); |
| 377 | - | |
| 378 | 296 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 379 | 297 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 380 | 298 | $other_array[ $opt_key ] = $opt; |
| 381 | 299 | } |
| @@ -380,10 +298,9 @@ | ||
| 380 | 298 | $other_array[ $opt_key ] = $opt; |
| 381 | 299 | } |
| 382 | 300 | unset( $opt_key, $opt ); |
| 383 | 301 | } |
| 384 | - | |
| 385 | - if ( $other_array ) { | |
| 302 | + if ( ! empty( $other_array ) ) { | |
| 386 | 303 | $opts = array_merge( $opts, $other_array ); |
| 387 | 304 | } |
| 388 | 305 | } |
| 389 | 306 | |
| @@ -397,9 +314,8 @@ | ||
| 397 | 314 | /** |
| 398 | 315 | * @since 4.0 |
| 399 | 316 | * |
| 400 | 317 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 401 | - * | |
| 402 | 318 | * @return void |
| 403 | 319 | */ |
| 404 | 320 | public static function load_single_field_settings( $atts ) { |
| 405 | 321 | $field = $atts['field']; |
| @@ -425,9 +341,9 @@ | ||
| 425 | 341 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 426 | 342 | // Add fallback for an add-on field type that has been deactivated. |
| 427 | 343 | $all_field_types[ $field['type'] ] = array( |
| 428 | 344 | 'name' => ucfirst( $field['type'] ), |
| 429 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 345 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 430 | 346 | ); |
| 431 | 347 | } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) { |
| 432 | 348 | // Fallback for fields added in a more basic way. |
| 433 | 349 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| @@ -433,9 +349,8 @@ | ||
| 433 | 349 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 434 | 350 | } |
| 435 | 351 | |
| 436 | 352 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 437 | - | |
| 438 | 353 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 439 | 354 | $type_name = $all_field_types['divider|repeat']['name']; |
| 440 | 355 | } |
| 441 | 356 | |
| @@ -446,79 +361,8 @@ | ||
| 446 | 361 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 447 | 362 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 448 | 363 | } |
| 449 | 364 | |
| 450 | - $pro_is_installed = FrmAppHelper::pro_is_installed(); | |
| 451 | - | |
| 452 | - $unique_values_label_atts = array( | |
| 453 | - 'for' => 'frm_uniq_field_' . $field['id'], | |
| 454 | - 'class' => 'frm_help frm-mb-0', | |
| 455 | - 'title' => __( | |
| 456 | - 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.', | |
| 457 | - 'formidable' | |
| 458 | - ), | |
| 459 | - 'data-trigger' => 'hover', | |
| 460 | - ); | |
| 461 | - | |
| 462 | - $read_only_label_atts = array( | |
| 463 | - 'for' => 'frm_read_only_field_' . $field['id'], | |
| 464 | - 'class' => 'frm_help frm-mb-0', | |
| 465 | - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ), | |
| 466 | - 'data-trigger' => 'hover', | |
| 467 | - ); | |
| 468 | - | |
| 469 | - if ( ! $pro_is_installed ) { | |
| 470 | - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 471 | - array( | |
| 472 | - 'id' => 'field_options_admin_only_' . $field['id'], | |
| 473 | - 'readonly' => '1', | |
| 474 | - ), | |
| 475 | - 'field_visibility', | |
| 476 | - __( 'Visibility options', 'formidable' ), | |
| 477 | - '/field-options/#kb-visibility' | |
| 478 | - ); | |
| 479 | - | |
| 480 | - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 481 | - array( 'id' => 'field_options_autocomplete_' . $field['id'] ), | |
| 482 | - 'autocomplete', | |
| 483 | - __( 'Autocomplete options', 'formidable' ), | |
| 484 | - '/email-address/#kb-autocomplete-attribute' | |
| 485 | - ); | |
| 486 | - | |
| 487 | - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 488 | - array( | |
| 489 | - 'type' => 'text', | |
| 490 | - 'readonly' => '1', | |
| 491 | - ), | |
| 492 | - 'before_after_contents', | |
| 493 | - __( 'Before and after field contents', 'formidable' ), | |
| 494 | - '/field-options/#kb-before-after-input' | |
| 495 | - ); | |
| 496 | - | |
| 497 | - $show_upsell_for_unique_value = in_array( | |
| 498 | - $field['type'], | |
| 499 | - array( 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), | |
| 500 | - true | |
| 501 | - ); | |
| 502 | - $show_upsell_for_read_only = in_array( $field['type'], array( 'address', 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true ); | |
| 503 | - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true ); | |
| 504 | - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true ); | |
| 505 | - $show_upsell_for_visibility = $field['type'] !== 'hidden'; | |
| 506 | - | |
| 507 | - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 508 | - $unique_values_label_atts, | |
| 509 | - 'unique_values', | |
| 510 | - __( 'Unique Values', 'formidable' ), | |
| 511 | - '/field-options/#kb-unique' | |
| 512 | - ); | |
| 513 | - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 514 | - $read_only_label_atts, | |
| 515 | - 'read_only', | |
| 516 | - __( 'Read Only Values', 'formidable' ), | |
| 517 | - '/field-options/#kb-read-only' | |
| 518 | - ); | |
| 519 | - }//end if | |
| 520 | - | |
| 521 | 365 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; |
| 522 | 366 | } |
| 523 | 367 | |
| 524 | 368 | /** |
| @@ -539,9 +383,8 @@ | ||
| 539 | 383 | * @since 4.0 |
| 540 | 384 | * |
| 541 | 385 | * @param array $field |
| 542 | 386 | * @param array $atts |
| 543 | - * | |
| 544 | 387 | * @return array |
| 545 | 388 | */ |
| 546 | 389 | private static function default_value_types( $field, $atts ) { |
| 547 | 390 | $types = array( |
| @@ -546,9 +389,9 @@ | ||
| 546 | 389 | private static function default_value_types( $field, $atts ) { |
| 547 | 390 | $types = array( |
| 548 | 391 | 'default_value' => array( |
| 549 | 392 | 'class' => '', |
| 550 | - 'icon' => 'frmfont frm_text2_icon', | |
| 393 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 551 | 394 | 'title' => __( 'Default Value', 'formidable' ), |
| 552 | 395 | 'data' => array( |
| 553 | 396 | 'frmshow' => '#default-value-for-', |
| 554 | 397 | ), |
| @@ -555,9 +398,9 @@ | ||
| 555 | 398 | ), |
| 556 | 399 | 'calc' => array( |
| 557 | 400 | 'class' => 'frm_show_upgrade frm_noallow', |
| 558 | 401 | 'title' => __( 'Calculate Value', 'formidable' ), |
| 559 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 402 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 560 | 403 | 'data' => array( |
| 561 | 404 | 'medium' => 'calculations', |
| 562 | 405 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 563 | 406 | ), |
| @@ -565,9 +408,9 @@ | ||
| 565 | 408 | ), |
| 566 | 409 | 'get_values_field' => array( |
| 567 | 410 | 'class' => 'frm_show_upgrade frm_noallow', |
| 568 | 411 | 'title' => __( 'Lookup', 'formidable' ), |
| 569 | - 'icon' => 'frmfont frm_search_icon', | |
| 412 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 570 | 413 | 'data' => array( |
| 571 | 414 | 'medium' => 'lookup', |
| 572 | 415 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 573 | 416 | ), |
| @@ -596,9 +439,8 @@ | ||
| 596 | 439 | } |
| 597 | 440 | |
| 598 | 441 | /** |
| 599 | 442 | * @param string $type |
| 600 | - * | |
| 601 | 443 | * @return string |
| 602 | 444 | */ |
| 603 | 445 | public static function change_type( $type ) { |
| 604 | 446 | $type_switch = array( |
| @@ -608,9 +450,8 @@ | ||
| 608 | 450 | 'rte' => 'textarea', |
| 609 | 451 | 'website' => 'url', |
| 610 | 452 | 'image' => 'url', |
| 611 | 453 | ); |
| 612 | - | |
| 613 | 454 | if ( isset( $type_switch[ $type ] ) ) { |
| 614 | 455 | $type = $type_switch[ $type ]; |
| 615 | 456 | } |
| 616 | 457 | |
| @@ -616,11 +457,15 @@ | ||
| 616 | 457 | |
| 617 | 458 | $pro_fields = FrmField::pro_field_selection(); |
| 618 | 459 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 619 | 460 | // The credit_card key is set for backward compatibility. |
| 620 | - FrmField::remove_moved_field_types_from_pro( $pro_fields ); | |
| 461 | + unset( $pro_fields['credit_card'] ); | |
| 621 | 462 | |
| 622 | - return array_key_exists( $type, $pro_fields ) ? 'text' : $type; | |
| 463 | + if ( array_key_exists( $type, $pro_fields ) ) { | |
| 464 | + $type = 'text'; | |
| 465 | + } | |
| 466 | + | |
| 467 | + return $type; | |
| 623 | 468 | } |
| 624 | 469 | |
| 625 | 470 | /** |
| 626 | 471 | * @param array $settings |
| @@ -645,9 +490,8 @@ | ||
| 645 | 490 | * @since 3.0 |
| 646 | 491 | * |
| 647 | 492 | * @param array $field Field data. |
| 648 | 493 | * @param bool $is_hidden Whether the format option should be hidden. |
| 649 | - * | |
| 650 | 494 | * @return void |
| 651 | 495 | */ |
| 652 | 496 | public static function show_format_option( $field, $is_hidden = false ) { |
| 653 | 497 | $attributes = array( |
| @@ -661,14 +505,8 @@ | ||
| 661 | 505 | |
| 662 | 506 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 663 | 507 | } |
| 664 | 508 | |
| 665 | - /** | |
| 666 | - * @param array $field | |
| 667 | - * @param bool $echo | |
| 668 | - * | |
| 669 | - * @return string | |
| 670 | - */ | |
| 671 | 509 | public static function input_html( $field, $echo = true ) { |
| 672 | 510 | $class = array(); |
| 673 | 511 | self::add_input_classes( $field, $class ); |
| 674 | 512 | |
| @@ -683,9 +521,8 @@ | ||
| 683 | 521 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
| 684 | 522 | |
| 685 | 523 | self::add_shortcodes_to_html( $field, $add_html ); |
| 686 | 524 | self::add_pattern_attribute( $field, $add_html ); |
| 687 | - self::add_currency_field_attributes( $field, $add_html ); | |
| 688 | 525 | |
| 689 | 526 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
| 690 | 527 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
| 691 | 528 | |
| @@ -698,9 +535,8 @@ | ||
| 698 | 535 | |
| 699 | 536 | /** |
| 700 | 537 | * @param array $field |
| 701 | 538 | * @param array $class |
| 702 | - * | |
| 703 | 539 | * @return void |
| 704 | 540 | */ |
| 705 | 541 | private static function add_input_classes( $field, array &$class ) { |
| 706 | 542 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -718,9 +554,8 @@ | ||
| 718 | 554 | |
| 719 | 555 | /** |
| 720 | 556 | * @param array $field |
| 721 | 557 | * @param array $add_html |
| 722 | - * | |
| 723 | 558 | * @return void |
| 724 | 559 | */ |
| 725 | 560 | private static function add_html_size( $field, array &$add_html ) { |
| 726 | 561 | $size_fields = array( |
| @@ -753,9 +588,8 @@ | ||
| 753 | 588 | |
| 754 | 589 | /** |
| 755 | 590 | * @param array $field |
| 756 | 591 | * @param array $add_html |
| 757 | - * | |
| 758 | 592 | * @return void |
| 759 | 593 | */ |
| 760 | 594 | private static function add_html_cols( $field, array &$add_html ) { |
| 761 | 595 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -769,9 +603,9 @@ | ||
| 769 | 603 | 'rem' => 0.444, |
| 770 | 604 | 'em' => 0.544, |
| 771 | 605 | ); |
| 772 | 606 | |
| 773 | - // Include "col" for valid html | |
| 607 | + // include "col" for valid html | |
| 774 | 608 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 775 | 609 | |
| 776 | 610 | if ( ! isset( $calc[ $unit ] ) ) { |
| 777 | 611 | return; |
| @@ -776,9 +610,10 @@ | ||
| 776 | 610 | if ( ! isset( $calc[ $unit ] ) ) { |
| 777 | 611 | return; |
| 778 | 612 | } |
| 779 | 613 | |
| 780 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 614 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 615 | + | |
| 781 | 616 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 782 | 617 | } |
| 783 | 618 | |
| 784 | 619 | /** |
| @@ -783,9 +618,8 @@ | ||
| 783 | 618 | |
| 784 | 619 | /** |
| 785 | 620 | * @param array $field |
| 786 | 621 | * @param array $add_html |
| 787 | - * | |
| 788 | 622 | * @return void |
| 789 | 623 | */ |
| 790 | 624 | private static function add_html_length( $field, array &$add_html ) { |
| 791 | 625 | // Check for max setting and if this field accepts maxlength. |
| @@ -811,13 +645,11 @@ | ||
| 811 | 645 | /** |
| 812 | 646 | * @param array $field |
| 813 | 647 | * @param array $add_html |
| 814 | 648 | * @param array $class |
| 815 | - * | |
| 816 | 649 | * @return void |
| 817 | 650 | */ |
| 818 | 651 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 819 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 820 | 652 | if ( $field['default_value'] != '' ) { |
| 821 | 653 | if ( is_array( $field['default_value'] ) ) { |
| 822 | 654 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 823 | 655 | } else { |
| @@ -825,12 +657,10 @@ | ||
| 825 | 657 | } |
| 826 | 658 | } |
| 827 | 659 | |
| 828 | 660 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 829 | - | |
| 830 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 831 | 661 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 832 | - // Don't include a json placeholder | |
| 662 | + // don't include a json placeholder | |
| 833 | 663 | return; |
| 834 | 664 | } |
| 835 | 665 | |
| 836 | 666 | self::add_placeholder_to_input( $field, $add_html ); |
| @@ -841,13 +671,14 @@ | ||
| 841 | 671 | * |
| 842 | 672 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 843 | 673 | * |
| 844 | 674 | * @param array $field Field array. |
| 845 | - * | |
| 846 | 675 | * @return string |
| 847 | 676 | */ |
| 848 | 677 | private static function prepare_placeholder( $field ) { |
| 849 | - return $field['placeholder'] ?? ''; | |
| 678 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 679 | + | |
| 680 | + return $placeholder; | |
| 850 | 681 | } |
| 851 | 682 | |
| 852 | 683 | /** |
| 853 | 684 | * If the label position is "inside", |
| @@ -868,17 +699,13 @@ | ||
| 868 | 699 | * Maybe add a blank placeholder option before any options |
| 869 | 700 | * in a dropdown. |
| 870 | 701 | * |
| 871 | 702 | * @since 4.04 |
| 872 | - * | |
| 873 | - * @param array|object $field | |
| 874 | - * | |
| 875 | 703 | * @return bool True if placeholder was added. |
| 876 | 704 | */ |
| 877 | 705 | public static function add_placeholder_to_select( $field ) { |
| 878 | 706 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 879 | - | |
| 880 | - if ( ! $placeholder ) { | |
| 707 | + if ( empty( $placeholder ) ) { | |
| 881 | 708 | $placeholder = self::get_default_value_from_name( $field ); |
| 882 | 709 | } |
| 883 | 710 | |
| 884 | 711 | $use_placeholder = $placeholder; |
| @@ -885,9 +712,8 @@ | ||
| 885 | 712 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 886 | 713 | |
| 887 | 714 | if ( $autocomplete ) { |
| 888 | 715 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 889 | - | |
| 890 | 716 | if ( $use_chosen ) { |
| 891 | 717 | $use_placeholder = ''; |
| 892 | 718 | } |
| 893 | 719 | } |
| @@ -910,9 +736,8 @@ | ||
| 910 | 736 | * Use HTML5 placeholder with js fallback. |
| 911 | 737 | * |
| 912 | 738 | * @param array $field |
| 913 | 739 | * @param array $add_html |
| 914 | - * | |
| 915 | 740 | * @return void |
| 916 | 741 | */ |
| 917 | 742 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 918 | 743 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -922,13 +747,11 @@ | ||
| 922 | 747 | |
| 923 | 748 | /** |
| 924 | 749 | * @param array $field |
| 925 | 750 | * @param array $add_html |
| 926 | - * | |
| 927 | 751 | * @return void |
| 928 | 752 | */ |
| 929 | 753 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 930 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 931 | 754 | if ( $field['placeholder'] != '' ) { |
| 932 | 755 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 933 | 756 | |
| 934 | 757 | if ( 'select' === $field['type'] ) { |
| @@ -935,20 +758,13 @@ | ||
| 935 | 758 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 936 | 759 | } |
| 937 | 760 | } |
| 938 | 761 | |
| 939 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 940 | 762 | if ( $field['default_value'] != '' ) { |
| 941 | 763 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 942 | 764 | } |
| 943 | 765 | } |
| 944 | 766 | |
| 945 | - /** | |
| 946 | - * @param array $field | |
| 947 | - * @param array $add_html | |
| 948 | - * | |
| 949 | - * @return void | |
| 950 | - */ | |
| 951 | 767 | private static function add_validation_messages( $field, array &$add_html ) { |
| 952 | 768 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 953 | 769 | |
| 954 | 770 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -972,9 +788,8 @@ | ||
| 972 | 788 | * |
| 973 | 789 | * @since 6.9 |
| 974 | 790 | * |
| 975 | 791 | * @param array|object $field |
| 976 | - * | |
| 977 | 792 | * @return array |
| 978 | 793 | */ |
| 979 | 794 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 980 | 795 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -1004,26 +819,21 @@ | ||
| 1004 | 819 | * @since 5.0.03 |
| 1005 | 820 | * |
| 1006 | 821 | * @param array $field |
| 1007 | 822 | * @param array $add_html |
| 1008 | - * | |
| 1009 | 823 | * @return void |
| 1010 | 824 | */ |
| 1011 | 825 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 1012 | 826 | $form = self::get_form_for_js_validation( $field ); |
| 1013 | - | |
| 1014 | 827 | if ( false === $form ) { |
| 1015 | 828 | return; |
| 1016 | 829 | } |
| 1017 | 830 | |
| 1018 | 831 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 1019 | - | |
| 1020 | - if ( false === $error_body ) { | |
| 1021 | - return; | |
| 832 | + if ( false !== $error_body ) { | |
| 833 | + $error_body = urlencode( $error_body ); | |
| 834 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 1022 | 835 | } |
| 1023 | - | |
| 1024 | - $error_body = urlencode( $error_body ); | |
| 1025 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 1026 | 836 | } |
| 1027 | 837 | |
| 1028 | 838 | /** |
| 1029 | 839 | * @since 5.0.03 |
| @@ -1028,24 +838,20 @@ | ||
| 1028 | 838 | /** |
| 1029 | 839 | * @since 5.0.03 |
| 1030 | 840 | * |
| 1031 | 841 | * @param array $field |
| 1032 | - * | |
| 1033 | 842 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 1034 | 843 | */ |
| 1035 | 844 | private static function get_form_for_js_validation( $field ) { |
| 1036 | 845 | global $frm_vars; |
| 1037 | - | |
| 1038 | 846 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 1039 | 847 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 1040 | 848 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 1041 | 849 | } |
| 1042 | - | |
| 1043 | 850 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 1044 | 851 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 1045 | 852 | } |
| 1046 | 853 | } |
| 1047 | - | |
| 1048 | 854 | return false; |
| 1049 | 855 | } |
| 1050 | 856 | |
| 1051 | 857 | /** |
| @@ -1051,9 +857,8 @@ | ||
| 1051 | 857 | /** |
| 1052 | 858 | * @param stdClass $form |
| 1053 | 859 | * @param array $field |
| 1054 | 860 | * @param array $errors |
| 1055 | - * | |
| 1056 | 861 | * @return false|string |
| 1057 | 862 | */ |
| 1058 | 863 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 1059 | 864 | if ( empty( $field['custom_html'] ) ) { |
| @@ -1061,16 +866,15 @@ | ||
| 1061 | 866 | } |
| 1062 | 867 | |
| 1063 | 868 | $custom_html = $field['custom_html']; |
| 1064 | 869 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 1065 | - $start = strpos( $custom_html, '[if error]' ); | |
| 1066 | 870 | |
| 871 | + $start = strpos( $custom_html, '[if error]' ); | |
| 1067 | 872 | if ( false === $start ) { |
| 1068 | 873 | return false; |
| 1069 | 874 | } |
| 1070 | 875 | |
| 1071 | 876 | $end = strpos( $custom_html, '[/if error]' ); |
| 1072 | - | |
| 1073 | 877 | if ( false === $end || $end < $start ) { |
| 1074 | 878 | return false; |
| 1075 | 879 | } |
| 1076 | 880 | |
| @@ -1081,9 +885,13 @@ | ||
| 1081 | 885 | '<div class="frm_error">[error]</div>', |
| 1082 | 886 | '<div class="frm_error" role="alert">[error]</div>', |
| 1083 | 887 | ); |
| 1084 | 888 | |
| 1085 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 889 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 890 | + return false; | |
| 891 | + } | |
| 892 | + | |
| 893 | + return $error_body; | |
| 1086 | 894 | } |
| 1087 | 895 | |
| 1088 | 896 | /** |
| 1089 | 897 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -1090,16 +898,13 @@ | ||
| 1090 | 898 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 1091 | 899 | * remove it is present if needed. |
| 1092 | 900 | * |
| 1093 | 901 | * @since 3.06.01 |
| 1094 | - * | |
| 1095 | 902 | * @param array $field |
| 1096 | 903 | * @param array $add_html |
| 1097 | - * | |
| 1098 | 904 | * @return void |
| 1099 | 905 | */ |
| 1100 | 906 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 1101 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1102 | 907 | $excluded_field_types = |
| 1103 | 908 | FrmField::is_radio( $field ) || |
| 1104 | 909 | FrmField::is_checkbox( $field ) || |
| 1105 | 910 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -1104,9 +909,8 @@ | ||
| 1104 | 909 | FrmField::is_checkbox( $field ) || |
| 1105 | 910 | FrmField::is_field_type( $field, 'file' ) || |
| 1106 | 911 | FrmField::is_field_type( $field, 'nps' ) || |
| 1107 | 912 | FrmField::is_field_type( $field, 'scale' ); |
| 1108 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1109 | 913 | |
| 1110 | 914 | if ( $excluded_field_types ) { |
| 1111 | 915 | return; |
| 1112 | 916 | } |
| @@ -1116,9 +920,8 @@ | ||
| 1116 | 920 | |
| 1117 | 921 | /** |
| 1118 | 922 | * @param array $field |
| 1119 | 923 | * @param array $add_html |
| 1120 | - * | |
| 1121 | 924 | * @return void |
| 1122 | 925 | */ |
| 1123 | 926 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 1124 | 927 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -1129,11 +932,10 @@ | ||
| 1129 | 932 | unset( $field['shortcodes']['autocomplete'] ); |
| 1130 | 933 | } |
| 1131 | 934 | |
| 1132 | 935 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 1133 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 936 | + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) { | |
| 1134 | 937 | $subfield_name = $field['subfield_name']; |
| 1135 | - | |
| 1136 | 938 | if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { |
| 1137 | 939 | continue; |
| 1138 | 940 | } |
| 1139 | 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. |
| @@ -1140,14 +942,13 @@ | ||
| 1140 | 942 | $k = 'aria-invalid'; |
| 1141 | 943 | $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; |
| 1142 | 944 | unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); |
| 1143 | 945 | } |
| 1144 | - | |
| 1145 | 946 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 1146 | 947 | continue; |
| 1147 | 948 | } |
| 1148 | 949 | |
| 1149 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 950 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1150 | 951 | $add_html[] = $v; |
| 1151 | 952 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1152 | 953 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1153 | 954 | } else { |
| @@ -1163,9 +964,8 @@ | ||
| 1163 | 964 | * |
| 1164 | 965 | * @since 6.11.2 |
| 1165 | 966 | * |
| 1166 | 967 | * @param string $key The option key. |
| 1167 | - * | |
| 1168 | 968 | * @return bool |
| 1169 | 969 | */ |
| 1170 | 970 | private static function should_allow_input_attribute( $key ) { |
| 1171 | 971 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1180,9 +980,8 @@ | ||
| 1180 | 980 | * @since 3.0 |
| 1181 | 981 | * |
| 1182 | 982 | * @param array $field |
| 1183 | 983 | * @param array $add_html |
| 1184 | - * | |
| 1185 | 984 | * @return void |
| 1186 | 985 | */ |
| 1187 | 986 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1188 | 987 | $format_value = FrmField::get_option( $field, 'format' ); |
| @@ -1188,83 +987,22 @@ | ||
| 1188 | 987 | $format_value = FrmField::get_option( $field, 'format' ); |
| 1189 | 988 | $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); |
| 1190 | 989 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1191 | 990 | |
| 1192 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1193 | - return; | |
| 1194 | - } | |
| 991 | + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 992 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 993 | + $format = substr( $format, 2, - 1 ); | |
| 1195 | 994 | |
| 1196 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1197 | - $format = substr( $format, 2, - 1 ); | |
| 1198 | - | |
| 1199 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1200 | - } | |
| 1201 | - | |
| 1202 | - /** | |
| 1203 | - * Add product attributes to fields in multi-paged forms. | |
| 1204 | - * | |
| 1205 | - * @param array $field | |
| 1206 | - * @param array $add_html | |
| 1207 | - * | |
| 1208 | - * @return void | |
| 1209 | - */ | |
| 1210 | - private static function add_currency_field_attributes( $field, &$add_html ) { | |
| 1211 | - $type = $field['original_type'] ?? $field['type']; | |
| 1212 | - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true ); | |
| 1213 | - | |
| 1214 | - if ( ! $is_product_field ) { | |
| 1215 | - return; | |
| 995 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1216 | 996 | } |
| 1217 | - | |
| 1218 | - if ( $type === 'total' ) { | |
| 1219 | - $add_html['data-frmtotal'] = 'data-frmtotal'; | |
| 1220 | - } elseif ( $type === 'quantity' ) { | |
| 1221 | - $product_field = FrmField::get_option( $field, 'product_field' ); | |
| 1222 | - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"'; | |
| 1223 | - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) { | |
| 1224 | - // We want to do this only for fields that are hidden because it's | |
| 1225 | - // not their page, hence the check : 'hidden' === $field['type']. | |
| 1226 | - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field ); | |
| 1227 | - | |
| 1228 | - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"'; | |
| 1229 | - } | |
| 1230 | 997 | } |
| 1231 | 998 | |
| 1232 | - /** | |
| 1233 | - * @param array $field | |
| 1234 | - */ | |
| 1235 | - private static function get_product_price( $field ) { | |
| 1236 | - if ( is_array( $field['value'] ) ) { | |
| 1237 | - // '' is unlikely though, let's just do it to prevent warnings | |
| 1238 | - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] ) | |
| 1239 | - ? $field['value'][ $field['opt_key'] ] | |
| 1240 | - : ''; | |
| 1241 | - } else { | |
| 1242 | - $value = $field['value']; | |
| 1243 | - } | |
| 1244 | - | |
| 1245 | - $field_obj = FrmFieldFactory::get_field_object( $field['id'] ); | |
| 1246 | - | |
| 1247 | - if ( method_exists( $field_obj, 'get_posted_price' ) ) { | |
| 1248 | - return $field_obj->get_posted_price( $value ); | |
| 1249 | - } | |
| 1250 | - | |
| 1251 | - return $value; | |
| 1252 | - } | |
| 1253 | - | |
| 1254 | - /** | |
| 1255 | - * @param mixed $opt | |
| 1256 | - * @param mixed $opt_key | |
| 1257 | - * @param array|object $field | |
| 1258 | - * | |
| 1259 | - * @return mixed | |
| 1260 | - */ | |
| 1261 | 999 | public static function check_value( $opt, $opt_key, $field ) { |
| 1262 | 1000 | if ( is_array( $opt ) ) { |
| 1263 | 1001 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1264 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 1002 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1265 | 1003 | } else { |
| 1266 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 1004 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1267 | 1005 | } |
| 1268 | 1006 | } |
| 1269 | 1007 | |
| 1270 | 1008 | return $opt; |
| @@ -1269,13 +1007,12 @@ | ||
| 1269 | 1007 | |
| 1270 | 1008 | return $opt; |
| 1271 | 1009 | } |
| 1272 | 1010 | |
| 1273 | - /** | |
| 1274 | - * @param mixed $opt | |
| 1275 | - * | |
| 1276 | - * @return mixed | |
| 1277 | - */ | |
| 1278 | 1011 | public static function check_label( $opt ) { |
| 1279 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 1012 | + if ( is_array( $opt ) ) { | |
| 1013 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1014 | + } | |
| 1015 | + | |
| 1016 | + return $opt; | |
| 1280 | 1017 | } |
| 1281 | 1018 | } |