| @@ -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,14 +121,15 @@ | ||
| 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 | - self::load_single_field( $new_field['field_id'], $new_field['values'], $form_id ); | |
| 131 | + self::load_single_field( $new_field['field_id'], $new_field['values'] ); | |
| 138 | 132 | } |
| 139 | 133 | |
| 140 | 134 | wp_die(); |
| 141 | 135 | } |
| @@ -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,26 +177,12 @@ | ||
| 183 | 177 | return; |
| 184 | 178 | } |
| 185 | 179 | |
| 186 | 180 | if ( ! isset( $field ) && is_object( $field_object ) ) { |
| 187 | - // Prefer the explicit form id. $values['id'] is not always a form id (for example when | |
| 188 | - // duplicating a field it is the copied field's id), so trusting it would set parent_form_id | |
| 189 | - // to a field id and break settings that resolve fields against the parent form. | |
| 190 | - $field_object->parent_form_id = $form_id ? $form_id : ( $values['id'] ?? $field_object->form_id ); | |
| 181 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 191 | 182 | $field = FrmFieldsHelper::setup_edit_vars( $field_object ); |
| 192 | 183 | } |
| 193 | 184 | |
| 194 | - /** | |
| 195 | - * Filter for adding extra attributes to the field container. | |
| 196 | - * | |
| 197 | - * @since 6.23 | |
| 198 | - * | |
| 199 | - * @param array $extra_field_attributes | |
| 200 | - * @param array $field | |
| 201 | - * @param array $display | |
| 202 | - */ | |
| 203 | - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display ); | |
| 204 | - | |
| 205 | 185 | $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); |
| 206 | 186 | $li_classes .= ' ui-state-default widgets-holder-wrap'; |
| 207 | 187 | |
| 208 | 188 | require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; |
| @@ -213,9 +193,8 @@ | ||
| 213 | 193 | * |
| 214 | 194 | * @param array $field |
| 215 | 195 | * @param array $display |
| 216 | 196 | * @param FrmFieldType $field_info |
| 217 | - * | |
| 218 | 197 | * @return string |
| 219 | 198 | */ |
| 220 | 199 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 221 | 200 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| @@ -220,14 +199,8 @@ | ||
| 220 | 199 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 221 | 200 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| 222 | 201 | $li_classes .= ' frm_form_field frmstart '; |
| 223 | 202 | |
| 224 | - $style_align_class = self::get_builder_field_style_align_class( $field, $field_info ); | |
| 225 | - | |
| 226 | - if ( $style_align_class ) { | |
| 227 | - $li_classes .= $style_align_class . ' '; | |
| 228 | - } | |
| 229 | - | |
| 230 | 203 | if ( isset( $field['classes'] ) ) { |
| 231 | 204 | $li_classes .= trim( $field['classes'] ) . ' '; |
| 232 | 205 | } |
| 233 | 206 | |
| @@ -233,45 +206,14 @@ | ||
| 233 | 206 | |
| 234 | 207 | $li_classes .= 'frmend'; |
| 235 | 208 | |
| 236 | 209 | if ( $field ) { |
| 237 | - return apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 210 | + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 238 | 211 | } |
| 239 | 212 | |
| 240 | 213 | return $li_classes; |
| 241 | 214 | } |
| 242 | 215 | |
| 243 | - /** | |
| 244 | - * Apply the active style alignment to a radio or checkbox builder preview on load. | |
| 245 | - * | |
| 246 | - * The per-field alignment setting only exists in Pro, so on load the style setting is | |
| 247 | - * used. When the field has an explicit alignment (Pro), the frm_build_field_class filter | |
| 248 | - * applies it instead. When Pro is not installed, any saved alignment is treated as empty. | |
| 249 | - * | |
| 250 | - * @since 6.32 | |
| 251 | - * | |
| 252 | - * @param array $field | |
| 253 | - * @param FrmFieldType $field_info | |
| 254 | - * | |
| 255 | - * @return string | |
| 256 | - */ | |
| 257 | - private static function get_builder_field_style_align_class( $field, $field_info ) { | |
| 258 | - if ( ! $field || ! is_array( $field ) || ( ! FrmField::is_radio( $field ) && ! FrmField::is_checkbox( $field ) ) ) { | |
| 259 | - return ''; | |
| 260 | - } | |
| 261 | - | |
| 262 | - $align = FrmAppHelper::pro_is_installed() ? FrmField::get_option( $field, 'align' ) : ''; | |
| 263 | - | |
| 264 | - if ( $align ) { | |
| 265 | - return ''; | |
| 266 | - } | |
| 267 | - | |
| 268 | - $align = FrmStylesHelper::get_align_from_active_style( $field ); | |
| 269 | - $field_info->prepare_align_class( $align ); | |
| 270 | - | |
| 271 | - return $align; | |
| 272 | - } | |
| 273 | - | |
| 274 | 216 | public static function destroy() { |
| 275 | 217 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 276 | 218 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 277 | 219 | |
| @@ -300,9 +242,8 @@ | ||
| 300 | 242 | * |
| 301 | 243 | * @since 6.8.4 |
| 302 | 244 | * |
| 303 | 245 | * @param array $bulk_edit_types |
| 304 | - * | |
| 305 | 246 | * @return array |
| 306 | 247 | */ |
| 307 | 248 | $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); |
| 308 | 249 | |
| @@ -310,19 +251,18 @@ | ||
| 310 | 251 | return; |
| 311 | 252 | } |
| 312 | 253 | |
| 313 | 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 ); | |
| 314 | 258 | |
| 315 | - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 316 | - $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 317 | - $opts = array_map( 'trim', $opts ); | |
| 318 | - | |
| 319 | 259 | $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); |
| 320 | 260 | $field['separate_value'] = $separate === 'true'; |
| 321 | 261 | |
| 322 | 262 | if ( $field['separate_value'] ) { |
| 323 | 263 | foreach ( $opts as $opt_key => $opt ) { |
| 324 | - if ( str_contains( $opt, '|' ) ) { | |
| 264 | + if ( strpos( $opt, '|' ) !== false ) { | |
| 325 | 265 | $vals = explode( '|', $opt ); |
| 326 | 266 | $opts[ $opt_key ] = array( |
| 327 | 267 | 'label' => trim( $vals[0] ), |
| 328 | 268 | 'value' => trim( $vals[1] ), |
| @@ -333,11 +273,10 @@ | ||
| 333 | 273 | } |
| 334 | 274 | } |
| 335 | 275 | |
| 336 | 276 | // Keep other options after bulk update. |
| 337 | - if ( ! empty( $field['field_options']['other'] ) ) { | |
| 277 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { | |
| 338 | 278 | $other_array = array(); |
| 339 | - | |
| 340 | 279 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 341 | 280 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 342 | 281 | $other_array[ $opt_key ] = $opt; |
| 343 | 282 | } |
| @@ -342,10 +281,9 @@ | ||
| 342 | 281 | $other_array[ $opt_key ] = $opt; |
| 343 | 282 | } |
| 344 | 283 | unset( $opt_key, $opt ); |
| 345 | 284 | } |
| 346 | - | |
| 347 | - if ( $other_array ) { | |
| 285 | + if ( ! empty( $other_array ) ) { | |
| 348 | 286 | $opts = array_merge( $opts, $other_array ); |
| 349 | 287 | } |
| 350 | 288 | } |
| 351 | 289 | |
| @@ -359,9 +297,8 @@ | ||
| 359 | 297 | /** |
| 360 | 298 | * @since 4.0 |
| 361 | 299 | * |
| 362 | 300 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 363 | - * | |
| 364 | 301 | * @return void |
| 365 | 302 | */ |
| 366 | 303 | public static function load_single_field_settings( $atts ) { |
| 367 | 304 | $field = $atts['field']; |
| @@ -387,9 +324,9 @@ | ||
| 387 | 324 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 388 | 325 | // Add fallback for an add-on field type that has been deactivated. |
| 389 | 326 | $all_field_types[ $field['type'] ] = array( |
| 390 | 327 | 'name' => ucfirst( $field['type'] ), |
| 391 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 328 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 392 | 329 | ); |
| 393 | 330 | } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) { |
| 394 | 331 | // Fallback for fields added in a more basic way. |
| 395 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| @@ -395,9 +332,8 @@ | ||
| 395 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 396 | 333 | } |
| 397 | 334 | |
| 398 | 335 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 399 | - | |
| 400 | 336 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 401 | 337 | $type_name = $all_field_types['divider|repeat']['name']; |
| 402 | 338 | } |
| 403 | 339 | |
| @@ -408,79 +344,8 @@ | ||
| 408 | 344 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 409 | 345 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 410 | 346 | } |
| 411 | 347 | |
| 412 | - $pro_is_installed = FrmAppHelper::pro_is_installed(); | |
| 413 | - | |
| 414 | - $unique_values_label_atts = array( | |
| 415 | - 'for' => 'frm_uniq_field_' . $field['id'], | |
| 416 | - 'class' => 'frm_help frm-mb-0', | |
| 417 | - 'title' => __( | |
| 418 | - '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.', | |
| 419 | - 'formidable' | |
| 420 | - ), | |
| 421 | - 'data-trigger' => 'hover', | |
| 422 | - ); | |
| 423 | - | |
| 424 | - $read_only_label_atts = array( | |
| 425 | - 'for' => 'frm_read_only_field_' . $field['id'], | |
| 426 | - 'class' => 'frm_help frm-mb-0', | |
| 427 | - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ), | |
| 428 | - 'data-trigger' => 'hover', | |
| 429 | - ); | |
| 430 | - | |
| 431 | - if ( ! $pro_is_installed ) { | |
| 432 | - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 433 | - array( | |
| 434 | - 'id' => 'field_options_admin_only_' . $field['id'], | |
| 435 | - 'readonly' => '1', | |
| 436 | - ), | |
| 437 | - 'field_visibility', | |
| 438 | - __( 'Visibility options', 'formidable' ), | |
| 439 | - '/field-options/#kb-visibility' | |
| 440 | - ); | |
| 441 | - | |
| 442 | - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 443 | - array( 'id' => 'field_options_autocomplete_' . $field['id'] ), | |
| 444 | - 'autocomplete', | |
| 445 | - __( 'Autocomplete options', 'formidable' ), | |
| 446 | - '/email-address/#kb-autocomplete-attribute' | |
| 447 | - ); | |
| 448 | - | |
| 449 | - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 450 | - array( | |
| 451 | - 'type' => 'text', | |
| 452 | - 'readonly' => '1', | |
| 453 | - ), | |
| 454 | - 'before_after_contents', | |
| 455 | - __( 'Before and after field contents', 'formidable' ), | |
| 456 | - '/field-options/#kb-before-after-input' | |
| 457 | - ); | |
| 458 | - | |
| 459 | - $show_upsell_for_unique_value = in_array( | |
| 460 | - $field['type'], | |
| 461 | - array( 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), | |
| 462 | - true | |
| 463 | - ); | |
| 464 | - $show_upsell_for_read_only = in_array( $field['type'], array( 'address', 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true ); | |
| 465 | - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true ); | |
| 466 | - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true ); | |
| 467 | - $show_upsell_for_visibility = $field['type'] !== 'hidden'; | |
| 468 | - | |
| 469 | - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 470 | - $unique_values_label_atts, | |
| 471 | - 'unique_values', | |
| 472 | - __( 'Unique Values', 'formidable' ), | |
| 473 | - '/field-options/#kb-unique' | |
| 474 | - ); | |
| 475 | - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 476 | - $read_only_label_atts, | |
| 477 | - 'read_only', | |
| 478 | - __( 'Read Only Values', 'formidable' ), | |
| 479 | - '/field-options/#kb-read-only' | |
| 480 | - ); | |
| 481 | - }//end if | |
| 482 | - | |
| 483 | 348 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; |
| 484 | 349 | } |
| 485 | 350 | |
| 486 | 351 | /** |
| @@ -501,9 +366,8 @@ | ||
| 501 | 366 | * @since 4.0 |
| 502 | 367 | * |
| 503 | 368 | * @param array $field |
| 504 | 369 | * @param array $atts |
| 505 | - * | |
| 506 | 370 | * @return array |
| 507 | 371 | */ |
| 508 | 372 | private static function default_value_types( $field, $atts ) { |
| 509 | 373 | $types = array( |
| @@ -508,33 +372,31 @@ | ||
| 508 | 372 | private static function default_value_types( $field, $atts ) { |
| 509 | 373 | $types = array( |
| 510 | 374 | 'default_value' => array( |
| 511 | 375 | 'class' => '', |
| 512 | - 'icon' => 'frmfont frm_text2_icon', | |
| 513 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 376 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 377 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 514 | 378 | 'data' => array( |
| 515 | 379 | 'frmshow' => '#default-value-for-', |
| 516 | 380 | ), |
| 517 | 381 | ), |
| 518 | 382 | 'calc' => array( |
| 519 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 520 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 521 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 522 | - '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( | |
| 523 | 387 | 'medium' => 'calculations', |
| 524 | 388 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 525 | 389 | ), |
| 526 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 527 | 390 | ), |
| 528 | 391 | 'get_values_field' => array( |
| 529 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 530 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 531 | - 'icon' => 'frmfont frm_search_icon', | |
| 532 | - '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( | |
| 533 | 396 | 'medium' => 'lookup', |
| 534 | 397 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 535 | 398 | ), |
| 536 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 537 | 399 | ), |
| 538 | 400 | ); |
| 539 | 401 | |
| 540 | 402 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| @@ -542,13 +404,11 @@ | ||
| 542 | 404 | // Set active class. |
| 543 | 405 | $settings = array_keys( $types ); |
| 544 | 406 | $active = 'default_value'; |
| 545 | 407 | |
| 546 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 547 | - foreach ( $settings as $type ) { | |
| 548 | - if ( ! empty( $field[ $type ] ) ) { | |
| 549 | - $active = $type; | |
| 550 | - } | |
| 408 | + foreach ( $settings as $type ) { | |
| 409 | + if ( ! empty( $field[ $type ] ) ) { | |
| 410 | + $active = $type; | |
| 551 | 411 | } |
| 552 | 412 | } |
| 553 | 413 | |
| 554 | 414 | $types[ $active ]['class'] .= ' current'; |
| @@ -558,9 +418,8 @@ | ||
| 558 | 418 | } |
| 559 | 419 | |
| 560 | 420 | /** |
| 561 | 421 | * @param string $type |
| 562 | - * | |
| 563 | 422 | * @return string |
| 564 | 423 | */ |
| 565 | 424 | public static function change_type( $type ) { |
| 566 | 425 | $type_switch = array( |
| @@ -570,9 +429,8 @@ | ||
| 570 | 429 | 'rte' => 'textarea', |
| 571 | 430 | 'website' => 'url', |
| 572 | 431 | 'image' => 'url', |
| 573 | 432 | ); |
| 574 | - | |
| 575 | 433 | if ( isset( $type_switch[ $type ] ) ) { |
| 576 | 434 | $type = $type_switch[ $type ]; |
| 577 | 435 | } |
| 578 | 436 | |
| @@ -578,11 +436,15 @@ | ||
| 578 | 436 | |
| 579 | 437 | $pro_fields = FrmField::pro_field_selection(); |
| 580 | 438 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 581 | 439 | // The credit_card key is set for backward compatibility. |
| 582 | - FrmField::remove_moved_field_types_from_pro( $pro_fields ); | |
| 440 | + unset( $pro_fields['credit_card'] ); | |
| 583 | 441 | |
| 584 | - 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; | |
| 585 | 447 | } |
| 586 | 448 | |
| 587 | 449 | /** |
| 588 | 450 | * @param array $settings |
| @@ -605,20 +467,17 @@ | ||
| 605 | 467 | * Display the format option |
| 606 | 468 | * |
| 607 | 469 | * @since 3.0 |
| 608 | 470 | * |
| 609 | - * @param array $field Field data. | |
| 610 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 611 | - * | |
| 471 | + * @param array $field | |
| 612 | 472 | * @return void |
| 613 | 473 | */ |
| 614 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 615 | - $attributes = array( | |
| 616 | - 'class' => 'frm-has-modal', | |
| 617 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 618 | - ); | |
| 474 | + public static function show_format_option( $field ) { | |
| 475 | + $attributes = array(); | |
| 476 | + $attributes['class'] = 'frm-has-modal'; | |
| 619 | 477 | |
| 620 | - if ( $is_hidden ) { | |
| 478 | + if ( 'phone' === $field['type'] ) { | |
| 479 | + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id']; | |
| 621 | 480 | $attributes['class'] .= ' frm_hidden'; |
| 622 | 481 | } |
| 623 | 482 | |
| 624 | 483 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| @@ -623,14 +482,8 @@ | ||
| 623 | 482 | |
| 624 | 483 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 625 | 484 | } |
| 626 | 485 | |
| 627 | - /** | |
| 628 | - * @param array $field | |
| 629 | - * @param bool $echo | |
| 630 | - * | |
| 631 | - * @return string | |
| 632 | - */ | |
| 633 | 486 | public static function input_html( $field, $echo = true ) { |
| 634 | 487 | $class = array(); |
| 635 | 488 | self::add_input_classes( $field, $class ); |
| 636 | 489 | |
| @@ -645,9 +498,8 @@ | ||
| 645 | 498 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
| 646 | 499 | |
| 647 | 500 | self::add_shortcodes_to_html( $field, $add_html ); |
| 648 | 501 | self::add_pattern_attribute( $field, $add_html ); |
| 649 | - self::add_currency_field_attributes( $field, $add_html ); | |
| 650 | 502 | |
| 651 | 503 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
| 652 | 504 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
| 653 | 505 | |
| @@ -660,9 +512,8 @@ | ||
| 660 | 512 | |
| 661 | 513 | /** |
| 662 | 514 | * @param array $field |
| 663 | 515 | * @param array $class |
| 664 | - * | |
| 665 | 516 | * @return void |
| 666 | 517 | */ |
| 667 | 518 | private static function add_input_classes( $field, array &$class ) { |
| 668 | 519 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -680,9 +531,8 @@ | ||
| 680 | 531 | |
| 681 | 532 | /** |
| 682 | 533 | * @param array $field |
| 683 | 534 | * @param array $add_html |
| 684 | - * | |
| 685 | 535 | * @return void |
| 686 | 536 | */ |
| 687 | 537 | private static function add_html_size( $field, array &$add_html ) { |
| 688 | 538 | $size_fields = array( |
| @@ -715,9 +565,8 @@ | ||
| 715 | 565 | |
| 716 | 566 | /** |
| 717 | 567 | * @param array $field |
| 718 | 568 | * @param array $add_html |
| 719 | - * | |
| 720 | 569 | * @return void |
| 721 | 570 | */ |
| 722 | 571 | private static function add_html_cols( $field, array &$add_html ) { |
| 723 | 572 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -731,9 +580,9 @@ | ||
| 731 | 580 | 'rem' => 0.444, |
| 732 | 581 | 'em' => 0.544, |
| 733 | 582 | ); |
| 734 | 583 | |
| 735 | - // Include "col" for valid html | |
| 584 | + // include "col" for valid html | |
| 736 | 585 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 737 | 586 | |
| 738 | 587 | if ( ! isset( $calc[ $unit ] ) ) { |
| 739 | 588 | return; |
| @@ -738,9 +587,10 @@ | ||
| 738 | 587 | if ( ! isset( $calc[ $unit ] ) ) { |
| 739 | 588 | return; |
| 740 | 589 | } |
| 741 | 590 | |
| 742 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 591 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 592 | + | |
| 743 | 593 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 744 | 594 | } |
| 745 | 595 | |
| 746 | 596 | /** |
| @@ -745,9 +595,8 @@ | ||
| 745 | 595 | |
| 746 | 596 | /** |
| 747 | 597 | * @param array $field |
| 748 | 598 | * @param array $add_html |
| 749 | - * | |
| 750 | 599 | * @return void |
| 751 | 600 | */ |
| 752 | 601 | private static function add_html_length( $field, array &$add_html ) { |
| 753 | 602 | // Check for max setting and if this field accepts maxlength. |
| @@ -773,13 +622,11 @@ | ||
| 773 | 622 | /** |
| 774 | 623 | * @param array $field |
| 775 | 624 | * @param array $add_html |
| 776 | 625 | * @param array $class |
| 777 | - * | |
| 778 | 626 | * @return void |
| 779 | 627 | */ |
| 780 | 628 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 781 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 782 | 629 | if ( $field['default_value'] != '' ) { |
| 783 | 630 | if ( is_array( $field['default_value'] ) ) { |
| 784 | 631 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 785 | 632 | } else { |
| @@ -787,12 +634,10 @@ | ||
| 787 | 634 | } |
| 788 | 635 | } |
| 789 | 636 | |
| 790 | 637 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 791 | - | |
| 792 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 793 | 638 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 794 | - // Don't include a json placeholder | |
| 639 | + // don't include a json placeholder | |
| 795 | 640 | return; |
| 796 | 641 | } |
| 797 | 642 | |
| 798 | 643 | self::add_placeholder_to_input( $field, $add_html ); |
| @@ -803,13 +648,14 @@ | ||
| 803 | 648 | * |
| 804 | 649 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 805 | 650 | * |
| 806 | 651 | * @param array $field Field array. |
| 807 | - * | |
| 808 | 652 | * @return string |
| 809 | 653 | */ |
| 810 | 654 | private static function prepare_placeholder( $field ) { |
| 811 | - return $field['placeholder'] ?? ''; | |
| 655 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 656 | + | |
| 657 | + return $placeholder; | |
| 812 | 658 | } |
| 813 | 659 | |
| 814 | 660 | /** |
| 815 | 661 | * If the label position is "inside", |
| @@ -830,17 +676,13 @@ | ||
| 830 | 676 | * Maybe add a blank placeholder option before any options |
| 831 | 677 | * in a dropdown. |
| 832 | 678 | * |
| 833 | 679 | * @since 4.04 |
| 834 | - * | |
| 835 | - * @param array|object $field | |
| 836 | - * | |
| 837 | 680 | * @return bool True if placeholder was added. |
| 838 | 681 | */ |
| 839 | 682 | public static function add_placeholder_to_select( $field ) { |
| 840 | 683 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 841 | - | |
| 842 | - if ( ! $placeholder ) { | |
| 684 | + if ( empty( $placeholder ) ) { | |
| 843 | 685 | $placeholder = self::get_default_value_from_name( $field ); |
| 844 | 686 | } |
| 845 | 687 | |
| 846 | 688 | $use_placeholder = $placeholder; |
| @@ -847,9 +689,8 @@ | ||
| 847 | 689 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 848 | 690 | |
| 849 | 691 | if ( $autocomplete ) { |
| 850 | 692 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 851 | - | |
| 852 | 693 | if ( $use_chosen ) { |
| 853 | 694 | $use_placeholder = ''; |
| 854 | 695 | } |
| 855 | 696 | } |
| @@ -860,8 +701,13 @@ | ||
| 860 | 701 | 'value' => '', |
| 861 | 702 | 'data-placeholder' => 'true', |
| 862 | 703 | ); |
| 863 | 704 | |
| 705 | + if ( $autocomplete && empty( $use_chosen ) ) { | |
| 706 | + // This is required for Slim Select. | |
| 707 | + $placeholder_attributes['data-placeholder'] = 'true'; | |
| 708 | + } | |
| 709 | + | |
| 864 | 710 | FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); |
| 865 | 711 | return true; |
| 866 | 712 | } |
| 867 | 713 | |
| @@ -872,9 +718,8 @@ | ||
| 872 | 718 | * Use HTML5 placeholder with js fallback. |
| 873 | 719 | * |
| 874 | 720 | * @param array $field |
| 875 | 721 | * @param array $add_html |
| 876 | - * | |
| 877 | 722 | * @return void |
| 878 | 723 | */ |
| 879 | 724 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 880 | 725 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -884,13 +729,11 @@ | ||
| 884 | 729 | |
| 885 | 730 | /** |
| 886 | 731 | * @param array $field |
| 887 | 732 | * @param array $add_html |
| 888 | - * | |
| 889 | 733 | * @return void |
| 890 | 734 | */ |
| 891 | 735 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 892 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 893 | 736 | if ( $field['placeholder'] != '' ) { |
| 894 | 737 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 895 | 738 | |
| 896 | 739 | if ( 'select' === $field['type'] ) { |
| @@ -897,20 +740,13 @@ | ||
| 897 | 740 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 898 | 741 | } |
| 899 | 742 | } |
| 900 | 743 | |
| 901 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 902 | 744 | if ( $field['default_value'] != '' ) { |
| 903 | 745 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 904 | 746 | } |
| 905 | 747 | } |
| 906 | 748 | |
| 907 | - /** | |
| 908 | - * @param array $field | |
| 909 | - * @param array $add_html | |
| 910 | - * | |
| 911 | - * @return void | |
| 912 | - */ | |
| 913 | 749 | private static function add_validation_messages( $field, array &$add_html ) { |
| 914 | 750 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 915 | 751 | |
| 916 | 752 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -934,9 +770,8 @@ | ||
| 934 | 770 | * |
| 935 | 771 | * @since 6.9 |
| 936 | 772 | * |
| 937 | 773 | * @param array|object $field |
| 938 | - * | |
| 939 | 774 | * @return array |
| 940 | 775 | */ |
| 941 | 776 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 942 | 777 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -966,26 +801,21 @@ | ||
| 966 | 801 | * @since 5.0.03 |
| 967 | 802 | * |
| 968 | 803 | * @param array $field |
| 969 | 804 | * @param array $add_html |
| 970 | - * | |
| 971 | 805 | * @return void |
| 972 | 806 | */ |
| 973 | 807 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 974 | 808 | $form = self::get_form_for_js_validation( $field ); |
| 975 | - | |
| 976 | 809 | if ( false === $form ) { |
| 977 | 810 | return; |
| 978 | 811 | } |
| 979 | 812 | |
| 980 | 813 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 981 | - | |
| 982 | - if ( false === $error_body ) { | |
| 983 | - return; | |
| 814 | + if ( false !== $error_body ) { | |
| 815 | + $error_body = urlencode( $error_body ); | |
| 816 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 984 | 817 | } |
| 985 | - | |
| 986 | - $error_body = urlencode( $error_body ); | |
| 987 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 988 | 818 | } |
| 989 | 819 | |
| 990 | 820 | /** |
| 991 | 821 | * @since 5.0.03 |
| @@ -990,24 +820,20 @@ | ||
| 990 | 820 | /** |
| 991 | 821 | * @since 5.0.03 |
| 992 | 822 | * |
| 993 | 823 | * @param array $field |
| 994 | - * | |
| 995 | 824 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 996 | 825 | */ |
| 997 | 826 | private static function get_form_for_js_validation( $field ) { |
| 998 | 827 | global $frm_vars; |
| 999 | - | |
| 1000 | 828 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 1001 | 829 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 1002 | 830 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 1003 | 831 | } |
| 1004 | - | |
| 1005 | 832 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 1006 | 833 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 1007 | 834 | } |
| 1008 | 835 | } |
| 1009 | - | |
| 1010 | 836 | return false; |
| 1011 | 837 | } |
| 1012 | 838 | |
| 1013 | 839 | /** |
| @@ -1013,9 +839,8 @@ | ||
| 1013 | 839 | /** |
| 1014 | 840 | * @param stdClass $form |
| 1015 | 841 | * @param array $field |
| 1016 | 842 | * @param array $errors |
| 1017 | - * | |
| 1018 | 843 | * @return false|string |
| 1019 | 844 | */ |
| 1020 | 845 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 1021 | 846 | if ( empty( $field['custom_html'] ) ) { |
| @@ -1023,16 +848,15 @@ | ||
| 1023 | 848 | } |
| 1024 | 849 | |
| 1025 | 850 | $custom_html = $field['custom_html']; |
| 1026 | 851 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 1027 | - $start = strpos( $custom_html, '[if error]' ); | |
| 1028 | 852 | |
| 853 | + $start = strpos( $custom_html, '[if error]' ); | |
| 1029 | 854 | if ( false === $start ) { |
| 1030 | 855 | return false; |
| 1031 | 856 | } |
| 1032 | 857 | |
| 1033 | 858 | $end = strpos( $custom_html, '[/if error]' ); |
| 1034 | - | |
| 1035 | 859 | if ( false === $end || $end < $start ) { |
| 1036 | 860 | return false; |
| 1037 | 861 | } |
| 1038 | 862 | |
| @@ -1043,9 +867,13 @@ | ||
| 1043 | 867 | '<div class="frm_error">[error]</div>', |
| 1044 | 868 | '<div class="frm_error" role="alert">[error]</div>', |
| 1045 | 869 | ); |
| 1046 | 870 | |
| 1047 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 871 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 872 | + return false; | |
| 873 | + } | |
| 874 | + | |
| 875 | + return $error_body; | |
| 1048 | 876 | } |
| 1049 | 877 | |
| 1050 | 878 | /** |
| 1051 | 879 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -1052,16 +880,13 @@ | ||
| 1052 | 880 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 1053 | 881 | * remove it is present if needed. |
| 1054 | 882 | * |
| 1055 | 883 | * @since 3.06.01 |
| 1056 | - * | |
| 1057 | 884 | * @param array $field |
| 1058 | 885 | * @param array $add_html |
| 1059 | - * | |
| 1060 | 886 | * @return void |
| 1061 | 887 | */ |
| 1062 | 888 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 1063 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1064 | 889 | $excluded_field_types = |
| 1065 | 890 | FrmField::is_radio( $field ) || |
| 1066 | 891 | FrmField::is_checkbox( $field ) || |
| 1067 | 892 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -1066,9 +891,8 @@ | ||
| 1066 | 891 | FrmField::is_checkbox( $field ) || |
| 1067 | 892 | FrmField::is_field_type( $field, 'file' ) || |
| 1068 | 893 | FrmField::is_field_type( $field, 'nps' ) || |
| 1069 | 894 | FrmField::is_field_type( $field, 'scale' ); |
| 1070 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1071 | 895 | |
| 1072 | 896 | if ( $excluded_field_types ) { |
| 1073 | 897 | return; |
| 1074 | 898 | } |
| @@ -1078,9 +902,8 @@ | ||
| 1078 | 902 | |
| 1079 | 903 | /** |
| 1080 | 904 | * @param array $field |
| 1081 | 905 | * @param array $add_html |
| 1082 | - * | |
| 1083 | 906 | * @return void |
| 1084 | 907 | */ |
| 1085 | 908 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 1086 | 909 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -1091,25 +914,13 @@ | ||
| 1091 | 914 | unset( $field['shortcodes']['autocomplete'] ); |
| 1092 | 915 | } |
| 1093 | 916 | |
| 1094 | 917 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 1095 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 1096 | - $subfield_name = $field['subfield_name']; | |
| 1097 | - | |
| 1098 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 1099 | - continue; | |
| 1100 | - } | |
| 1101 | - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. | |
| 1102 | - $k = 'aria-invalid'; | |
| 1103 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 1104 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | 918 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 1108 | 919 | continue; |
| 1109 | 920 | } |
| 1110 | 921 | |
| 1111 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 922 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1112 | 923 | $add_html[] = $v; |
| 1113 | 924 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1114 | 925 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1115 | 926 | } else { |
| @@ -1116,9 +927,9 @@ | ||
| 1116 | 927 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 1117 | 928 | } |
| 1118 | 929 | |
| 1119 | 930 | unset( $k, $v ); |
| 1120 | - }//end foreach | |
| 931 | + } | |
| 1121 | 932 | } |
| 1122 | 933 | |
| 1123 | 934 | /** |
| 1124 | 935 | * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. |
| @@ -1125,9 +936,8 @@ | ||
| 1125 | 936 | * |
| 1126 | 937 | * @since 6.11.2 |
| 1127 | 938 | * |
| 1128 | 939 | * @param string $key The option key. |
| 1129 | - * | |
| 1130 | 940 | * @return bool |
| 1131 | 941 | */ |
| 1132 | 942 | private static function should_allow_input_attribute( $key ) { |
| 1133 | 943 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1142,91 +952,28 @@ | ||
| 1142 | 952 | * @since 3.0 |
| 1143 | 953 | * |
| 1144 | 954 | * @param array $field |
| 1145 | 955 | * @param array $add_html |
| 1146 | - * | |
| 1147 | 956 | * @return void |
| 1148 | 957 | */ |
| 1149 | 958 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1150 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 1151 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 959 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 1152 | 960 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1153 | 961 | |
| 1154 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1155 | - return; | |
| 1156 | - } | |
| 962 | + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 963 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 964 | + $format = substr( $format, 2, - 1 ); | |
| 1157 | 965 | |
| 1158 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1159 | - $format = substr( $format, 2, - 1 ); | |
| 1160 | - | |
| 1161 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1162 | - } | |
| 1163 | - | |
| 1164 | - /** | |
| 1165 | - * Add product attributes to fields in multi-paged forms. | |
| 1166 | - * | |
| 1167 | - * @param array $field | |
| 1168 | - * @param array $add_html | |
| 1169 | - * | |
| 1170 | - * @return void | |
| 1171 | - */ | |
| 1172 | - private static function add_currency_field_attributes( $field, &$add_html ) { | |
| 1173 | - $type = $field['original_type'] ?? $field['type']; | |
| 1174 | - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true ); | |
| 1175 | - | |
| 1176 | - if ( ! $is_product_field ) { | |
| 1177 | - return; | |
| 966 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1178 | 967 | } |
| 1179 | - | |
| 1180 | - if ( $type === 'total' ) { | |
| 1181 | - $add_html['data-frmtotal'] = 'data-frmtotal'; | |
| 1182 | - } elseif ( $type === 'quantity' ) { | |
| 1183 | - $product_field = FrmField::get_option( $field, 'product_field' ); | |
| 1184 | - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"'; | |
| 1185 | - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) { | |
| 1186 | - // We want to do this only for fields that are hidden because it's | |
| 1187 | - // not their page, hence the check : 'hidden' === $field['type']. | |
| 1188 | - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field ); | |
| 1189 | - | |
| 1190 | - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"'; | |
| 1191 | - } | |
| 1192 | 968 | } |
| 1193 | 969 | |
| 1194 | - /** | |
| 1195 | - * @param array $field | |
| 1196 | - */ | |
| 1197 | - private static function get_product_price( $field ) { | |
| 1198 | - if ( is_array( $field['value'] ) ) { | |
| 1199 | - // '' is unlikely though, let's just do it to prevent warnings | |
| 1200 | - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] ) | |
| 1201 | - ? $field['value'][ $field['opt_key'] ] | |
| 1202 | - : ''; | |
| 1203 | - } else { | |
| 1204 | - $value = $field['value']; | |
| 1205 | - } | |
| 1206 | - | |
| 1207 | - $field_obj = FrmFieldFactory::get_field_object( $field['id'] ); | |
| 1208 | - | |
| 1209 | - if ( method_exists( $field_obj, 'get_posted_price' ) ) { | |
| 1210 | - return $field_obj->get_posted_price( $value ); | |
| 1211 | - } | |
| 1212 | - | |
| 1213 | - return $value; | |
| 1214 | - } | |
| 1215 | - | |
| 1216 | - /** | |
| 1217 | - * @param mixed $opt | |
| 1218 | - * @param mixed $opt_key | |
| 1219 | - * @param array|object $field | |
| 1220 | - * | |
| 1221 | - * @return mixed | |
| 1222 | - */ | |
| 1223 | 970 | public static function check_value( $opt, $opt_key, $field ) { |
| 1224 | 971 | if ( is_array( $opt ) ) { |
| 1225 | 972 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1226 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 973 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1227 | 974 | } else { |
| 1228 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 975 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1229 | 976 | } |
| 1230 | 977 | } |
| 1231 | 978 | |
| 1232 | 979 | return $opt; |
| @@ -1231,13 +978,12 @@ | ||
| 1231 | 978 | |
| 1232 | 979 | return $opt; |
| 1233 | 980 | } |
| 1234 | 981 | |
| 1235 | - /** | |
| 1236 | - * @param mixed $opt | |
| 1237 | - * | |
| 1238 | - * @return mixed | |
| 1239 | - */ | |
| 1240 | 982 | public static function check_label( $opt ) { |
| 1241 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 983 | + if ( is_array( $opt ) ) { | |
| 984 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 985 | + } | |
| 986 | + | |
| 987 | + return $opt; | |
| 1242 | 988 | } |
| 1243 | 989 | } |