PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/fields/FrmFieldName.php +5 -127 6.266.7 View file →
@@ -2,9 +2,8 @@
2 2 /**
3 3 * Name field
4 4 *
5 5 * @package Formidable
6 - *
7 6 * @since 4.11
8 7 */
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -13,19 +12,11 @@
13 12
14 13 class FrmFieldName extends FrmFieldCombo {
15 14
16 15 /**
17 - * Track the first name field ID in forms.
18 - *
19 - * @var array Array with keys are form ID and values are name field IDs.
20 - */
21 - private static $first_name_field_ids = array();
22 -
23 - /**
24 16 * Field name.
25 17 *
26 18 * @var string
27 - *
28 19 * @since 3.0
29 20 */
30 21 protected $type = 'name';
31 22
@@ -32,25 +23,20 @@
32 23 /**
33 24 * Could this field hold email values?
34 25 *
35 26 * @var bool
36 - *
37 27 * @since 3.0
38 28 */
39 29 protected $holds_email_values = true;
40 30
41 - /**
42 - * @param array|int|object $field
43 - * @param string $type
44 - */
45 - public function __construct( $field = 0, $type = '' ) {
31 + public function __construct( $field = '', $type = '' ) {
46 32 parent::__construct( $field, $type );
47 33
48 34 $this->register_sub_fields(
49 35 array(
50 - 'first' => __( 'First Name', 'formidable' ),
51 - 'middle' => __( 'Middle Name', 'formidable' ),
52 - 'last' => __( 'Last Name', 'formidable' ),
36 + 'first' => __( 'First', 'formidable' ),
37 + 'middle' => __( 'Middle', 'formidable' ),
38 + 'last' => __( 'Last', 'formidable' ),
53 39 )
54 40 );
55 41 }
56 42
@@ -92,9 +78,8 @@
92 78 * @return string
93 79 */
94 80 protected function get_name_layout() {
95 81 $name_layout = FrmField::get_option( $this->field, 'name_layout' );
96 -
97 82 if ( ! $name_layout ) {
98 83 $name_layout = 'first_last';
99 84 }
100 85 return $name_layout;
@@ -139,9 +124,8 @@
139 124 * This also handles the shortcode output. Support [id], [id show=first], [id show=last], [id show=middle].
140 125 *
141 126 * @param mixed $value Field value before processing.
142 127 * @param array $atts Shortcode attributes.
143 - *
144 128 * @return string Most of cases, this will return string.
145 129 */
146 130 protected function prepare_display_value( $value, $atts ) {
147 131 if ( ! is_array( $value ) ) {
@@ -150,9 +134,9 @@
150 134
151 135 $name_layout = $this->get_name_layout();
152 136
153 137 if ( ! empty( $atts['show'] ) ) {
154 - return $value[ $atts['show'] ] ?? '';
138 + return isset( $value[ $atts['show'] ] ) ? $value[ $atts['show'] ] : '';
155 139 }
156 140
157 141 $value = wp_parse_args(
158 142 $value,
@@ -181,10 +165,8 @@
181 165
182 166 /**
183 167 * @since 4.0.04
184 168 *
185 - * @param array|string $value
186 - *
187 169 * @return void
188 170 */
189 171 public function sanitize_value( &$value ) {
190 172 FrmAppHelper::sanitize_value( 'sanitize_text_field', $value );
@@ -193,9 +175,8 @@
193 175 /**
194 176 * Validate field.
195 177 *
196 178 * @param array $args Arguments. Includes `errors`, `value`.
197 - *
198 179 * @return array Errors array.
199 180 */
200 181 public function validate( $args ) {
201 182 /**
@@ -254,110 +235,7 @@
254 235 protected function get_inputs_container_attrs() {
255 236 $attrs = parent::get_inputs_container_attrs();
256 237
257 238 $attrs['data-name-layout'] = $this->get_name_layout();
258 - return $attrs;
259 - }
260 -
261 - /**
262 - * Maybe show a warning if a name field is using a description that is not descriptive enough.
263 - * Prior to version 6.16, First and Last were the default values, but this has been updated to
264 - * improve accessibility.
265 - *
266 - * @since 6.16
267 - *
268 - * @param array $args
269 - *
270 - * @return void
271 - */
272 - public function show_after_default( $args ) {
273 - echo '<div class="frm-mt-xs">';
274 - parent::show_after_default( $args );
275 - echo '</div>';
276 -
277 - /**
278 - * @var array $field
279 - */
280 - $field = $args['field'];
281 -
282 - $show_warning = false;
283 -
284 - foreach ( $this->sub_fields as $name => $sub_field ) {
285 - $description = FrmField::get_option( $field, $sub_field['name'] . '_desc' );
286 -
287 - if ( in_array( $description, array( 'First', 'Last' ), true ) ) {
288 - $show_warning = true;
289 - break;
290 - }
291 - }
292 -
293 - if ( ! $show_warning ) {
294 - return;
295 - }
296 - ?>
297 - <div class="frm_warning_style">
298 - <?php
299 - FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon', array( 'style' => 'width:24px' ) );
300 - echo ' ';
301 - esc_html_e( 'Subfield descriptions are read by screen readers. Enhance accessibility by using complete labels, like "First Name" instead of "First".', 'formidable' );
302 - ?>
303 - </div>
304 - <?php
305 - }
306 -
307 - /**
308 - * Tracks the first name field ID in a form.
309 - *
310 - * @since 6.26
311 - *
312 - * @param object[] $fields Array of fields in a form.
313 - *
314 - * @return void
315 - */
316 - public static function track_first_name_field( $fields ) {
317 - foreach ( $fields as $field ) {
318 - if ( 'name' === $field->type ) {
319 - self::$first_name_field_ids[ $field->form_id ] = $field->id;
320 - return;
321 - }
322 - }
323 - }
324 -
325 - /**
326 - * Gets subfield input attributes.
327 - *
328 - * @since 6.26
329 - *
330 - * @param array $sub_field Subfield data.
331 - * @param array $args Field output args. See {@see FrmFieldCombo::load_field_output()}.
332 - *
333 - * @return array
334 - */
335 - protected function get_sub_field_input_attrs( $sub_field, $args ) {
336 - $attrs = parent::get_sub_field_input_attrs( $sub_field, $args );
337 -
338 - $form_id = (int) ( is_array( $args['field'] ) ? $args['field']['form_id'] : $args['field']->form_id );
339 -
340 - if ( ! self::$first_name_field_ids || empty( self::$first_name_field_ids[ $form_id ] ) ) {
341 - return $attrs;
342 - }
343 -
344 - $parent_form_id = (int) FrmField::get_option( $args['field'], 'parent_form_id' );
345 -
346 - if ( $form_id !== $parent_form_id ) {
347 - // Do not add autocomplete attribute to a name field inside repeater.
348 - return $attrs;
349 - }
350 -
351 - $field_id = (int) ( is_array( $args['field'] ) ? $args['field']['id'] : $args['field']->id );
352 -
353 - if ( intval( self::$first_name_field_ids[ $form_id ] ) === $field_id ) {
354 - if ( 'first' === $sub_field['name'] ) {
355 - $attrs['autocomplete'] = 'given-name';
356 - } elseif ( 'last' === $sub_field['name'] ) {
357 - $attrs['autocomplete'] = 'family-name';
358 - }
359 - }
360 -
361 239 return $attrs;
362 240 }
363 241 }