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