PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.11
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.11
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
← All changes | inc/fields/base.php +45 -136 trunk0.0.11 View file →
@@ -24,16 +24,8 @@
24 24 * @since 0.0.1
25 25 */
26 26 class Base {
27 27 /**
28 - * Stores the attributes of the block.
29 - *
30 - * @var array<mixed> $attributes Block attributes.
31 - * @since 1.3.0
32 - */
33 - protected $attributes;
34 -
35 - /**
36 28 * Flag indicating if the field is required.
37 29 *
38 30 * @var bool
39 31 * @since 0.0.2
@@ -107,12 +99,12 @@
107 99
108 100 /**
109 101 * Indicates whether the attribute should be set to true or false.
110 102 *
111 - * @var string $data_require_attr Value of the data-required attribute.
103 + * @var string $aria_require_attr Value of the aria-required attribute.
112 104 * @since 0.0.2
113 105 */
114 - protected $data_require_attr;
106 + protected $aria_require_attr;
115 107
116 108 /**
117 109 * Dynamically sets the CSS class for block width based on the field width.
118 110 *
@@ -281,8 +273,16 @@
281 273 */
282 274 protected $label_markup;
283 275
284 276 /**
277 + * Stores the error icon to be used in HTML markup.
278 + *
279 + * @var string
280 + * @since 0.0.2
281 + */
282 + protected $error_svg;
283 +
284 + /**
285 285 * Stores the duplicate message markup for a field.
286 286 *
287 287 * @var string
288 288 * @since 0.0.2
@@ -297,91 +297,8 @@
297 297 */
298 298 protected $aria_described_by;
299 299
300 300 /**
301 - * Stores the minimum number of selections required.
302 - *
303 - * @var string
304 - * @since 0.0.13
305 - */
306 - protected $min_selection;
307 -
308 - /**
309 - * Stores the maximum number of selections allowed.
310 - *
311 - * @var string
312 - * @since 0.0.13
313 - */
314 - protected $max_selection;
315 -
316 - /**
317 - * Whether or not block is render in editing mode.
318 - * If it is true, then block is currently rendered in edit entry.
319 - *
320 - * @var bool
321 - * @since 1.3.0
322 - */
323 - protected $is_editing = false;
324 -
325 - /**
326 - * Currently rendered entry ID.
327 - *
328 - * @var int
329 - * @since 1.3.0
330 - */
331 - protected $entry_id = 0;
332 -
333 - /**
334 - * Configuration array for the field.
335 - *
336 - * This associative array contains configuration settings for the field,
337 - * which can be used for various JavaScript functionalities such as
338 - * calculation, validation, and conditional logic (in future).
339 - * The array data will be stored in the block field's "data-field-config"
340 - * attribute as a JSON string.
341 - *
342 - * @var string $field_config Configuration settings for the field.
343 - * @since 1.5.0
344 - */
345 - protected $field_config;
346 -
347 - /**
348 - * Render the sureforms default
349 - *
350 - * @since 0.0.2
351 - * @return string|bool
352 - */
353 - public function markup() {
354 - return '';
355 - }
356 -
357 - /**
358 - * Constructor for the Base class.
359 - *
360 - * @param array<mixed> $extra_classes Extra classes to be added to the field.
361 - * @since 1.5.0
362 - * @return string
363 - */
364 - public function get_field_classes( $extra_classes = [] ) {
365 - $common_classes = [
366 - 'srfm-block-single',
367 - 'srfm-block',
368 - "srfm-{$this->slug}-block",
369 - "srf-{$this->slug}-{$this->block_id}-block",
370 - $this->block_width,
371 - $this->class_name,
372 - "srfm-slug-{$this->block_slug}",
373 - $this->conditional_class,
374 - ];
375 -
376 - if ( ! empty( $extra_classes ) && is_array( $extra_classes ) ) {
377 - $common_classes = array_merge( $common_classes, $extra_classes );
378 - }
379 -
380 - return Helper::join_strings( $common_classes );
381 - }
382 -
383 - /**
384 301 * Setter for the properties of class based on block attributes.
385 302 *
386 303 * @param array<mixed> $attributes Block attributes.
387 304 * @since 0.0.2
@@ -387,36 +304,26 @@
387 304 * @since 0.0.2
388 305 * @return void
389 306 */
390 307 protected function set_properties( $attributes ) {
391 - $default_classes = isset( $attributes['className'] ) ? ' ' . $attributes['className'] : '';
392 - $filter_classes = apply_filters( 'srfm_field_classes', $default_classes, [ 'attributes' => $attributes ] );
393 - $field_config = apply_filters( 'srfm_field_config', [], [ 'attributes' => $attributes ] );
394 -
395 - $this->field_config = $field_config ? htmlspecialchars( Helper::get_string_value( wp_json_encode( $field_config, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ), ENT_QUOTES, 'UTF-8' ) : '';
396 - $this->attributes = $attributes;
397 - $this->required = $attributes['required'] ?? false;
398 - $this->field_width = $attributes['fieldWidth'] ?? '';
399 - $this->label = $attributes['label'] ?? '';
400 - $this->help = $attributes['help'] ?? '';
401 - $this->block_id = isset( $attributes['block_id'] ) ? Helper::get_string_value( $attributes['block_id'] ) : '';
402 - $this->form_id = isset( $attributes['formId'] ) ? Helper::get_string_value( $attributes['formId'] ) : '';
403 - $this->block_slug = $attributes['slug'] ?? '';
404 - $this->class_name = $filter_classes;
405 - $this->placeholder = $attributes['placeholder'] ?? '';
406 - $this->default = $attributes['defaultValue'] ?? '';
407 - $this->checked = $attributes['checked'] ?? '';
408 - // Inject the block type slug (e.g. 'dropdown', 'multi-choice') into the attributes passed to
409 - // the filter. The field's `slug` attribute can be prefixed when the block is inside a repeater
410 - // (e.g. 'srfm-repeater-srfm-dropdown'), so filter consumers need a reliable block type identifier.
411 - $block_args = [ 'block_args' => [ 'slug' => $this->slug ] ];
412 - $this->options = apply_filters( 'srfm_field_options', $attributes['options'] ?? '', array_merge( $attributes, $block_args ) );
413 - $this->is_unique = $attributes['isUnique'] ?? false;
308 + $this->required = isset( $attributes['required'] ) ? $attributes['required'] : false;
309 + $this->field_width = isset( $attributes['fieldWidth'] ) ? $attributes['fieldWidth'] : '';
310 + $this->label = isset( $attributes['label'] ) ? $attributes['label'] : '';
311 + $this->help = isset( $attributes['help'] ) ? $attributes['help'] : '';
312 + $this->block_id = isset( $attributes['block_id'] ) ? Helper::get_string_value( $attributes['block_id'] ) : '';
313 + $this->form_id = isset( $attributes['formId'] ) ? Helper::get_string_value( $attributes['formId'] ) : '';
314 + $this->block_slug = isset( $attributes['slug'] ) ? $attributes['slug'] : '';
315 + $this->class_name = isset( $attributes['className'] ) ? ' ' . $attributes['className'] : '';
316 + $this->placeholder = isset( $attributes['placeholder'] ) ? $attributes['placeholder'] : '';
317 + $this->default = isset( $attributes['defaultValue'] ) ? $attributes['defaultValue'] : '';
318 + $this->checked = isset( $attributes['checked'] ) ? $attributes['checked'] : '';
319 + $this->options = isset( $attributes['options'] ) ? $attributes['options'] : '';
320 + $this->is_unique = isset( $attributes['isUnique'] ) ? $attributes['isUnique'] : false;
414 321 $this->conditional_class = apply_filters( 'srfm_conditional_logic_classes', $this->form_id, $this->block_id );
415 - $this->data_require_attr = $this->required ? 'true' : 'false';
322 + $this->aria_require_attr = $this->required ? 'true' : 'false';
416 323 $this->block_width = $this->field_width ? ' srfm-block-width-' . str_replace( '.', '-', $this->field_width ) : '';
417 - $this->placeholder_attr = '' !== $this->placeholder ? ' placeholder="' . esc_attr( $this->placeholder ) . '" ' : '';
418 - $this->default_value_attr = '' !== $this->default ? ' value="' . esc_attr( $this->default ) . '" ' : '';
324 + $this->placeholder_attr = $this->placeholder ? ' placeholder="' . $this->placeholder . '" ' : '';
325 + $this->default_value_attr = $this->default ? ' value="' . $this->default . '" ' : '';
419 326 $this->checked_attr = $this->checked ? 'checked' : '';
420 327 $this->aria_unique = $this->is_unique ? 'true' : 'false';
421 328 $this->allowed_tags = [
422 329 'a' => [
@@ -423,13 +330,8 @@
423 330 'href' => [],
424 331 'target' => [],
425 332 ],
426 333 ];
427 - $this->min_selection = $attributes['minValue'] ?? '';
428 - $this->max_selection = $attributes['maxValue'] ?? '';
429 -
430 - $this->is_editing = isset( $attributes['isEditing'] ) ? true : false;
431 - $this->entry_id = $attributes['entryID'] ?? 0;
432 334 }
433 335
434 336 /**
435 337 * Setter for the label of input field if available, otherwise provided value is utilized.
@@ -440,9 +342,9 @@
440 342 * @return void
441 343 */
442 344 protected function set_input_label( $value ) {
443 345 $this->input_label_fallback = $this->label ? $this->label : $value;
444 - $this->input_label = '-lbl-' . Helper::encode( $this->input_label_fallback );
346 + $this->input_label = '-lbl-' . Helper::encrypt( $this->input_label_fallback );
445 347 $this->set_field_name( $this->input_label );
446 348 }
447 349
448 350 /**
@@ -465,9 +367,9 @@
465 367 * @return void
466 368 */
467 369 protected function set_error_msg( $attributes, $key = '' ) {
468 370 if ( empty( $key ) ) {
469 - $this->error_msg = $attributes['errorMsg'] ?? '';
371 + $this->error_msg = isset( $attributes['errorMsg'] ) ? $attributes['errorMsg'] : '';
470 372 } else {
471 373 $this->error_msg = isset( $attributes['errorMsg'] ) && $attributes['errorMsg'] ? $attributes['errorMsg'] : Helper::get_default_dynamic_block_option( $key );
472 374 }
473 375 }
@@ -503,13 +405,12 @@
503 405 * @since 0.0.2
504 406 * @return void
505 407 */
506 408 protected function set_markup_properties( $input_label = '', $override = false ) {
507 - $this->help_markup = Helper::generate_common_form_markup( $this->form_id, 'help', '', '', $this->block_id, false, $this->help );
508 - $this->error_msg_markup = Helper::generate_common_form_markup( $this->form_id, 'error', '', '', $this->block_id, boolval( $this->required || $this->min_selection || $this->max_selection ), '', $this->error_msg, false, '', $override );
509 - $type = in_array( $this->slug, [ 'multi-choice', 'dropdown', 'address' ], true ) ? 'label_text' : 'label';
510 - $this->label_markup = Helper::generate_common_form_markup( $this->form_id, $type, $this->label, $this->slug, $this->block_id . $input_label, boolval( $this->required ) );
511 -
409 + $this->help_markup = Helper::generate_common_form_markup( $this->form_id, 'help', '', '', $this->block_id, false, $this->help );
410 + $this->error_msg_markup = Helper::generate_common_form_markup( $this->form_id, 'error', '', '', $this->block_id, boolval( $this->required ), '', $this->error_msg, false, '', $override );
411 + $this->label_markup = Helper::generate_common_form_markup( $this->form_id, 'label', $this->label, $this->slug, $this->block_id . $input_label, boolval( $this->required ) );
412 + $this->error_svg = Helper::fetch_svg( 'error', 'srfm-error-icon' );
512 413 $this->duplicate_msg_markup = Helper::generate_common_form_markup( $this->form_id, 'error', '', '', $this->block_id, boolval( $this->required ), '', $this->error_msg, false, $this->duplicate_msg, $override );
513 414 }
514 415
515 416 /**
@@ -524,11 +425,9 @@
524 425 $this->placeholder_attr = '';
525 426 $placeholder = Helper::generate_common_form_markup( $this->form_id, 'placeholder', $this->label, $this->slug, $this->block_id . $input_label, boolval( $this->required ) );
526 427 if ( ! empty( $placeholder ) ) {
527 428 $this->label_markup = '';
528 - $this->placeholder_attr = ' placeholder="' . esc_attr( $placeholder ) . '" ';
529 - } elseif ( '' !== $this->placeholder ) {
530 - $this->placeholder_attr = ' placeholder="' . esc_attr( $this->placeholder ) . '" ';
429 + $this->placeholder_attr = ' placeholder="' . $placeholder . '" ';
531 430 }
532 431 }
533 432
534 433 /**
@@ -537,8 +436,18 @@
537 436 * @since 0.0.6
538 437 * @return void
539 438 */
540 439 protected function set_aria_described_by() {
541 - $this->aria_described_by .= ' srfm-error-' . esc_attr( $this->block_id );
542 - $this->aria_described_by .= ! empty( $this->help ) ? ' srfm-description-' . esc_attr( $this->block_id ) : '';
440 + $this->aria_described_by .= ! empty( $this->help ) ? ' srfm-description-' . $this->block_id : '';
441 + $this->aria_described_by .= ! empty( $this->required ) ? ' srfm-error-' . $this->block_id : '';
442 + }
443 +
444 + /**
445 + * Render the sureforms default
446 + *
447 + * @since 0.0.2
448 + * @return string|boolean
449 + */
450 + public function markup() {
451 + return '';
543 452 }
544 453 }