| @@ -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 | |
| @@ -372,72 +324,57 @@ | ||
| 372 | 324 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; |
| 373 | 325 | } |
| 374 | 326 | |
| 375 | 327 | /** |
| 376 | - * @since 6.9.1 | |
| 377 | - * | |
| 378 | - * @return FrmFieldSelectionData | |
| 379 | - */ | |
| 380 | - private static function maybe_define_field_selection_data() { | |
| 381 | - if ( ! isset( self::$field_selection_data ) ) { | |
| 382 | - self::$field_selection_data = new FrmFieldSelectionData(); | |
| 383 | - } | |
| 384 | - return self::$field_selection_data; | |
| 385 | - } | |
| 386 | - | |
| 387 | - /** | |
| 388 | 328 | * Get the list of default value types that can be toggled in the builder. |
| 389 | 329 | * |
| 390 | 330 | * @since 4.0 |
| 391 | - * | |
| 392 | - * @param array $field | |
| 393 | - * @param array $atts | |
| 394 | - * | |
| 395 | 331 | * @return array |
| 396 | 332 | */ |
| 397 | 333 | private static function default_value_types( $field, $atts ) { |
| 398 | 334 | $types = array( |
| 399 | - 'default_value' => array( | |
| 335 | + 'default_value' => array( | |
| 400 | 336 | 'class' => '', |
| 401 | - 'icon' => 'frmfont frm_text2_icon', | |
| 402 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 337 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 338 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 403 | 339 | 'data' => array( |
| 404 | 340 | 'frmshow' => '#default-value-for-', |
| 405 | 341 | ), |
| 406 | 342 | ), |
| 407 | - 'calc' => array( | |
| 408 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 409 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 410 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 411 | - '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( | |
| 412 | 348 | 'medium' => 'calculations', |
| 413 | 349 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 414 | 350 | ), |
| 415 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 416 | 351 | ), |
| 417 | 352 | 'get_values_field' => array( |
| 418 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 419 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 420 | - 'icon' => 'frmfont frm_search_icon', | |
| 421 | - '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( | |
| 422 | 357 | 'medium' => 'lookup', |
| 423 | 358 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 424 | 359 | ), |
| 425 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 426 | 360 | ), |
| 427 | 361 | ); |
| 428 | 362 | |
| 429 | 363 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| 430 | 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 | + | |
| 431 | 370 | // Set active class. |
| 432 | 371 | $settings = array_keys( $types ); |
| 433 | 372 | $active = 'default_value'; |
| 434 | 373 | |
| 435 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 436 | - foreach ( $settings as $type ) { | |
| 437 | - if ( ! empty( $field[ $type ] ) ) { | |
| 438 | - $active = $type; | |
| 439 | - } | |
| 374 | + foreach ( $settings as $type ) { | |
| 375 | + if ( ! empty( $field[ $type ] ) ) { | |
| 376 | + $active = $type; | |
| 440 | 377 | } |
| 441 | 378 | } |
| 442 | 379 | |
| 443 | 380 | $types[ $active ]['class'] .= ' current'; |
| @@ -445,13 +382,8 @@ | ||
| 445 | 382 | |
| 446 | 383 | return $types; |
| 447 | 384 | } |
| 448 | 385 | |
| 449 | - /** | |
| 450 | - * @param string $type | |
| 451 | - * | |
| 452 | - * @return string | |
| 453 | - */ | |
| 454 | 386 | public static function change_type( $type ) { |
| 455 | 387 | $type_switch = array( |
| 456 | 388 | 'scale' => 'radio', |
| 457 | 389 | 'star' => 'radio', |
| @@ -459,9 +391,8 @@ | ||
| 459 | 391 | 'rte' => 'textarea', |
| 460 | 392 | 'website' => 'url', |
| 461 | 393 | 'image' => 'url', |
| 462 | 394 | ); |
| 463 | - | |
| 464 | 395 | if ( isset( $type_switch[ $type ] ) ) { |
| 465 | 396 | $type = $type_switch[ $type ]; |
| 466 | 397 | } |
| 467 | 398 | |
| @@ -469,22 +400,24 @@ | ||
| 469 | 400 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 470 | 401 | // The credit_card key is set for backward compatibility. |
| 471 | 402 | unset( $pro_fields['credit_card'] ); |
| 472 | 403 | |
| 473 | - 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; | |
| 474 | 409 | } |
| 475 | 410 | |
| 476 | 411 | /** |
| 477 | - * @param array $settings | |
| 478 | - * @param FrmFieldType|null $field_info | |
| 412 | + * @param array $settings | |
| 413 | + * @param object $field_info | |
| 479 | 414 | * |
| 480 | 415 | * @return array |
| 481 | 416 | */ |
| 482 | 417 | public static function display_field_options( $settings, $field_info = null ) { |
| 483 | 418 | if ( $field_info ) { |
| 484 | - $settings = $field_info->display_field_settings(); | |
| 485 | - | |
| 486 | - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public. | |
| 419 | + $settings = $field_info->display_field_settings(); | |
| 487 | 420 | $settings['field_data'] = $field_info->field; |
| 488 | 421 | } |
| 489 | 422 | |
| 490 | 423 | return apply_filters( 'frm_display_field_options', $settings ); |
| @@ -494,32 +427,14 @@ | ||
| 494 | 427 | * Display the format option |
| 495 | 428 | * |
| 496 | 429 | * @since 3.0 |
| 497 | 430 | * |
| 498 | - * @param array $field Field data. | |
| 499 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 500 | - * | |
| 501 | - * @return void | |
| 431 | + * @param array $field | |
| 502 | 432 | */ |
| 503 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 504 | - $attributes = array( | |
| 505 | - 'class' => 'frm-has-modal', | |
| 506 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 507 | - ); | |
| 508 | - | |
| 509 | - if ( $is_hidden ) { | |
| 510 | - $attributes['class'] .= ' frm_hidden'; | |
| 511 | - } | |
| 512 | - | |
| 513 | - 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' ); | |
| 514 | 435 | } |
| 515 | 436 | |
| 516 | - /** | |
| 517 | - * @param array $field | |
| 518 | - * @param bool $echo | |
| 519 | - * | |
| 520 | - * @return string | |
| 521 | - */ | |
| 522 | 437 | public static function input_html( $field, $echo = true ) { |
| 523 | 438 | $class = array(); |
| 524 | 439 | self::add_input_classes( $field, $class ); |
| 525 | 440 | |
| @@ -545,20 +460,14 @@ | ||
| 545 | 460 | |
| 546 | 461 | return $add_html; |
| 547 | 462 | } |
| 548 | 463 | |
| 549 | - /** | |
| 550 | - * @param array $field | |
| 551 | - * @param array $class | |
| 552 | - * | |
| 553 | - * @return void | |
| 554 | - */ | |
| 555 | 464 | private static function add_input_classes( $field, array &$class ) { |
| 556 | - if ( ! empty( $field['input_class'] ) ) { | |
| 465 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { | |
| 557 | 466 | $class[] = $field['input_class']; |
| 558 | 467 | } |
| 559 | 468 | |
| 560 | - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) { | |
| 469 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { | |
| 561 | 470 | return; |
| 562 | 471 | } |
| 563 | 472 | |
| 564 | 473 | if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
| @@ -565,14 +474,8 @@ | ||
| 565 | 474 | $class[] = 'auto_width'; |
| 566 | 475 | } |
| 567 | 476 | } |
| 568 | 477 | |
| 569 | - /** | |
| 570 | - * @param array $field | |
| 571 | - * @param array $add_html | |
| 572 | - * | |
| 573 | - * @return void | |
| 574 | - */ | |
| 575 | 478 | private static function add_html_size( $field, array &$add_html ) { |
| 576 | 479 | $size_fields = array( |
| 577 | 480 | 'select', |
| 578 | 481 | 'data', |
| @@ -581,9 +484,9 @@ | ||
| 581 | 484 | 'file', |
| 582 | 485 | 'lookup', |
| 583 | 486 | ); |
| 584 | 487 | |
| 585 | - 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 ) ) { | |
| 586 | 489 | return; |
| 587 | 490 | } |
| 588 | 491 | |
| 589 | 492 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| @@ -600,14 +503,8 @@ | ||
| 600 | 503 | |
| 601 | 504 | self::add_html_cols( $field, $add_html ); |
| 602 | 505 | } |
| 603 | 506 | |
| 604 | - /** | |
| 605 | - * @param array $field | |
| 606 | - * @param array $add_html | |
| 607 | - * | |
| 608 | - * @return void | |
| 609 | - */ | |
| 610 | 507 | private static function add_html_cols( $field, array &$add_html ) { |
| 611 | 508 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| 612 | 509 | return; |
| 613 | 510 | } |
| @@ -619,9 +516,9 @@ | ||
| 619 | 516 | 'rem' => 0.444, |
| 620 | 517 | 'em' => 0.544, |
| 621 | 518 | ); |
| 622 | 519 | |
| 623 | - // Include "col" for valid html | |
| 520 | + // include "col" for valid html | |
| 624 | 521 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 625 | 522 | |
| 626 | 523 | if ( ! isset( $calc[ $unit ] ) ) { |
| 627 | 524 | return; |
| @@ -626,18 +523,13 @@ | ||
| 626 | 523 | if ( ! isset( $calc[ $unit ] ) ) { |
| 627 | 524 | return; |
| 628 | 525 | } |
| 629 | 526 | |
| 630 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 527 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 528 | + | |
| 631 | 529 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 632 | 530 | } |
| 633 | 531 | |
| 634 | - /** | |
| 635 | - * @param array $field | |
| 636 | - * @param array $add_html | |
| 637 | - * | |
| 638 | - * @return void | |
| 639 | - */ | |
| 640 | 532 | private static function add_html_length( $field, array &$add_html ) { |
| 641 | 533 | // Check for max setting and if this field accepts maxlength. |
| 642 | 534 | $fields = array( |
| 643 | 535 | 'textarea', |
| @@ -645,9 +537,9 @@ | ||
| 645 | 537 | 'hidden', |
| 646 | 538 | 'file', |
| 647 | 539 | ); |
| 648 | 540 | |
| 649 | - 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 ) ) { | |
| 650 | 542 | return; |
| 651 | 543 | } |
| 652 | 544 | |
| 653 | 545 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| @@ -657,17 +549,9 @@ | ||
| 657 | 549 | |
| 658 | 550 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
| 659 | 551 | } |
| 660 | 552 | |
| 661 | - /** | |
| 662 | - * @param array $field | |
| 663 | - * @param array $add_html | |
| 664 | - * @param array $class | |
| 665 | - * | |
| 666 | - * @return void | |
| 667 | - */ | |
| 668 | 553 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 669 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 670 | 554 | if ( $field['default_value'] != '' ) { |
| 671 | 555 | if ( is_array( $field['default_value'] ) ) { |
| 672 | 556 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 673 | 557 | } else { |
| @@ -675,16 +559,26 @@ | ||
| 675 | 559 | } |
| 676 | 560 | } |
| 677 | 561 | |
| 678 | 562 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 679 | - | |
| 680 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 681 | 563 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 682 | - // Don't include a json placeholder | |
| 564 | + // don't include a json placeholder | |
| 683 | 565 | return; |
| 684 | 566 | } |
| 685 | 567 | |
| 686 | - 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 | + } | |
| 687 | 581 | } |
| 688 | 582 | |
| 689 | 583 | /** |
| 690 | 584 | * Prepares field placeholder. |
| @@ -691,13 +585,14 @@ | ||
| 691 | 585 | * |
| 692 | 586 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 693 | 587 | * |
| 694 | 588 | * @param array $field Field array. |
| 695 | - * | |
| 696 | 589 | * @return string |
| 697 | 590 | */ |
| 698 | 591 | private static function prepare_placeholder( $field ) { |
| 699 | - return $field['placeholder'] ?? ''; | |
| 592 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 593 | + | |
| 594 | + return $placeholder; | |
| 700 | 595 | } |
| 701 | 596 | |
| 702 | 597 | /** |
| 703 | 598 | * If the label position is "inside", |
| @@ -718,17 +613,13 @@ | ||
| 718 | 613 | * Maybe add a blank placeholder option before any options |
| 719 | 614 | * in a dropdown. |
| 720 | 615 | * |
| 721 | 616 | * @since 4.04 |
| 722 | - * | |
| 723 | - * @param array|object $field | |
| 724 | - * | |
| 725 | 617 | * @return bool True if placeholder was added. |
| 726 | 618 | */ |
| 727 | 619 | public static function add_placeholder_to_select( $field ) { |
| 728 | 620 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 729 | - | |
| 730 | - if ( ! $placeholder ) { | |
| 621 | + if ( empty( $placeholder ) ) { | |
| 731 | 622 | $placeholder = self::get_default_value_from_name( $field ); |
| 732 | 623 | } |
| 733 | 624 | |
| 734 | 625 | $use_placeholder = $placeholder; |
| @@ -735,9 +626,8 @@ | ||
| 735 | 626 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 736 | 627 | |
| 737 | 628 | if ( $autocomplete ) { |
| 738 | 629 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 739 | - | |
| 740 | 630 | if ( $use_chosen ) { |
| 741 | 631 | $use_placeholder = ''; |
| 742 | 632 | } |
| 743 | 633 | } |
| @@ -748,8 +638,13 @@ | ||
| 748 | 638 | 'value' => '', |
| 749 | 639 | 'data-placeholder' => 'true', |
| 750 | 640 | ); |
| 751 | 641 | |
| 642 | + if ( $autocomplete && empty( $use_chosen ) ) { | |
| 643 | + // This is required for Slim Select. | |
| 644 | + $placeholder_attributes['data-placeholder'] = 'true'; | |
| 645 | + } | |
| 646 | + | |
| 752 | 647 | FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); |
| 753 | 648 | return true; |
| 754 | 649 | } |
| 755 | 650 | |
| @@ -756,14 +651,12 @@ | ||
| 756 | 651 | return false; |
| 757 | 652 | } |
| 758 | 653 | |
| 759 | 654 | /** |
| 760 | - * Use HTML5 placeholder with js fallback. | |
| 655 | + * Use HMTL5 placeholder with js fallback | |
| 761 | 656 | * |
| 762 | 657 | * @param array $field |
| 763 | 658 | * @param array $add_html |
| 764 | - * | |
| 765 | - * @return void | |
| 766 | 659 | */ |
| 767 | 660 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 768 | 661 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| 769 | 662 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| @@ -769,16 +662,9 @@ | ||
| 769 | 662 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 770 | 663 | } |
| 771 | 664 | } |
| 772 | 665 | |
| 773 | - /** | |
| 774 | - * @param array $field | |
| 775 | - * @param array $add_html | |
| 776 | - * | |
| 777 | - * @return void | |
| 778 | - */ | |
| 779 | 666 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 780 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 781 | 667 | if ( $field['placeholder'] != '' ) { |
| 782 | 668 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 783 | 669 | |
| 784 | 670 | if ( 'select' === $field['type'] ) { |
| @@ -785,30 +671,21 @@ | ||
| 785 | 671 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 786 | 672 | } |
| 787 | 673 | } |
| 788 | 674 | |
| 789 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 790 | 675 | if ( $field['default_value'] != '' ) { |
| 791 | 676 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 792 | 677 | } |
| 793 | 678 | } |
| 794 | 679 | |
| 795 | - /** | |
| 796 | - * @param array $field | |
| 797 | - * @param array $add_html | |
| 798 | - * | |
| 799 | - * @return void | |
| 800 | - */ | |
| 801 | 680 | private static function add_validation_messages( $field, array &$add_html ) { |
| 802 | - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); | |
| 803 | - | |
| 804 | - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { | |
| 681 | + if ( FrmField::is_required( $field ) ) { | |
| 805 | 682 | $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' ); |
| 806 | 683 | $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"'; |
| 807 | 684 | self::maybe_add_html_required( $field, $add_html ); |
| 808 | 685 | } |
| 809 | 686 | |
| 810 | - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) { | |
| 687 | + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) { | |
| 811 | 688 | $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| 812 | 689 | $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"'; |
| 813 | 690 | } |
| 814 | 691 | |
| @@ -817,63 +694,24 @@ | ||
| 817 | 694 | } |
| 818 | 695 | } |
| 819 | 696 | |
| 820 | 697 | /** |
| 821 | - * Returns an array that contains field validation messages status. | |
| 822 | - * | |
| 823 | - * @since 6.9 | |
| 824 | - * | |
| 825 | - * @param array|object $field | |
| 826 | - * | |
| 827 | - * @return array | |
| 828 | - */ | |
| 829 | - private static function get_validation_data_attribute_visibility_info( $field ) { | |
| 830 | - if ( FrmField::get_field_type( $field ) === 'hidden' ) { | |
| 831 | - $field_validation_data_attributes = array( | |
| 832 | - 'data-invmsg' => false, | |
| 833 | - 'data-reqmsg' => false, | |
| 834 | - ); | |
| 835 | - } else { | |
| 836 | - $field_validation_data_attributes = array( | |
| 837 | - 'data-invmsg' => true, | |
| 838 | - 'data-reqmsg' => true, | |
| 839 | - ); | |
| 840 | - } | |
| 841 | - | |
| 842 | - /** | |
| 843 | - * Allows controlling which field validation messages would be included in the field html. | |
| 844 | - * | |
| 845 | - * @since 6.9 | |
| 846 | - * | |
| 847 | - * @param array $field_validation_messages_status | |
| 848 | - * @param array|object $field | |
| 849 | - */ | |
| 850 | - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field ); | |
| 851 | - } | |
| 852 | - | |
| 853 | - /** | |
| 854 | 698 | * @since 5.0.03 |
| 855 | 699 | * |
| 856 | 700 | * @param array $field |
| 857 | 701 | * @param array $add_html |
| 858 | - * | |
| 859 | - * @return void | |
| 860 | 702 | */ |
| 861 | 703 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 862 | 704 | $form = self::get_form_for_js_validation( $field ); |
| 863 | - | |
| 864 | 705 | if ( false === $form ) { |
| 865 | 706 | return; |
| 866 | 707 | } |
| 867 | 708 | |
| 868 | 709 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 869 | - | |
| 870 | - if ( false === $error_body ) { | |
| 871 | - 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 ) . '"'; | |
| 872 | 713 | } |
| 873 | - | |
| 874 | - $error_body = urlencode( $error_body ); | |
| 875 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 876 | 714 | } |
| 877 | 715 | |
| 878 | 716 | /** |
| 879 | 717 | * @since 5.0.03 |
| @@ -878,24 +716,20 @@ | ||
| 878 | 716 | /** |
| 879 | 717 | * @since 5.0.03 |
| 880 | 718 | * |
| 881 | 719 | * @param array $field |
| 882 | - * | |
| 883 | - * @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. | |
| 884 | 721 | */ |
| 885 | 722 | private static function get_form_for_js_validation( $field ) { |
| 886 | 723 | global $frm_vars; |
| 887 | - | |
| 888 | 724 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 889 | 725 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 890 | 726 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 891 | 727 | } |
| 892 | - | |
| 893 | 728 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 894 | 729 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 895 | 730 | } |
| 896 | 731 | } |
| 897 | - | |
| 898 | 732 | return false; |
| 899 | 733 | } |
| 900 | 734 | |
| 901 | 735 | /** |
| @@ -901,10 +735,9 @@ | ||
| 901 | 735 | /** |
| 902 | 736 | * @param stdClass $form |
| 903 | 737 | * @param array $field |
| 904 | 738 | * @param array $errors |
| 905 | - * | |
| 906 | - * @return false|string | |
| 739 | + * @return string|false | |
| 907 | 740 | */ |
| 908 | 741 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 909 | 742 | if ( empty( $field['custom_html'] ) ) { |
| 910 | 743 | return false; |
| @@ -911,16 +744,15 @@ | ||
| 911 | 744 | } |
| 912 | 745 | |
| 913 | 746 | $custom_html = $field['custom_html']; |
| 914 | 747 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 915 | - $start = strpos( $custom_html, '[if error]' ); | |
| 916 | 748 | |
| 749 | + $start = strpos( $custom_html, '[if error]' ); | |
| 917 | 750 | if ( false === $start ) { |
| 918 | 751 | return false; |
| 919 | 752 | } |
| 920 | 753 | |
| 921 | 754 | $end = strpos( $custom_html, '[/if error]' ); |
| 922 | - | |
| 923 | 755 | if ( false === $end || $end < $start ) { |
| 924 | 756 | return false; |
| 925 | 757 | } |
| 926 | 758 | |
| @@ -931,9 +763,13 @@ | ||
| 931 | 763 | '<div class="frm_error">[error]</div>', |
| 932 | 764 | '<div class="frm_error" role="alert">[error]</div>', |
| 933 | 765 | ); |
| 934 | 766 | |
| 935 | - 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; | |
| 936 | 772 | } |
| 937 | 773 | |
| 938 | 774 | /** |
| 939 | 775 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -940,16 +776,12 @@ | ||
| 940 | 776 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 941 | 777 | * remove it is present if needed. |
| 942 | 778 | * |
| 943 | 779 | * @since 3.06.01 |
| 944 | - * | |
| 945 | 780 | * @param array $field |
| 946 | 781 | * @param array $add_html |
| 947 | - * | |
| 948 | - * @return void | |
| 949 | 782 | */ |
| 950 | 783 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 951 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 952 | 784 | $excluded_field_types = |
| 953 | 785 | FrmField::is_radio( $field ) || |
| 954 | 786 | FrmField::is_checkbox( $field ) || |
| 955 | 787 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -954,23 +786,19 @@ | ||
| 954 | 786 | FrmField::is_checkbox( $field ) || |
| 955 | 787 | FrmField::is_field_type( $field, 'file' ) || |
| 956 | 788 | FrmField::is_field_type( $field, 'nps' ) || |
| 957 | 789 | FrmField::is_field_type( $field, 'scale' ); |
| 958 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 959 | 790 | |
| 960 | 791 | if ( $excluded_field_types ) { |
| 961 | 792 | return; |
| 962 | 793 | } |
| 963 | 794 | |
| 964 | - $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 | + } | |
| 965 | 799 | } |
| 966 | 800 | |
| 967 | - /** | |
| 968 | - * @param array $field | |
| 969 | - * @param array $add_html | |
| 970 | - * | |
| 971 | - * @return void | |
| 972 | - */ | |
| 973 | 801 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 974 | 802 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| 975 | 803 | return; |
| 976 | 804 | } |
| @@ -979,25 +807,13 @@ | ||
| 979 | 807 | unset( $field['shortcodes']['autocomplete'] ); |
| 980 | 808 | } |
| 981 | 809 | |
| 982 | 810 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 983 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 984 | - $subfield_name = $field['subfield_name']; | |
| 985 | - | |
| 986 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 987 | - continue; | |
| 988 | - } | |
| 989 | - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. | |
| 990 | - $k = 'aria-invalid'; | |
| 991 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 992 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 993 | - } | |
| 994 | - | |
| 995 | - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { | |
| 811 | + if ( 'opt' === $k ) { | |
| 996 | 812 | continue; |
| 997 | 813 | } |
| 998 | 814 | |
| 999 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 815 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1000 | 816 | $add_html[] = $v; |
| 1001 | 817 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1002 | 818 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1003 | 819 | } else { |
| @@ -1004,65 +820,41 @@ | ||
| 1004 | 820 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 1005 | 821 | } |
| 1006 | 822 | |
| 1007 | 823 | unset( $k, $v ); |
| 1008 | - }//end foreach | |
| 1009 | - } | |
| 1010 | - | |
| 1011 | - /** | |
| 1012 | - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. | |
| 1013 | - * | |
| 1014 | - * @since 6.11.2 | |
| 1015 | - * | |
| 1016 | - * @param string $key The option key. | |
| 1017 | - * | |
| 1018 | - * @return bool | |
| 1019 | - */ | |
| 1020 | - private static function should_allow_input_attribute( $key ) { | |
| 1021 | - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { | |
| 1022 | - return true; | |
| 1023 | 824 | } |
| 1024 | - return FrmAppHelper::input_key_is_safe( $key ); | |
| 1025 | 825 | } |
| 1026 | 826 | |
| 1027 | 827 | /** |
| 1028 | - * Add pattern attribute. | |
| 828 | + * Add pattern attribute | |
| 1029 | 829 | * |
| 1030 | 830 | * @since 3.0 |
| 1031 | 831 | * |
| 1032 | 832 | * @param array $field |
| 1033 | 833 | * @param array $add_html |
| 1034 | - * | |
| 1035 | - * @return void | |
| 1036 | 834 | */ |
| 1037 | 835 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1038 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 1039 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 836 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 1040 | 837 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1041 | 838 | |
| 1042 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1043 | - return; | |
| 1044 | - } | |
| 839 | + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) { | |
| 840 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 1045 | 841 | |
| 1046 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1047 | - $format = substr( $format, 2, - 1 ); | |
| 842 | + if ( $frm_settings->use_html ) { | |
| 843 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 844 | + $format = substr( $format, 2, - 1 ); | |
| 1048 | 845 | |
| 1049 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 846 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 847 | + } | |
| 848 | + } | |
| 1050 | 849 | } |
| 1051 | 850 | |
| 1052 | - /** | |
| 1053 | - * @param mixed $opt | |
| 1054 | - * @param mixed $opt_key | |
| 1055 | - * @param array|object $field | |
| 1056 | - * | |
| 1057 | - * @return mixed | |
| 1058 | - */ | |
| 1059 | 851 | public static function check_value( $opt, $opt_key, $field ) { |
| 1060 | 852 | if ( is_array( $opt ) ) { |
| 1061 | 853 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1062 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 854 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1063 | 855 | } else { |
| 1064 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 856 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1065 | 857 | } |
| 1066 | 858 | } |
| 1067 | 859 | |
| 1068 | 860 | return $opt; |
| @@ -1067,13 +859,90 @@ | ||
| 1067 | 859 | |
| 1068 | 860 | return $opt; |
| 1069 | 861 | } |
| 1070 | 862 | |
| 863 | + public static function check_label( $opt ) { | |
| 864 | + if ( is_array( $opt ) ) { | |
| 865 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 866 | + } | |
| 867 | + | |
| 868 | + return $opt; | |
| 869 | + } | |
| 870 | + | |
| 1071 | 871 | /** |
| 1072 | - * @param mixed $opt | |
| 872 | + * @deprecated 4.0 | |
| 873 | + */ | |
| 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(); | |
| 882 | + } | |
| 883 | + | |
| 884 | + $field = FrmField::getOne( $field_id ); | |
| 885 | + | |
| 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 ); | |
| 891 | + } | |
| 892 | + | |
| 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(); | |
| 901 | + } | |
| 902 | + | |
| 903 | + /** | |
| 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. | |
| 1073 | 913 | * |
| 1074 | - * @return mixed | |
| 914 | + * @deprecated 4.0 Moved to Pro for Other option only. | |
| 1075 | 915 | */ |
| 1076 | - public static function check_label( $opt ) { | |
| 1077 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 916 | + public static function add_option() { | |
| 917 | + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' ); | |
| 918 | + } | |
| 919 | + | |
| 920 | + /** | |
| 921 | + * @deprecated 4.0 | |
| 922 | + */ | |
| 923 | + public static function update_order() { | |
| 924 | + FrmDeprecated::update_order(); | |
| 925 | + } | |
| 926 | + | |
| 927 | + /** | |
| 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 | |
| 938 | + * | |
| 939 | + * @param int $field_id | |
| 940 | + * @param array $values | |
| 941 | + * @param int $form_id | |
| 942 | + * | |
| 943 | + * @return array | |
| 944 | + */ | |
| 945 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { | |
| 946 | + return FrmDeprecated::include_single_field( $field_id, $values, $form_id ); | |
| 1078 | 947 | } |
| 1079 | 948 | } |