| 1 |
<?php // phpcs:ignore |
| 2 |
|
| 3 |
/** |
| 4 |
* Video class |
| 5 |
* |
| 6 |
* @package opitn/inludes/uitls |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace OPTN\Includes\Utils; |
| 10 |
|
| 11 |
/** |
| 12 |
* Video |
| 13 |
*/ |
| 14 |
class FormHelper { |
| 15 |
/** |
| 16 |
* Get checkbox html |
| 17 |
* |
| 18 |
* @param object $field field data. |
| 19 |
* @return string |
| 20 |
*/ |
| 21 |
private static function get_text_html( $field ) { |
| 22 |
|
| 23 |
ob_start(); |
| 24 |
?> |
| 25 |
<div class="optn-block-form-input" id="<?php echo 'optn-field-' . esc_attr( $field->id ); ?>"> |
| 26 |
|
| 27 |
<label class="optn-block-form-input-label" for="<?php echo esc_attr( $field->name ); ?>"> |
| 28 |
<?php echo esc_html( $field->label ); ?> |
| 29 |
</label> |
| 30 |
|
| 31 |
<div class="optn-block-form-input-wrapper"> |
| 32 |
<input |
| 33 |
class="optn-block-form-input-input" |
| 34 |
name="<?php echo esc_attr( $field->name ); ?>" |
| 35 |
placeholder="<?php echo esc_attr( $field->placeholder ); ?>" |
| 36 |
type="<?php echo esc_attr( $field->inputType ); // phpcs:ignore ?>" |
| 37 |
<?php echo $field->required ? 'required' : ''; ?> |
| 38 |
/> |
| 39 |
|
| 40 |
<?php if ( ! empty( $field->message ) ) : ?> |
| 41 |
|
| 42 |
<div class="optn-block-form-input-msg"> |
| 43 |
<?php echo esc_html( $field->message ); ?> |
| 44 |
</div> |
| 45 |
|
| 46 |
<?php endif; ?> |
| 47 |
</div> |
| 48 |
|
| 49 |
</div> |
| 50 |
<?php |
| 51 |
|
| 52 |
return ob_get_clean(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get checkbox html |
| 57 |
* |
| 58 |
* @param object $field field data. |
| 59 |
* @return string |
| 60 |
*/ |
| 61 |
private static function get_checkbox_html( $field ) { |
| 62 |
|
| 63 |
ob_start(); |
| 64 |
?> |
| 65 |
<div |
| 66 |
class="optn-block-form-input optn-block-form-input-checkbox" |
| 67 |
id="<?php echo 'optn-field-' . esc_attr( $field->id ); ?>" |
| 68 |
> |
| 69 |
|
| 70 |
<div class="optn-block-form-input-checkbox"> |
| 71 |
<input |
| 72 |
name="<?php echo esc_attr( $field->name ); ?>" |
| 73 |
type="<?php echo esc_attr( $field->inputType ); // phpcs:ignore ?>" |
| 74 |
<?php echo $field->required ? 'required' : ''; ?> |
| 75 |
/> |
| 76 |
|
| 77 |
<label for="<?php echo esc_attr( $field->name ); ?>"> |
| 78 |
<?php echo wp_kses_post( $field->label ); ?> |
| 79 |
</label> |
| 80 |
</div> |
| 81 |
|
| 82 |
<?php if ( ! empty( $field->message ) ) : ?> |
| 83 |
<div class="optn-block-form-input-msg"> |
| 84 |
<?php echo esc_html( $field->message ); ?> |
| 85 |
</div> |
| 86 |
<?php endif; ?> |
| 87 |
|
| 88 |
</div> |
| 89 |
<?php |
| 90 |
|
| 91 |
return ob_get_clean(); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Extract the Vimeo video ID from a URL. |
| 96 |
* |
| 97 |
* @param object $attr attributes. |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public static function get_input_html_v2( &$attr ) { |
| 101 |
|
| 102 |
$fields = $attr->fields; |
| 103 |
|
| 104 |
$html = ''; |
| 105 |
|
| 106 |
foreach ( $fields as $f_id => $field ) { |
| 107 |
|
| 108 |
if ( 'spacer' === $field->type ) { |
| 109 |
$html .= self::get_spacer_html( $field ); |
| 110 |
continue; |
| 111 |
} |
| 112 |
|
| 113 |
$html .= '<div class="optn-block-form-field-wrapper" data-optn-form-field-id="' . esc_attr( $f_id ) . '">'; |
| 114 |
|
| 115 |
switch ( $field->type ) { |
| 116 |
case 'consent': |
| 117 |
case 'checkbox': |
| 118 |
BlockUtils::add_google_font( $field->typo->fontFamily, array( $field->typo->fontWeight ) ); // phpcs:ignore |
| 119 |
$html .= self::get_checkbox_html( $field ); |
| 120 |
break; |
| 121 |
default: |
| 122 |
$html .= self::get_text_html( $field ); |
| 123 |
break; |
| 124 |
} |
| 125 |
|
| 126 |
$html .= '</div>'; |
| 127 |
} |
| 128 |
|
| 129 |
// Form Button. |
| 130 |
|
| 131 |
$html .= '<div class="optn-block-form-field-wrapper" data-optn-form-field-id="button">'; |
| 132 |
$button_data = array( |
| 133 |
'text' => $attr->btnText, // phpcs:ignore |
| 134 |
'submittedText' => $attr->btnSuccessText, // phpcs:ignore |
| 135 |
'submittingText' => $attr->btnWaitText, // phpcs:ignore |
| 136 |
); |
| 137 |
$html .= '<button class="optn-block-form-button" type="submit" '; |
| 138 |
$html .= 'data-optn="' . esc_attr( wp_json_encode( $button_data ) ) . '">'; |
| 139 |
$html .= '<div class="optn-block-form-button-text">'; |
| 140 |
$html .= esc_html( $attr->btnText ); // phpcs:ignore |
| 141 |
$html .= '</div>'; |
| 142 |
$html .= '</button>'; |
| 143 |
$html .= '</div>'; |
| 144 |
|
| 145 |
return $html; |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Get spacer html |
| 150 |
* |
| 151 |
* @return string |
| 152 |
*/ |
| 153 |
private static function get_spacer_html( &$field ) { |
| 154 |
return '<div class="optn-form-spacer" data-optn-form-field-id="' . esc_attr( $field->id ) . '"></div>'; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Extract the Vimeo video ID from a URL. |
| 159 |
* |
| 160 |
* @param object $fields attributes. |
| 161 |
* @return string |
| 162 |
*/ |
| 163 |
public static function get_input_html( &$fields ) { |
| 164 |
$html = ''; |
| 165 |
|
| 166 |
foreach ( $fields as $field ) { |
| 167 |
switch ( $field->type ) { |
| 168 |
case 'consent': |
| 169 |
case 'checkbox': |
| 170 |
$html .= self::get_checkbox_html( $field ); |
| 171 |
break; |
| 172 |
default: |
| 173 |
$html .= self::get_text_html( $field ); |
| 174 |
break; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
return $html; |
| 179 |
} |
| 180 |
} |
| 181 |
|