| @@ -4,15 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFieldsController { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * This is stored statically so we can re-use this data for every field. | |
| 10 | - * | |
| 11 | - * @var FrmFieldSelectionData|null | |
| 12 | - */ | |
| 13 | - private static $field_selection_data; | |
| 14 | - | |
| 15 | 8 | public static function load_field() { |
| 16 | 9 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 17 | 10 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 18 | 11 | |
| @@ -18,10 +11,9 @@ | ||
| 18 | 11 | |
| 19 | 12 | // Javascript may be included in some field settings. |
| 20 | 13 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 21 | 14 | $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array(); |
| 22 | - | |
| 23 | - if ( ! $fields ) { | |
| 15 | + if ( empty( $fields ) ) { | |
| 24 | 16 | wp_die(); |
| 25 | 17 | } |
| 26 | 18 | |
| 27 | 19 | $_GET['page'] = 'formidable'; |
| @@ -34,11 +26,10 @@ | ||
| 34 | 26 | |
| 35 | 27 | foreach ( $fields as $field ) { |
| 36 | 28 | $field = htmlspecialchars_decode( nl2br( $field ) ); |
| 37 | 29 | $field = json_decode( $field ); |
| 38 | - | |
| 39 | 30 | if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) { |
| 40 | - // This field may have already been loaded | |
| 31 | + // this field may have already been loaded | |
| 41 | 32 | continue; |
| 42 | 33 | } |
| 43 | 34 | |
| 44 | 35 | if ( ! isset( $field->value ) ) { |
| @@ -49,10 +40,11 @@ | ||
| 49 | 40 | $field->default_value = json_decode( json_encode( $field->default_value ), true ); |
| 50 | 41 | |
| 51 | 42 | ob_start(); |
| 52 | 43 | self::load_single_field( $field, $values ); |
| 53 | - $field_html[ absint( $field->id ) ] = ob_get_clean(); | |
| 54 | - }//end foreach | |
| 44 | + $field_html[ absint( $field->id ) ] = ob_get_contents(); | |
| 45 | + ob_end_clean(); | |
| 46 | + } | |
| 55 | 47 | |
| 56 | 48 | echo json_encode( $field_html ); |
| 57 | 49 | |
| 58 | 50 | wp_die(); |
| @@ -64,17 +56,16 @@ | ||
| 64 | 56 | public static function create() { |
| 65 | 57 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 66 | 58 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 67 | 59 | |
| 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' ); | |
| 60 | + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 61 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 71 | 62 | |
| 72 | 63 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 73 | 64 | |
| 74 | - $field = self::include_new_field( $field_type, $form_id, $field_options ); | |
| 65 | + $field = self::include_new_field( $field_type, $form_id ); | |
| 75 | 66 | |
| 76 | - // This hook will allow for multiple fields to be added at once | |
| 67 | + // this hook will allow for multiple fields to be added at once | |
| 77 | 68 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 78 | 69 | |
| 79 | 70 | wp_die(); |
| 80 | 71 | } |
| @@ -81,21 +72,16 @@ | ||
| 81 | 72 | |
| 82 | 73 | /** |
| 83 | 74 | * Set up and create a new field |
| 84 | 75 | * |
| 85 | - * @param string $field_type | |
| 86 | - * @param int $form_id | |
| 87 | - * @param array $field_options | |
| 76 | + * @param string $field_type | |
| 77 | + * @param integer $form_id | |
| 88 | 78 | * |
| 89 | - * @return array|false | |
| 79 | + * @return array|bool | |
| 90 | 80 | */ |
| 91 | - public static function include_new_field( $field_type, $form_id, $field_options = array() ) { | |
| 81 | + public static function include_new_field( $field_type, $form_id ) { | |
| 92 | 82 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 93 | 83 | |
| 94 | - if ( $field_options ) { | |
| 95 | - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); | |
| 96 | - } | |
| 97 | - | |
| 98 | 84 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| 99 | 85 | $field_values['field_options']['draft'] = 1; |
| 100 | 86 | |
| 101 | 87 | /** |
| @@ -107,15 +93,15 @@ | ||
| 107 | 93 | if ( ! $field_id ) { |
| 108 | 94 | return false; |
| 109 | 95 | } |
| 110 | 96 | |
| 111 | - $field = self::get_field_array_from_id( $field_id ); | |
| 97 | + $field = self::get_field_array_from_id( $field_id ); | |
| 98 | + | |
| 112 | 99 | $values = array(); |
| 113 | - | |
| 114 | 100 | if ( FrmAppHelper::pro_is_installed() ) { |
| 115 | 101 | $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 | 102 | |
| 103 | + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 118 | 104 | if ( $parent_form_id ) { |
| 119 | 105 | $field['parent_form_id'] = $parent_form_id; |
| 120 | 106 | } |
| 121 | 107 | } |
| @@ -128,10 +114,11 @@ | ||
| 128 | 114 | public static function duplicate() { |
| 129 | 115 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 130 | 116 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 131 | 117 | |
| 132 | - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 133 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 118 | + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 119 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 120 | + | |
| 134 | 121 | $new_field = FrmField::duplicate_single_field( $field_id, $form_id ); |
| 135 | 122 | |
| 136 | 123 | if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) { |
| 137 | 124 | self::load_single_field( $new_field['field_id'], $new_field['values'] ); |
| @@ -148,8 +135,9 @@ | ||
| 148 | 135 | * @return array |
| 149 | 136 | */ |
| 150 | 137 | public static function get_field_array_from_id( $field_id ) { |
| 151 | 138 | $field = FrmField::getOne( $field_id ); |
| 139 | + | |
| 152 | 140 | return FrmFieldsHelper::setup_edit_vars( $field ); |
| 153 | 141 | } |
| 154 | 142 | |
| 155 | 143 | /** |
| @@ -154,13 +142,11 @@ | ||
| 154 | 142 | |
| 155 | 143 | /** |
| 156 | 144 | * @since 3.0 |
| 157 | 145 | * |
| 158 | - * @param array|int|object|string $field_object | |
| 159 | - * @param array $values | |
| 160 | - * @param int $form_id | |
| 161 | - * | |
| 162 | - * @return void | |
| 146 | + * @param int|array|object $field_object | |
| 147 | + * @param array $values | |
| 148 | + * @param int $form_id | |
| 163 | 149 | */ |
| 164 | 150 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 165 | 151 | global $frm_vars; |
| 166 | 152 | $frm_vars['is_admin'] = true; |
| @@ -171,49 +157,33 @@ | ||
| 171 | 157 | $field = $field_object; |
| 172 | 158 | $field_object = FrmField::getOne( $field['id'] ); |
| 173 | 159 | } |
| 174 | 160 | |
| 175 | - $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 176 | - $display = self::display_field_options( array(), $field_obj ); | |
| 177 | - $ajax_loading = ! empty( $values['ajax_load'] ); | |
| 178 | - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true ); | |
| 161 | + $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 162 | + $display = self::display_field_options( array(), $field_obj ); | |
| 179 | 163 | |
| 164 | + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load']; | |
| 165 | + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) ); | |
| 166 | + | |
| 180 | 167 | if ( $ajax_loading && $ajax_this_field ) { |
| 181 | 168 | $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj ); |
| 182 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php'; | |
| 183 | - return; | |
| 184 | - } | |
| 169 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' ); | |
| 170 | + } else { | |
| 171 | + if ( ! isset( $field ) && is_object( $field_object ) ) { | |
| 172 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 185 | 173 | |
| 186 | - if ( ! isset( $field ) && is_object( $field_object ) ) { | |
| 187 | - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id; | |
| 188 | - $field = FrmFieldsHelper::setup_edit_vars( $field_object ); | |
| 189 | - } | |
| 174 | + $field = FrmFieldsHelper::setup_edit_vars( $field_object ); | |
| 175 | + } | |
| 190 | 176 | |
| 191 | - /** | |
| 192 | - * Filter for adding extra attributes to the field container. | |
| 193 | - * | |
| 194 | - * @since 6.23 | |
| 195 | - * | |
| 196 | - * @param array $extra_field_attributes | |
| 197 | - * @param array $field | |
| 198 | - * @param array $display | |
| 199 | - */ | |
| 200 | - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display ); | |
| 177 | + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); | |
| 178 | + $li_classes .= ' ui-state-default widgets-holder-wrap'; | |
| 201 | 179 | |
| 202 | - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); | |
| 203 | - $li_classes .= ' ui-state-default widgets-holder-wrap'; | |
| 204 | - | |
| 205 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; | |
| 180 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); | |
| 181 | + } | |
| 206 | 182 | } |
| 207 | 183 | |
| 208 | 184 | /** |
| 209 | 185 | * @since 3.0 |
| 210 | - * | |
| 211 | - * @param array $field | |
| 212 | - * @param array $display | |
| 213 | - * @param FrmFieldType $field_info | |
| 214 | - * | |
| 215 | - * @return string | |
| 216 | 186 | */ |
| 217 | 187 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 218 | 188 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| 219 | 189 | $li_classes .= ' frm_form_field frmstart '; |
| @@ -224,9 +194,9 @@ | ||
| 224 | 194 | |
| 225 | 195 | $li_classes .= 'frmend'; |
| 226 | 196 | |
| 227 | 197 | if ( $field ) { |
| 228 | - return apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 198 | + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 229 | 199 | } |
| 230 | 200 | |
| 231 | 201 | return $li_classes; |
| 232 | 202 | } |
| @@ -250,40 +220,27 @@ | ||
| 250 | 220 | if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 251 | 221 | return; |
| 252 | 222 | } |
| 253 | 223 | |
| 254 | - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' ); | |
| 255 | - $field = FrmField::getOne( $field_id ); | |
| 256 | - $bulk_edit_types = array( 'radio', 'checkbox', 'select' ); | |
| 224 | + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' ); | |
| 225 | + $field = FrmField::getOne( $field_id ); | |
| 257 | 226 | |
| 258 | - /** | |
| 259 | - * Filter to add new fields that will support import_options/Bulk Edit Options. | |
| 260 | - * | |
| 261 | - * @since 6.8.4 | |
| 262 | - * | |
| 263 | - * @param array $bulk_edit_types | |
| 264 | - * | |
| 265 | - * @return array | |
| 266 | - */ | |
| 267 | - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); | |
| 268 | - | |
| 269 | - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) { | |
| 227 | + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { | |
| 270 | 228 | return; |
| 271 | 229 | } |
| 272 | 230 | |
| 273 | 231 | $field = FrmFieldsHelper::setup_edit_vars( $field ); |
| 232 | + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 233 | + $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 234 | + $opts = array_map( 'trim', $opts ); | |
| 274 | 235 | |
| 275 | - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 276 | - $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 277 | - $opts = array_map( 'trim', $opts ); | |
| 236 | + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); | |
| 237 | + $field['separate_value'] = ( $separate === 'true' ); | |
| 278 | 238 | |
| 279 | - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); | |
| 280 | - $field['separate_value'] = $separate === 'true'; | |
| 281 | - | |
| 282 | 239 | if ( $field['separate_value'] ) { |
| 283 | 240 | foreach ( $opts as $opt_key => $opt ) { |
| 284 | - if ( str_contains( $opt, '|' ) ) { | |
| 285 | - $vals = explode( '|', $opt ); | |
| 241 | + if ( strpos( $opt, '|' ) !== false ) { | |
| 242 | + $vals = explode( '|', $opt ); | |
| 286 | 243 | $opts[ $opt_key ] = array( |
| 287 | 244 | 'label' => trim( $vals[0] ), |
| 288 | 245 | 'value' => trim( $vals[1] ), |
| 289 | 246 | ); |
| @@ -293,11 +250,10 @@ | ||
| 293 | 250 | } |
| 294 | 251 | } |
| 295 | 252 | |
| 296 | 253 | // Keep other options after bulk update. |
| 297 | - if ( ! empty( $field['field_options']['other'] ) ) { | |
| 254 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { | |
| 298 | 255 | $other_array = array(); |
| 299 | - | |
| 300 | 256 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 301 | 257 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 302 | 258 | $other_array[ $opt_key ] = $opt; |
| 303 | 259 | } |
| @@ -302,10 +258,9 @@ | ||
| 302 | 258 | $other_array[ $opt_key ] = $opt; |
| 303 | 259 | } |
| 304 | 260 | unset( $opt_key, $opt ); |
| 305 | 261 | } |
| 306 | - | |
| 307 | - if ( $other_array ) { | |
| 262 | + if ( ! empty( $other_array ) ) { | |
| 308 | 263 | $opts = array_merge( $opts, $other_array ); |
| 309 | 264 | } |
| 310 | 265 | } |
| 311 | 266 | |
| @@ -319,10 +274,8 @@ | ||
| 319 | 274 | /** |
| 320 | 275 | * @since 4.0 |
| 321 | 276 | * |
| 322 | 277 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 323 | - * | |
| 324 | - * @return void | |
| 325 | 278 | */ |
| 326 | 279 | public static function load_single_field_settings( $atts ) { |
| 327 | 280 | $field = $atts['field']; |
| 328 | 281 | $field_obj = $atts['field_obj']; |
| @@ -337,19 +290,19 @@ | ||
| 337 | 290 | if ( ! isset( $field['read_only'] ) ) { |
| 338 | 291 | $field['read_only'] = false; |
| 339 | 292 | } |
| 340 | 293 | |
| 341 | - $field_selection_data = self::maybe_define_field_selection_data(); | |
| 342 | - $all_field_types = $field_selection_data->all_field_types; | |
| 343 | - $disabled_fields = $field_selection_data->disabled_fields; | |
| 344 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 345 | - $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] ); | |
| 294 | + $field_types = FrmFieldsHelper::get_field_types( $field['type'] ); | |
| 295 | + $pro_field_selection = FrmField::pro_field_selection(); | |
| 296 | + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() ); | |
| 297 | + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection; | |
| 298 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 346 | 299 | |
| 347 | 300 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 348 | 301 | // Add fallback for an add-on field type that has been deactivated. |
| 349 | 302 | $all_field_types[ $field['type'] ] = array( |
| 350 | 303 | 'name' => ucfirst( $field['type'] ), |
| 351 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 304 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 352 | 305 | ); |
| 353 | 306 | } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) { |
| 354 | 307 | // Fallback for fields added in a more basic way. |
| 355 | 308 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| @@ -355,9 +308,8 @@ | ||
| 355 | 308 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 356 | 309 | } |
| 357 | 310 | |
| 358 | 311 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 359 | - | |
| 360 | 312 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 361 | 313 | $type_name = $all_field_types['divider|repeat']['name']; |
| 362 | 314 | } |
| 363 | 315 | |
| @@ -368,147 +320,61 @@ | ||
| 368 | 320 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 369 | 321 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 370 | 322 | } |
| 371 | 323 | |
| 372 | - $pro_is_installed = FrmAppHelper::pro_is_installed(); | |
| 373 | - | |
| 374 | - $unique_values_label_atts = array( | |
| 375 | - 'for' => 'frm_uniq_field_' . $field['id'], | |
| 376 | - 'class' => 'frm_help frm-mb-0', | |
| 377 | - 'title' => __( | |
| 378 | - '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.', | |
| 379 | - 'formidable' | |
| 380 | - ), | |
| 381 | - 'data-trigger' => 'hover', | |
| 382 | - ); | |
| 383 | - | |
| 384 | - $read_only_label_atts = array( | |
| 385 | - 'for' => 'frm_read_only_field_' . $field['id'], | |
| 386 | - 'class' => 'frm_help frm-mb-0', | |
| 387 | - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ), | |
| 388 | - 'data-trigger' => 'hover', | |
| 389 | - ); | |
| 390 | - | |
| 391 | - if ( ! $pro_is_installed ) { | |
| 392 | - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 393 | - array( | |
| 394 | - 'id' => 'field_options_admin_only_' . $field['id'], | |
| 395 | - 'readonly' => '1', | |
| 396 | - ), | |
| 397 | - 'field_visibility', | |
| 398 | - __( 'Visibility options', 'formidable' ), | |
| 399 | - '/field-options/#kb-visibility' | |
| 400 | - ); | |
| 401 | - | |
| 402 | - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 403 | - array( 'id' => 'field_options_autocomplete_' . $field['id'] ), | |
| 404 | - 'autocomplete', | |
| 405 | - __( 'Autocomplete options', 'formidable' ), | |
| 406 | - '/email-address/#kb-autocomplete-attribute' | |
| 407 | - ); | |
| 408 | - | |
| 409 | - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 410 | - array( | |
| 411 | - 'type' => 'text', | |
| 412 | - 'readonly' => '1', | |
| 413 | - ), | |
| 414 | - 'before_after_contents', | |
| 415 | - __( 'Before and after field contents', 'formidable' ), | |
| 416 | - '/field-options/#kb-before-after-input' | |
| 417 | - ); | |
| 418 | - | |
| 419 | - $show_upsell_for_unique_value = in_array( | |
| 420 | - $field['type'], | |
| 421 | - array( 'address', 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), | |
| 422 | - true | |
| 423 | - ); | |
| 424 | - $show_upsell_for_read_only = in_array( $field['type'], array( 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true ); | |
| 425 | - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true ); | |
| 426 | - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true ); | |
| 427 | - $show_upsell_for_visibility = $field['type'] !== 'hidden'; | |
| 428 | - | |
| 429 | - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 430 | - $unique_values_label_atts, | |
| 431 | - 'unique_values', | |
| 432 | - __( 'Unique Values', 'formidable' ), | |
| 433 | - '/field-options/#kb-unique' | |
| 434 | - ); | |
| 435 | - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 436 | - $read_only_label_atts, | |
| 437 | - 'read_only', | |
| 438 | - __( 'Read Only Values', 'formidable' ), | |
| 439 | - '/field-options/#kb-read-only' | |
| 440 | - ); | |
| 441 | - }//end if | |
| 442 | - | |
| 443 | 324 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; |
| 444 | 325 | } |
| 445 | 326 | |
| 446 | 327 | /** |
| 447 | - * @since 6.9.1 | |
| 448 | - * | |
| 449 | - * @return FrmFieldSelectionData | |
| 450 | - */ | |
| 451 | - private static function maybe_define_field_selection_data() { | |
| 452 | - if ( ! isset( self::$field_selection_data ) ) { | |
| 453 | - self::$field_selection_data = new FrmFieldSelectionData(); | |
| 454 | - } | |
| 455 | - return self::$field_selection_data; | |
| 456 | - } | |
| 457 | - | |
| 458 | - /** | |
| 459 | 328 | * Get the list of default value types that can be toggled in the builder. |
| 460 | 329 | * |
| 461 | 330 | * @since 4.0 |
| 462 | - * | |
| 463 | - * @param array $field | |
| 464 | - * @param array $atts | |
| 465 | - * | |
| 466 | 331 | * @return array |
| 467 | 332 | */ |
| 468 | 333 | private static function default_value_types( $field, $atts ) { |
| 469 | 334 | $types = array( |
| 470 | - 'default_value' => array( | |
| 335 | + 'default_value' => array( | |
| 471 | 336 | 'class' => '', |
| 472 | - 'icon' => 'frmfont frm_text2_icon', | |
| 473 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 337 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 338 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 474 | 339 | 'data' => array( |
| 475 | 340 | 'frmshow' => '#default-value-for-', |
| 476 | 341 | ), |
| 477 | 342 | ), |
| 478 | - 'calc' => array( | |
| 479 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 480 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 481 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 482 | - 'data' => array( | |
| 343 | + 'calc' => array( | |
| 344 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 345 | + 'title' => __( 'Default Value (Calculation)', 'formidable' ), | |
| 346 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 347 | + 'data' => array( | |
| 483 | 348 | 'medium' => 'calculations', |
| 484 | 349 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 485 | 350 | ), |
| 486 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 487 | 351 | ), |
| 488 | 352 | 'get_values_field' => array( |
| 489 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 490 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 491 | - 'icon' => 'frmfont frm_search_icon', | |
| 492 | - 'data' => array( | |
| 353 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 354 | + 'title' => __( 'Default Value (Lookup)', 'formidable' ), | |
| 355 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 356 | + 'data' => array( | |
| 493 | 357 | 'medium' => 'lookup', |
| 494 | 358 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 495 | 359 | ), |
| 496 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 497 | 360 | ), |
| 498 | 361 | ); |
| 499 | 362 | |
| 500 | 363 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| 501 | 364 | |
| 365 | + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) { | |
| 366 | + // Prevent settings from showing in 2 spots. | |
| 367 | + unset( $types['calc'], $types['get_values_field'] ); | |
| 368 | + } | |
| 369 | + | |
| 502 | 370 | // Set active class. |
| 503 | 371 | $settings = array_keys( $types ); |
| 504 | 372 | $active = 'default_value'; |
| 505 | 373 | |
| 506 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 507 | - foreach ( $settings as $type ) { | |
| 508 | - if ( ! empty( $field[ $type ] ) ) { | |
| 509 | - $active = $type; | |
| 510 | - } | |
| 374 | + foreach ( $settings as $type ) { | |
| 375 | + if ( ! empty( $field[ $type ] ) ) { | |
| 376 | + $active = $type; | |
| 511 | 377 | } |
| 512 | 378 | } |
| 513 | 379 | |
| 514 | 380 | $types[ $active ]['class'] .= ' current'; |
| @@ -516,13 +382,8 @@ | ||
| 516 | 382 | |
| 517 | 383 | return $types; |
| 518 | 384 | } |
| 519 | 385 | |
| 520 | - /** | |
| 521 | - * @param string $type | |
| 522 | - * | |
| 523 | - * @return string | |
| 524 | - */ | |
| 525 | 386 | public static function change_type( $type ) { |
| 526 | 387 | $type_switch = array( |
| 527 | 388 | 'scale' => 'radio', |
| 528 | 389 | 'star' => 'radio', |
| @@ -530,9 +391,8 @@ | ||
| 530 | 391 | 'rte' => 'textarea', |
| 531 | 392 | 'website' => 'url', |
| 532 | 393 | 'image' => 'url', |
| 533 | 394 | ); |
| 534 | - | |
| 535 | 395 | if ( isset( $type_switch[ $type ] ) ) { |
| 536 | 396 | $type = $type_switch[ $type ]; |
| 537 | 397 | } |
| 538 | 398 | |
| @@ -538,24 +398,26 @@ | ||
| 538 | 398 | |
| 539 | 399 | $pro_fields = FrmField::pro_field_selection(); |
| 540 | 400 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 541 | 401 | // The credit_card key is set for backward compatibility. |
| 542 | - FrmField::remove_moved_field_types_from_pro( $pro_fields ); | |
| 402 | + unset( $pro_fields['credit_card'] ); | |
| 543 | 403 | |
| 544 | - return array_key_exists( $type, $pro_fields ) ? 'text' : $type; | |
| 404 | + if ( array_key_exists( $type, $pro_fields ) ) { | |
| 405 | + $type = 'text'; | |
| 406 | + } | |
| 407 | + | |
| 408 | + return $type; | |
| 545 | 409 | } |
| 546 | 410 | |
| 547 | 411 | /** |
| 548 | - * @param array $settings | |
| 549 | - * @param FrmFieldType|null $field_info | |
| 412 | + * @param array $settings | |
| 413 | + * @param object $field_info | |
| 550 | 414 | * |
| 551 | 415 | * @return array |
| 552 | 416 | */ |
| 553 | 417 | public static function display_field_options( $settings, $field_info = null ) { |
| 554 | 418 | if ( $field_info ) { |
| 555 | - $settings = $field_info->display_field_settings(); | |
| 556 | - | |
| 557 | - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public. | |
| 419 | + $settings = $field_info->display_field_settings(); | |
| 558 | 420 | $settings['field_data'] = $field_info->field; |
| 559 | 421 | } |
| 560 | 422 | |
| 561 | 423 | return apply_filters( 'frm_display_field_options', $settings ); |
| @@ -565,32 +427,14 @@ | ||
| 565 | 427 | * Display the format option |
| 566 | 428 | * |
| 567 | 429 | * @since 3.0 |
| 568 | 430 | * |
| 569 | - * @param array $field Field data. | |
| 570 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 571 | - * | |
| 572 | - * @return void | |
| 431 | + * @param array $field | |
| 573 | 432 | */ |
| 574 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 575 | - $attributes = array( | |
| 576 | - 'class' => 'frm-has-modal', | |
| 577 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 578 | - ); | |
| 579 | - | |
| 580 | - if ( $is_hidden ) { | |
| 581 | - $attributes['class'] .= ' frm_hidden'; | |
| 582 | - } | |
| 583 | - | |
| 584 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; | |
| 433 | + public static function show_format_option( $field ) { | |
| 434 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' ); | |
| 585 | 435 | } |
| 586 | 436 | |
| 587 | - /** | |
| 588 | - * @param array $field | |
| 589 | - * @param bool $echo | |
| 590 | - * | |
| 591 | - * @return string | |
| 592 | - */ | |
| 593 | 437 | public static function input_html( $field, $echo = true ) { |
| 594 | 438 | $class = array(); |
| 595 | 439 | self::add_input_classes( $field, $class ); |
| 596 | 440 | |
| @@ -605,9 +449,8 @@ | ||
| 605 | 449 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
| 606 | 450 | |
| 607 | 451 | self::add_shortcodes_to_html( $field, $add_html ); |
| 608 | 452 | self::add_pattern_attribute( $field, $add_html ); |
| 609 | - self::add_currency_field_attributes( $field, $add_html ); | |
| 610 | 453 | |
| 611 | 454 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
| 612 | 455 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
| 613 | 456 | |
| @@ -617,20 +460,14 @@ | ||
| 617 | 460 | |
| 618 | 461 | return $add_html; |
| 619 | 462 | } |
| 620 | 463 | |
| 621 | - /** | |
| 622 | - * @param array $field | |
| 623 | - * @param array $class | |
| 624 | - * | |
| 625 | - * @return void | |
| 626 | - */ | |
| 627 | 464 | private static function add_input_classes( $field, array &$class ) { |
| 628 | - if ( ! empty( $field['input_class'] ) ) { | |
| 465 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { | |
| 629 | 466 | $class[] = $field['input_class']; |
| 630 | 467 | } |
| 631 | 468 | |
| 632 | - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) { | |
| 469 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { | |
| 633 | 470 | return; |
| 634 | 471 | } |
| 635 | 472 | |
| 636 | 473 | if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
| @@ -637,14 +474,8 @@ | ||
| 637 | 474 | $class[] = 'auto_width'; |
| 638 | 475 | } |
| 639 | 476 | } |
| 640 | 477 | |
| 641 | - /** | |
| 642 | - * @param array $field | |
| 643 | - * @param array $add_html | |
| 644 | - * | |
| 645 | - * @return void | |
| 646 | - */ | |
| 647 | 478 | private static function add_html_size( $field, array &$add_html ) { |
| 648 | 479 | $size_fields = array( |
| 649 | 480 | 'select', |
| 650 | 481 | 'data', |
| @@ -653,9 +484,9 @@ | ||
| 653 | 484 | 'file', |
| 654 | 485 | 'lookup', |
| 655 | 486 | ); |
| 656 | 487 | |
| 657 | - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) { | |
| 488 | + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) { | |
| 658 | 489 | return; |
| 659 | 490 | } |
| 660 | 491 | |
| 661 | 492 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| @@ -672,14 +503,8 @@ | ||
| 672 | 503 | |
| 673 | 504 | self::add_html_cols( $field, $add_html ); |
| 674 | 505 | } |
| 675 | 506 | |
| 676 | - /** | |
| 677 | - * @param array $field | |
| 678 | - * @param array $add_html | |
| 679 | - * | |
| 680 | - * @return void | |
| 681 | - */ | |
| 682 | 507 | private static function add_html_cols( $field, array &$add_html ) { |
| 683 | 508 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| 684 | 509 | return; |
| 685 | 510 | } |
| @@ -691,9 +516,9 @@ | ||
| 691 | 516 | 'rem' => 0.444, |
| 692 | 517 | 'em' => 0.544, |
| 693 | 518 | ); |
| 694 | 519 | |
| 695 | - // Include "col" for valid html | |
| 520 | + // include "col" for valid html | |
| 696 | 521 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 697 | 522 | |
| 698 | 523 | if ( ! isset( $calc[ $unit ] ) ) { |
| 699 | 524 | return; |
| @@ -698,18 +523,13 @@ | ||
| 698 | 523 | if ( ! isset( $calc[ $unit ] ) ) { |
| 699 | 524 | return; |
| 700 | 525 | } |
| 701 | 526 | |
| 702 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 527 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 528 | + | |
| 703 | 529 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 704 | 530 | } |
| 705 | 531 | |
| 706 | - /** | |
| 707 | - * @param array $field | |
| 708 | - * @param array $add_html | |
| 709 | - * | |
| 710 | - * @return void | |
| 711 | - */ | |
| 712 | 532 | private static function add_html_length( $field, array &$add_html ) { |
| 713 | 533 | // Check for max setting and if this field accepts maxlength. |
| 714 | 534 | $fields = array( |
| 715 | 535 | 'textarea', |
| @@ -717,9 +537,9 @@ | ||
| 717 | 537 | 'hidden', |
| 718 | 538 | 'file', |
| 719 | 539 | ); |
| 720 | 540 | |
| 721 | - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) { | |
| 541 | + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) { | |
| 722 | 542 | return; |
| 723 | 543 | } |
| 724 | 544 | |
| 725 | 545 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| @@ -729,17 +549,9 @@ | ||
| 729 | 549 | |
| 730 | 550 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
| 731 | 551 | } |
| 732 | 552 | |
| 733 | - /** | |
| 734 | - * @param array $field | |
| 735 | - * @param array $add_html | |
| 736 | - * @param array $class | |
| 737 | - * | |
| 738 | - * @return void | |
| 739 | - */ | |
| 740 | 553 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 741 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 742 | 554 | if ( $field['default_value'] != '' ) { |
| 743 | 555 | if ( is_array( $field['default_value'] ) ) { |
| 744 | 556 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 745 | 557 | } else { |
| @@ -747,16 +559,26 @@ | ||
| 747 | 559 | } |
| 748 | 560 | } |
| 749 | 561 | |
| 750 | 562 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 751 | - | |
| 752 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 753 | 563 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 754 | - // Don't include a json placeholder | |
| 564 | + // don't include a json placeholder | |
| 755 | 565 | return; |
| 756 | 566 | } |
| 757 | 567 | |
| 758 | - self::add_placeholder_to_input( $field, $add_html ); | |
| 568 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 569 | + | |
| 570 | + if ( $frm_settings->use_html ) { | |
| 571 | + self::add_placeholder_to_input( $field, $add_html ); | |
| 572 | + } else { | |
| 573 | + self::add_frmval_to_input( $field, $add_html ); | |
| 574 | + | |
| 575 | + $class[] = 'frm_toggle_default'; | |
| 576 | + | |
| 577 | + if ( $field['value'] == $field['placeholder'] ) { | |
| 578 | + $class[] = 'frm_default'; | |
| 579 | + } | |
| 580 | + } | |
| 759 | 581 | } |
| 760 | 582 | |
| 761 | 583 | /** |
| 762 | 584 | * Prepares field placeholder. |
| @@ -763,13 +585,14 @@ | ||
| 763 | 585 | * |
| 764 | 586 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 765 | 587 | * |
| 766 | 588 | * @param array $field Field array. |
| 767 | - * | |
| 768 | 589 | * @return string |
| 769 | 590 | */ |
| 770 | 591 | private static function prepare_placeholder( $field ) { |
| 771 | - return $field['placeholder'] ?? ''; | |
| 592 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 593 | + | |
| 594 | + return $placeholder; | |
| 772 | 595 | } |
| 773 | 596 | |
| 774 | 597 | /** |
| 775 | 598 | * If the label position is "inside", |
| @@ -790,17 +613,13 @@ | ||
| 790 | 613 | * Maybe add a blank placeholder option before any options |
| 791 | 614 | * in a dropdown. |
| 792 | 615 | * |
| 793 | 616 | * @since 4.04 |
| 794 | - * | |
| 795 | - * @param array|object $field | |
| 796 | - * | |
| 797 | 617 | * @return bool True if placeholder was added. |
| 798 | 618 | */ |
| 799 | 619 | public static function add_placeholder_to_select( $field ) { |
| 800 | 620 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 801 | - | |
| 802 | - if ( ! $placeholder ) { | |
| 621 | + if ( empty( $placeholder ) ) { | |
| 803 | 622 | $placeholder = self::get_default_value_from_name( $field ); |
| 804 | 623 | } |
| 805 | 624 | |
| 806 | 625 | $use_placeholder = $placeholder; |
| @@ -807,9 +626,8 @@ | ||
| 807 | 626 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 808 | 627 | |
| 809 | 628 | if ( $autocomplete ) { |
| 810 | 629 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 811 | - | |
| 812 | 630 | if ( $use_chosen ) { |
| 813 | 631 | $use_placeholder = ''; |
| 814 | 632 | } |
| 815 | 633 | } |
| @@ -820,8 +638,13 @@ | ||
| 820 | 638 | 'value' => '', |
| 821 | 639 | 'data-placeholder' => 'true', |
| 822 | 640 | ); |
| 823 | 641 | |
| 642 | + if ( $autocomplete && empty( $use_chosen ) ) { | |
| 643 | + // This is required for Slim Select. | |
| 644 | + $placeholder_attributes['data-placeholder'] = 'true'; | |
| 645 | + } | |
| 646 | + | |
| 824 | 647 | FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); |
| 825 | 648 | return true; |
| 826 | 649 | } |
| 827 | 650 | |
| @@ -828,14 +651,12 @@ | ||
| 828 | 651 | return false; |
| 829 | 652 | } |
| 830 | 653 | |
| 831 | 654 | /** |
| 832 | - * Use HTML5 placeholder with js fallback. | |
| 655 | + * Use HMTL5 placeholder with js fallback | |
| 833 | 656 | * |
| 834 | 657 | * @param array $field |
| 835 | 658 | * @param array $add_html |
| 836 | - * | |
| 837 | - * @return void | |
| 838 | 659 | */ |
| 839 | 660 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 840 | 661 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| 841 | 662 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| @@ -841,16 +662,9 @@ | ||
| 841 | 662 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 842 | 663 | } |
| 843 | 664 | } |
| 844 | 665 | |
| 845 | - /** | |
| 846 | - * @param array $field | |
| 847 | - * @param array $add_html | |
| 848 | - * | |
| 849 | - * @return void | |
| 850 | - */ | |
| 851 | 666 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 852 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 853 | 667 | if ( $field['placeholder'] != '' ) { |
| 854 | 668 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 855 | 669 | |
| 856 | 670 | if ( 'select' === $field['type'] ) { |
| @@ -857,30 +671,21 @@ | ||
| 857 | 671 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 858 | 672 | } |
| 859 | 673 | } |
| 860 | 674 | |
| 861 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 862 | 675 | if ( $field['default_value'] != '' ) { |
| 863 | 676 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 864 | 677 | } |
| 865 | 678 | } |
| 866 | 679 | |
| 867 | - /** | |
| 868 | - * @param array $field | |
| 869 | - * @param array $add_html | |
| 870 | - * | |
| 871 | - * @return void | |
| 872 | - */ | |
| 873 | 680 | private static function add_validation_messages( $field, array &$add_html ) { |
| 874 | - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); | |
| 875 | - | |
| 876 | - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { | |
| 681 | + if ( FrmField::is_required( $field ) ) { | |
| 877 | 682 | $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' ); |
| 878 | 683 | $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"'; |
| 879 | 684 | self::maybe_add_html_required( $field, $add_html ); |
| 880 | 685 | } |
| 881 | 686 | |
| 882 | - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) { | |
| 687 | + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) { | |
| 883 | 688 | $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| 884 | 689 | $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"'; |
| 885 | 690 | } |
| 886 | 691 | |
| @@ -889,63 +694,24 @@ | ||
| 889 | 694 | } |
| 890 | 695 | } |
| 891 | 696 | |
| 892 | 697 | /** |
| 893 | - * Returns an array that contains field validation messages status. | |
| 894 | - * | |
| 895 | - * @since 6.9 | |
| 896 | - * | |
| 897 | - * @param array|object $field | |
| 898 | - * | |
| 899 | - * @return array | |
| 900 | - */ | |
| 901 | - private static function get_validation_data_attribute_visibility_info( $field ) { | |
| 902 | - if ( FrmField::get_field_type( $field ) === 'hidden' ) { | |
| 903 | - $field_validation_data_attributes = array( | |
| 904 | - 'data-invmsg' => false, | |
| 905 | - 'data-reqmsg' => false, | |
| 906 | - ); | |
| 907 | - } else { | |
| 908 | - $field_validation_data_attributes = array( | |
| 909 | - 'data-invmsg' => true, | |
| 910 | - 'data-reqmsg' => true, | |
| 911 | - ); | |
| 912 | - } | |
| 913 | - | |
| 914 | - /** | |
| 915 | - * Allows controlling which field validation messages would be included in the field html. | |
| 916 | - * | |
| 917 | - * @since 6.9 | |
| 918 | - * | |
| 919 | - * @param array $field_validation_messages_status | |
| 920 | - * @param array|object $field | |
| 921 | - */ | |
| 922 | - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field ); | |
| 923 | - } | |
| 924 | - | |
| 925 | - /** | |
| 926 | 698 | * @since 5.0.03 |
| 927 | 699 | * |
| 928 | 700 | * @param array $field |
| 929 | 701 | * @param array $add_html |
| 930 | - * | |
| 931 | - * @return void | |
| 932 | 702 | */ |
| 933 | 703 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 934 | 704 | $form = self::get_form_for_js_validation( $field ); |
| 935 | - | |
| 936 | 705 | if ( false === $form ) { |
| 937 | 706 | return; |
| 938 | 707 | } |
| 939 | 708 | |
| 940 | 709 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 941 | - | |
| 942 | - if ( false === $error_body ) { | |
| 943 | - return; | |
| 710 | + if ( false !== $error_body ) { | |
| 711 | + $error_body = urlencode( $error_body ); | |
| 712 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 944 | 713 | } |
| 945 | - | |
| 946 | - $error_body = urlencode( $error_body ); | |
| 947 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 948 | 714 | } |
| 949 | 715 | |
| 950 | 716 | /** |
| 951 | 717 | * @since 5.0.03 |
| @@ -950,24 +716,20 @@ | ||
| 950 | 716 | /** |
| 951 | 717 | * @since 5.0.03 |
| 952 | 718 | * |
| 953 | 719 | * @param array $field |
| 954 | - * | |
| 955 | - * @return false|stdClass false if there is no form object found with JS validation active. | |
| 720 | + * @return stdClass|false false if there is no form object found with JS validation active. | |
| 956 | 721 | */ |
| 957 | 722 | private static function get_form_for_js_validation( $field ) { |
| 958 | 723 | global $frm_vars; |
| 959 | - | |
| 960 | 724 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 961 | 725 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 962 | 726 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 963 | 727 | } |
| 964 | - | |
| 965 | 728 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 966 | 729 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 967 | 730 | } |
| 968 | 731 | } |
| 969 | - | |
| 970 | 732 | return false; |
| 971 | 733 | } |
| 972 | 734 | |
| 973 | 735 | /** |
| @@ -973,10 +735,9 @@ | ||
| 973 | 735 | /** |
| 974 | 736 | * @param stdClass $form |
| 975 | 737 | * @param array $field |
| 976 | 738 | * @param array $errors |
| 977 | - * | |
| 978 | - * @return false|string | |
| 739 | + * @return string|false | |
| 979 | 740 | */ |
| 980 | 741 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 981 | 742 | if ( empty( $field['custom_html'] ) ) { |
| 982 | 743 | return false; |
| @@ -983,16 +744,15 @@ | ||
| 983 | 744 | } |
| 984 | 745 | |
| 985 | 746 | $custom_html = $field['custom_html']; |
| 986 | 747 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 987 | - $start = strpos( $custom_html, '[if error]' ); | |
| 988 | 748 | |
| 749 | + $start = strpos( $custom_html, '[if error]' ); | |
| 989 | 750 | if ( false === $start ) { |
| 990 | 751 | return false; |
| 991 | 752 | } |
| 992 | 753 | |
| 993 | 754 | $end = strpos( $custom_html, '[/if error]' ); |
| 994 | - | |
| 995 | 755 | if ( false === $end || $end < $start ) { |
| 996 | 756 | return false; |
| 997 | 757 | } |
| 998 | 758 | |
| @@ -1003,9 +763,13 @@ | ||
| 1003 | 763 | '<div class="frm_error">[error]</div>', |
| 1004 | 764 | '<div class="frm_error" role="alert">[error]</div>', |
| 1005 | 765 | ); |
| 1006 | 766 | |
| 1007 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 767 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 768 | + return false; | |
| 769 | + } | |
| 770 | + | |
| 771 | + return $error_body; | |
| 1008 | 772 | } |
| 1009 | 773 | |
| 1010 | 774 | /** |
| 1011 | 775 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -1012,16 +776,12 @@ | ||
| 1012 | 776 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 1013 | 777 | * remove it is present if needed. |
| 1014 | 778 | * |
| 1015 | 779 | * @since 3.06.01 |
| 1016 | - * | |
| 1017 | 780 | * @param array $field |
| 1018 | 781 | * @param array $add_html |
| 1019 | - * | |
| 1020 | - * @return void | |
| 1021 | 782 | */ |
| 1022 | 783 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 1023 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1024 | 784 | $excluded_field_types = |
| 1025 | 785 | FrmField::is_radio( $field ) || |
| 1026 | 786 | FrmField::is_checkbox( $field ) || |
| 1027 | 787 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -1026,23 +786,19 @@ | ||
| 1026 | 786 | FrmField::is_checkbox( $field ) || |
| 1027 | 787 | FrmField::is_field_type( $field, 'file' ) || |
| 1028 | 788 | FrmField::is_field_type( $field, 'nps' ) || |
| 1029 | 789 | FrmField::is_field_type( $field, 'scale' ); |
| 1030 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1031 | 790 | |
| 1032 | 791 | if ( $excluded_field_types ) { |
| 1033 | 792 | return; |
| 1034 | 793 | } |
| 1035 | 794 | |
| 1036 | - $add_html['aria-required'] = 'aria-required="true"'; | |
| 795 | + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' ); | |
| 796 | + if ( $include_html ) { | |
| 797 | + $add_html['aria-required'] = 'aria-required="true"'; | |
| 798 | + } | |
| 1037 | 799 | } |
| 1038 | 800 | |
| 1039 | - /** | |
| 1040 | - * @param array $field | |
| 1041 | - * @param array $add_html | |
| 1042 | - * | |
| 1043 | - * @return void | |
| 1044 | - */ | |
| 1045 | 801 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 1046 | 802 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| 1047 | 803 | return; |
| 1048 | 804 | } |
| @@ -1051,25 +807,13 @@ | ||
| 1051 | 807 | unset( $field['shortcodes']['autocomplete'] ); |
| 1052 | 808 | } |
| 1053 | 809 | |
| 1054 | 810 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 1055 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 1056 | - $subfield_name = $field['subfield_name']; | |
| 1057 | - | |
| 1058 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 1059 | - continue; | |
| 1060 | - } | |
| 1061 | - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. | |
| 1062 | - $k = 'aria-invalid'; | |
| 1063 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 1064 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 1065 | - } | |
| 1066 | - | |
| 1067 | - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { | |
| 811 | + if ( 'opt' === $k ) { | |
| 1068 | 812 | continue; |
| 1069 | 813 | } |
| 1070 | 814 | |
| 1071 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 815 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1072 | 816 | $add_html[] = $v; |
| 1073 | 817 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1074 | 818 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1075 | 819 | } else { |
| @@ -1076,128 +820,129 @@ | ||
| 1076 | 820 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 1077 | 821 | } |
| 1078 | 822 | |
| 1079 | 823 | unset( $k, $v ); |
| 1080 | - }//end foreach | |
| 1081 | - } | |
| 1082 | - | |
| 1083 | - /** | |
| 1084 | - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. | |
| 1085 | - * | |
| 1086 | - * @since 6.11.2 | |
| 1087 | - * | |
| 1088 | - * @param string $key The option key. | |
| 1089 | - * | |
| 1090 | - * @return bool | |
| 1091 | - */ | |
| 1092 | - private static function should_allow_input_attribute( $key ) { | |
| 1093 | - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { | |
| 1094 | - return true; | |
| 1095 | 824 | } |
| 1096 | - return FrmAppHelper::input_key_is_safe( $key ); | |
| 1097 | 825 | } |
| 1098 | 826 | |
| 1099 | 827 | /** |
| 1100 | - * Add pattern attribute. | |
| 828 | + * Add pattern attribute | |
| 1101 | 829 | * |
| 1102 | 830 | * @since 3.0 |
| 1103 | 831 | * |
| 1104 | 832 | * @param array $field |
| 1105 | 833 | * @param array $add_html |
| 1106 | - * | |
| 1107 | - * @return void | |
| 1108 | 834 | */ |
| 1109 | 835 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1110 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 1111 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 836 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 1112 | 837 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1113 | 838 | |
| 1114 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1115 | - return; | |
| 1116 | - } | |
| 839 | + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) { | |
| 840 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 1117 | 841 | |
| 1118 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1119 | - $format = substr( $format, 2, - 1 ); | |
| 842 | + if ( $frm_settings->use_html ) { | |
| 843 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 844 | + $format = substr( $format, 2, - 1 ); | |
| 1120 | 845 | |
| 1121 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 846 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 847 | + } | |
| 848 | + } | |
| 1122 | 849 | } |
| 1123 | 850 | |
| 1124 | - /** | |
| 1125 | - * Add product attributes to fields in multi-paged forms. | |
| 1126 | - * | |
| 1127 | - * @param array $field | |
| 1128 | - * @param array $add_html | |
| 1129 | - * | |
| 1130 | - * @return void | |
| 1131 | - */ | |
| 1132 | - private static function add_currency_field_attributes( $field, &$add_html ) { | |
| 1133 | - $type = $field['original_type'] ?? $field['type']; | |
| 1134 | - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true ); | |
| 1135 | - | |
| 1136 | - if ( ! $is_product_field ) { | |
| 1137 | - return; | |
| 851 | + public static function check_value( $opt, $opt_key, $field ) { | |
| 852 | + if ( is_array( $opt ) ) { | |
| 853 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { | |
| 854 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 855 | + } else { | |
| 856 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 857 | + } | |
| 1138 | 858 | } |
| 1139 | 859 | |
| 1140 | - if ( $type === 'total' ) { | |
| 1141 | - $add_html['data-frmtotal'] = 'data-frmtotal'; | |
| 1142 | - } elseif ( $type === 'quantity' ) { | |
| 1143 | - $product_field = FrmField::get_option( $field, 'product_field' ); | |
| 1144 | - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"'; | |
| 1145 | - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) { | |
| 1146 | - // We want to do this only for fields that are hidden because it's | |
| 1147 | - // not their page, hence the check : 'hidden' === $field['type']. | |
| 1148 | - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field ); | |
| 860 | + return $opt; | |
| 861 | + } | |
| 1149 | 862 | |
| 1150 | - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"'; | |
| 863 | + public static function check_label( $opt ) { | |
| 864 | + if ( is_array( $opt ) ) { | |
| 865 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1151 | 866 | } |
| 867 | + | |
| 868 | + return $opt; | |
| 1152 | 869 | } |
| 1153 | 870 | |
| 1154 | 871 | /** |
| 1155 | - * @param array $field | |
| 872 | + * @deprecated 4.0 | |
| 1156 | 873 | */ |
| 1157 | - private static function get_product_price( $field ) { | |
| 1158 | - if ( is_array( $field['value'] ) ) { | |
| 1159 | - // '' is unlikely though, let's just do it to prevent warnings | |
| 1160 | - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] ) | |
| 1161 | - ? $field['value'][ $field['opt_key'] ] | |
| 1162 | - : ''; | |
| 1163 | - } else { | |
| 1164 | - $value = $field['value']; | |
| 874 | + public static function update_ajax_option() { | |
| 875 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 876 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 877 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 878 | + | |
| 879 | + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); | |
| 880 | + if ( ! $field_id ) { | |
| 881 | + wp_die(); | |
| 1165 | 882 | } |
| 1166 | 883 | |
| 1167 | - $field_obj = FrmFieldFactory::get_field_object( $field['id'] ); | |
| 884 | + $field = FrmField::getOne( $field_id ); | |
| 1168 | 885 | |
| 1169 | - if ( method_exists( $field_obj, 'get_posted_price' ) ) { | |
| 1170 | - return $field_obj->get_posted_price( $value ); | |
| 886 | + if ( isset( $_POST['separate_value'] ) ) { | |
| 887 | + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1; | |
| 888 | + | |
| 889 | + $field->field_options['separate_value'] = $new_val; | |
| 890 | + unset( $new_val ); | |
| 1171 | 891 | } |
| 1172 | 892 | |
| 1173 | - return $value; | |
| 893 | + FrmField::update( | |
| 894 | + $field_id, | |
| 895 | + array( | |
| 896 | + 'field_options' => $field->field_options, | |
| 897 | + 'form_id' => $field->form_id, | |
| 898 | + ) | |
| 899 | + ); | |
| 900 | + wp_die(); | |
| 1174 | 901 | } |
| 1175 | 902 | |
| 1176 | 903 | /** |
| 1177 | - * @param mixed $opt | |
| 1178 | - * @param mixed $opt_key | |
| 1179 | - * @param array|object $field | |
| 904 | + * @deprecated 4.0 | |
| 905 | + */ | |
| 906 | + public static function import_choices() { | |
| 907 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 908 | + wp_die(); | |
| 909 | + } | |
| 910 | + | |
| 911 | + /** | |
| 912 | + * Add Single Option or Other Option. | |
| 1180 | 913 | * |
| 1181 | - * @return mixed | |
| 914 | + * @deprecated 4.0 Moved to Pro for Other option only. | |
| 1182 | 915 | */ |
| 1183 | - public static function check_value( $opt, $opt_key, $field ) { | |
| 1184 | - if ( is_array( $opt ) ) { | |
| 1185 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { | |
| 1186 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 1187 | - } else { | |
| 1188 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 1189 | - } | |
| 1190 | - } | |
| 916 | + public static function add_option() { | |
| 917 | + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' ); | |
| 918 | + } | |
| 1191 | 919 | |
| 1192 | - return $opt; | |
| 920 | + /** | |
| 921 | + * @deprecated 4.0 | |
| 922 | + */ | |
| 923 | + public static function update_order() { | |
| 924 | + FrmDeprecated::update_order(); | |
| 1193 | 925 | } |
| 1194 | 926 | |
| 1195 | 927 | /** |
| 1196 | - * @param mixed $opt | |
| 928 | + * @deprecated 3.0 | |
| 929 | + * @codeCoverageIgnore | |
| 930 | + */ | |
| 931 | + public static function edit_name( $field = 'name', $id = '' ) { | |
| 932 | + FrmDeprecated::edit_name( $field, $id ); | |
| 933 | + } | |
| 934 | + | |
| 935 | + /** | |
| 936 | + * @deprecated 3.0 | |
| 937 | + * @codeCoverageIgnore | |
| 1197 | 938 | * |
| 1198 | - * @return mixed | |
| 939 | + * @param int $field_id | |
| 940 | + * @param array $values | |
| 941 | + * @param int $form_id | |
| 942 | + * | |
| 943 | + * @return array | |
| 1199 | 944 | */ |
| 1200 | - public static function check_label( $opt ) { | |
| 1201 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 945 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { | |
| 946 | + return FrmDeprecated::include_single_field( $field_id, $values, $form_id ); | |
| 1202 | 947 | } |
| 1203 | 948 | } |