PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.8.0
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.8.0
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
sureforms / inc / fields / input-markup.php
input-markup.php
103 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sureforms Input Markup Class file.
4 *
5 * @package sureforms.
6 * @since 0.0.1
7 */
8
9 namespace SRFM\Inc\Fields;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Sureforms Input Markup Class.
17 *
18 * @since 0.0.1
19 */
20 class Input_Markup extends Base {
21 /**
22 * Maximum length of text allowed for an input field.
23 *
24 * @var string
25 * @since 0.0.2
26 */
27 protected $max_text_length;
28
29 /**
30 * Input mask for the input field.
31 *
32 * @var string
33 * @since 0.0.11
34 */
35 protected $input_mask;
36 /**
37 * Custom input mask for the input field.
38 *
39 * @var string
40 * @since 0.0.11
41 */
42 protected $custom_input_mask;
43
44 /**
45 * Read-only attribute for the input field.
46 *
47 * @var bool
48 * @since 1.7.2
49 */
50 protected $read_only;
51
52 /**
53 * Initialize the properties based on block attributes.
54 *
55 * @param array<mixed> $attributes Block attributes.
56 * @since 0.0.2
57 */
58 public function __construct( $attributes ) {
59 $this->slug = 'input';
60 $this->max_text_length = $attributes['textLength'] ?? '';
61 $this->input_mask = $attributes['inputMask'] ?? '';
62 $this->custom_input_mask = 'custom-mask' === $this->input_mask && isset( $attributes['customInputMask'] ) ? $attributes['customInputMask'] : '';
63 $this->set_properties( $attributes );
64 $this->read_only = ! empty( $this->default ) && $attributes['readOnly'];
65 $this->set_input_label( __( 'Text field', 'sureforms' ) );
66 $this->set_error_msg( $attributes, 'srfm_input_block_required_text' );
67 $this->set_duplicate_msg( $attributes, 'srfm_input_block_unique_text' );
68 $this->set_unique_slug();
69 $this->set_field_name( $this->unique_slug );
70 $this->set_markup_properties( $this->input_label, true );
71 $this->set_aria_described_by();
72 $this->set_label_as_placeholder( $this->input_label );
73 }
74
75 /**
76 * Render input markup
77 *
78 * @since 0.0.2
79 * @return string|bool
80 */
81 public function markup() {
82 $data_config = $this->field_config;
83
84 $this->class_name = $this->get_field_classes( $this->read_only ? [ 'srfm-read-only' ] : [] );
85
86 ob_start(); ?>
87 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $this->class_name ); ?>" <?php echo $data_config ? "data-field-config='" . esc_attr( $data_config ) . "'" : ''; ?>>
88 <?php echo wp_kses_post( $this->label_markup ); ?>
89 <?php echo wp_kses_post( $this->help_markup ); ?>
90 <div class="srfm-block-wrap">
91 <input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" type="text" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>"
92 <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?>
93 data-required="<?php echo esc_attr( strval( $this->data_require_attr ) ); ?>" aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>" data-unique="<?php echo esc_attr( $this->aria_unique ); ?>" maxlength="<?php echo esc_attr( $this->max_text_length ); ?>" value="<?php echo esc_attr( $this->default ); ?>" <?php echo wp_kses_post( $this->placeholder_attr ); ?> data-srfm-mask="<?php echo esc_attr( $this->input_mask ); ?>" <?php echo ! empty( $this->custom_input_mask ) ? 'data-custom-srfm-mask="' . esc_attr( $this->custom_input_mask ) . '"' : ''; ?> <?php echo $this->read_only ? 'readonly' : ''; ?> />
94 </div>
95 <div class="srfm-error-wrap">
96 <?php echo wp_kses_post( $this->duplicate_msg_markup ); ?>
97 </div>
98 </div>
99 <?php
100 return ob_get_clean();
101 }
102 }
103