PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / class-evf-field-scale-rating.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 year ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 1 month ago class-evf-field-checkbox.php 3 months ago class-evf-field-color.php 1 month ago class-evf-field-country.php 3 months ago class-evf-field-credit-card.php 1 month ago class-evf-field-date-time.php 1 month ago class-evf-field-divider.php 2 years ago class-evf-field-email.php 1 year ago class-evf-field-file-upload.php 1 year ago class-evf-field-first-name.php 1 year ago class-evf-field-hcaptcha.php 4 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 9 months ago class-evf-field-image-upload.php 1 year ago class-evf-field-last-name.php 1 year ago class-evf-field-likert.php 1 year ago class-evf-field-lookup.php 1 month ago class-evf-field-number.php 1 year ago class-evf-field-password.php 1 month ago class-evf-field-payment-authorize-net.php 1 month ago class-evf-field-payment-checkbox.php 1 month ago class-evf-field-payment-coupon.php 1 month ago class-evf-field-payment-gateway-selector.php 1 month ago class-evf-field-payment-quantity.php 1 month ago class-evf-field-payment-radio.php 1 month ago class-evf-field-payment-single.php 1 month ago class-evf-field-payment-square.php 1 year ago class-evf-field-payment-subscription-plan.php 1 month ago class-evf-field-payment-subtotal.php 1 month ago class-evf-field-payment-total.php 1 month ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 3 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 1 month ago class-evf-field-radio.php 3 months ago class-evf-field-range-slider.php 1 month ago class-evf-field-rating.php 3 months ago class-evf-field-recaptcha.php 4 months ago class-evf-field-repeater.php 1 month ago class-evf-field-reset.php 1 month ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 1 month ago class-evf-field-text.php 1 year ago class-evf-field-textarea.php 1 year ago class-evf-field-title.php 2 years ago class-evf-field-turnstile.php 4 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 3 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 1 month ago
class-evf-field-scale-rating.php
431 lines
1 <?php
2 /**
3 * Scale Rating field
4 *
5 * @package EverestForms\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Scale_Rating Class.
13 */
14 class EVF_Field_Scale_Rating extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Scale Rating', 'everest-forms' );
21 $this->type = 'scale-rating';
22 $this->icon = 'evf-icon evf-icon-scale-rating';
23 $this->order = 30;
24 $this->group = 'survey';
25 $this->settings = array(
26 'basic-options' => array(
27 'field_options' => array(
28 'label',
29 'highest_rating_text',
30 'lowest_rating_text',
31 'highest_rating_point',
32 'lowest_rating_point',
33 'description',
34 'required',
35 'required_field_message_setting',
36 'required_field_message',
37 ),
38 ),
39 'advanced-options' => array(
40 'field_options' => array(
41 'meta',
42 'label_hide',
43 'css',
44 ),
45 ),
46 );
47
48 parent::__construct();
49 }
50
51 /**
52 * Hook in tabs.
53 */
54 public function init_hooks() {
55 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
56 add_filter( 'everest_forms_field_exporter_' . $this->type, array( $this, 'field_exporter' ) );
57 add_filter( 'everest_forms_entries_field_editable', array( $this, 'field_editable' ), 10, 2 );
58 }
59
60 /**
61 * Highest rating text field option.
62 *
63 * @param array $field Field settings.
64 */
65 public function highest_rating_text( $field ) {
66 $value = ! empty( $field['highest_rating_text'] ) ? esc_attr( $field['highest_rating_text'] ) : __( 'Best', 'everest-forms' );
67 $tooltip = esc_html__( 'Label for the highest rating in the scale.', 'everest-forms' );
68 $lbl = $this->field_element(
69 'label',
70 $field,
71 array(
72 'slug' => 'highest_rating_text',
73 'value' => esc_html__( 'Highest Rating Text', 'everest-forms' ),
74 'tooltip' => $tooltip,
75 ),
76 false
77 );
78
79 $fld = $this->field_element(
80 'text',
81 $field,
82 array(
83 'slug' => 'highest_rating_text',
84 'value' => $value,
85 ),
86 false
87 );
88
89 $this->field_element(
90 'row',
91 $field,
92 array(
93 'slug' => 'highest_rating_text',
94 'content' => $lbl . $fld,
95 )
96 );
97 }
98
99 /**
100 * Lowest rating text field option.
101 *
102 * @param array $field Field settings.
103 */
104 public function lowest_rating_text( $field ) {
105 $value = ! empty( $field['lowest_rating_text'] ) ? esc_attr( $field['lowest_rating_text'] ) : __( 'Worst', 'everest-forms' );
106 $tooltip = esc_html__( 'Label for the lowest rating in the scale.', 'everest-forms' );
107 $lbl = $this->field_element(
108 'label',
109 $field,
110 array(
111 'slug' => 'lowest_rating_text',
112 'value' => __( 'Lowest Rating Text', 'everest-forms' ),
113 'tooltip' => $tooltip,
114 ),
115 false
116 );
117 $fld = $this->field_element(
118 'text',
119 $field,
120 array(
121 'slug' => 'lowest_rating_text',
122 'value' => $value,
123 ),
124 false
125 );
126 $this->field_element(
127 'row',
128 $field,
129 array(
130 'slug' => 'lowest_rating_text',
131 'content' => $lbl . $fld,
132 )
133 );
134 }
135
136 /**
137 * Highest rating point field option.
138 *
139 * @param array $field Field settings.
140 */
141 public function highest_rating_point( $field ) {
142 $value = ! empty( $field['highest_rating_point'] ) ? esc_attr( $field['highest_rating_point'] ) : 10;
143 $tooltip = esc_html__( 'Value for the highest rating in the scale.', 'everest-forms' );
144 $lbl = $this->field_element(
145 'label',
146 $field,
147 array(
148 'slug' => 'highest_rating_point',
149 'value' => esc_html__( 'Highest Rating Point', 'everest-forms' ),
150 'tooltip' => $tooltip,
151 ),
152 false
153 );
154
155 $fld = $this->field_element(
156 'text',
157 $field,
158 array(
159 'type' => 'number',
160 'slug' => 'highest_rating_point',
161 'class' => 'evf-input-highest-rating-point',
162 'value' => $value,
163 'attrs' => array(
164 'min' => 1,
165 'max' => 100,
166 'pattern' => '[0-9]',
167 ),
168 ),
169 false
170 );
171
172 $this->field_element(
173 'row',
174 $field,
175 array(
176 'slug' => 'highest_rating_point',
177 'content' => $lbl . $fld,
178 )
179 );
180 }
181
182 /**
183 * Lowest rating point field option.
184 *
185 * @param array $field Field settings.
186 */
187 public function lowest_rating_point( $field ) {
188 $value = ! empty( $field['lowest_rating_point'] ) ? esc_attr( $field['lowest_rating_point'] ) : 0;
189 $tooltip = esc_html__( 'Value for the highest rating in the scale.', 'everest-forms' );
190 $lbl = $this->field_element(
191 'label',
192 $field,
193 array(
194 'slug' => 'lowest_rating_point',
195 'value' => esc_html__( 'Lowest Rating Point', 'everest-forms' ),
196 'tooltip' => $tooltip,
197 ),
198 false
199 );
200
201 $fld = $this->field_element(
202 'text',
203 $field,
204 array(
205 'type' => 'number',
206 'slug' => 'lowest_rating_point',
207 'class' => 'evf-input-lowest-rating-point',
208 'value' => $value,
209 'max' => '99',
210 'required' => true,
211 ),
212 false
213 );
214
215 $this->field_element(
216 'row',
217 $field,
218 array(
219 'slug' => 'lowest_rating_point',
220 'content' => $lbl . $fld,
221 )
222 );
223 }
224
225 /**
226 * Define additional field properties.
227 *
228 * @since 1.0.0
229 *
230 * @param array $properties Field properties.
231 * @param array $field Field settings.
232 * @param array $form_data Form data and settings.
233 *
234 * @return array of additional field properties.
235 */
236 public function field_properties( $properties, $field, $form_data ) {
237 // Remove the attributes since this field only appers with survey, polls and quiz.
238 unset( $properties['inputs']['primary'] );
239 $highest_rating_point = ! empty( $field['highest_rating_point'] ) ? esc_html( $field['highest_rating_point'] ) : 10;
240 $lowest_rating_point = ! empty( $field['lowest_rating_point'] ) ? esc_html( $field['lowest_rating_point'] ) : 0;
241
242 $form_id = $form_data['id'];
243 $field_id = $field['id'];
244
245 for ( $i = $lowest_rating_point; $i <= $highest_rating_point; $i++ ) {
246 $properties['inputs'][ $i ] = array(
247 'label' => array(
248 'text' => $i,
249 ),
250 'attr' => array(
251 'name' => "everest_forms[form_fields][{$field_id}]",
252 'value' => $i,
253 ),
254 'class' => array( 'everest-forms-scale-rating-field-option', 'input-text' ),
255 'data' => array(),
256 'id' => "everest-forms-{$form_id}-field_{$field_id}_{$i}",
257 'required' => ! empty( $field['required'] ) ? 'required' : '',
258 );
259 }
260
261 return $properties;
262 }
263
264 /**
265 * Filter callback for outputting formatted data.
266 *
267 * @param array $field Field Data.
268 */
269 public function field_exporter( $field ) {
270 return array(
271 'label' => ! empty( $field['name'] ) ? $field['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}",
272 'value' => ! empty( $field['value'] ) ? $field['value'] : false,
273 );
274 }
275
276 /**
277 * Allow this field to be editable.
278 *
279 * @param bool $is_editable True if editable. False if not.
280 * @param string $field_type Field type to check for editable.
281 */
282 public function field_editable( $is_editable, $field_type ) {
283 return ! empty( $field_type ) && $field_type === $this->type ? true : $is_editable;
284 }
285
286 /**
287 * Field preview inside the builder.
288 *
289 * @since 1.0.0
290 *
291 * @param array $field Field data and settings.
292 */
293 public function field_preview( $field ) {
294 $highest_rating_text = ! empty( $field['highest_rating_text'] ) ? esc_html( $field['highest_rating_text'] ) : __( 'Best', 'everest-forms' );
295 $lowest_rating_text = ! empty( $field['lowest_rating_text'] ) ? esc_html( $field['lowest_rating_text'] ) : __( 'Worst', 'everest-forms' );
296 $highest_rating_point = ! empty( $field['highest_rating_point'] ) ? esc_html( $field['highest_rating_point'] ) : 10;
297 $lowest_rating_point = ! empty( $field['lowest_rating_point'] ) ? esc_html( $field['lowest_rating_point'] ) : 0;
298 $colspan = ( $highest_rating_point - $lowest_rating_point ) + 1;
299 $this->field_preview_option( 'label', $field );
300 ?>
301
302 <table cellspacing="0" cellpadding="0" class="everest-forms-scale-rating-table">
303 <thead>
304 <tr>
305 <th colspan="<?php echo $colspan; // WPCS: XSS ok. ?>">
306 <span class="lowest-rating"><?php echo $lowest_rating_text; // WPCS: XSS ok. ?></span>
307 <span class="highest-rating"><?php echo $highest_rating_text; // WPCS: XSS ok. ?></span>
308 </th>
309 </tr>
310 </thead>
311 <tbody>
312 <tr>
313 <?php
314 for ( $i = $lowest_rating_point; $i <= $highest_rating_point; $i++ ) {
315 ?>
316 <td>
317 <input type="radio" disabled>
318 <label><?php echo absint( $i ); ?></label>
319 </td>
320 <?php
321 }
322 ?>
323 </tr>
324 </tbody>
325 </table>
326 <?php
327
328 // Description.
329 $this->field_preview_option( 'description', $field );
330 }
331
332 /**
333 * Field display on the form front-end.
334 *
335 * @since 1.0.0
336 *
337 * @param array $field Field Data.
338 * @param array $field_atts Field attributes.
339 * @param array $form_data All Form Data.
340 */
341 public function field_display( $field, $field_atts, $form_data ) {
342 $inputs = $field['properties']['inputs'];
343 $current = isset( $inputs['primary']['attr']['value'] ) ? $inputs['primary']['attr']['value'] : '';
344 $lowest_rating_text = ! empty( $field['lowest_rating_text'] ) ? evf_string_translation( $form_data['id'], $field['id'], $field['lowest_rating_text'], '-lowest-rating-text' ) : esc_html__( 'Not at all Likely', 'everest-forms' );
345 $highest_rating_text = ! empty( $field['highest_rating_text'] ) ? evf_string_translation( $form_data['id'], $field['id'], $field['highest_rating_text'], '-highest-rating-text' ) : esc_html__( 'Extremely Likely', 'everest-forms' );
346 $highest_rating_point = ! empty( $field['highest_rating_point'] ) ? esc_html( $field['highest_rating_point'] ) : 10;
347 $lowest_rating_point = ! empty( $field['lowest_rating_point'] ) ? esc_html( $field['lowest_rating_point'] ) : 0;
348 $colspan = ( $highest_rating_point - $lowest_rating_point ) + 1;
349 $conditional_id = isset( $field['properties']['inputs']['primary']['attr']['conditional_id'] ) ? $field['properties']['inputs']['primary']['attr']['conditional_id'] : '';
350 $conditional_rules = isset( $field['properties']['inputs']['primary']['attr']['conditional_rules'] ) ? $field['properties']['inputs']['primary']['attr']['conditional_rules'] : '';
351 ?>
352 <table id="evf-<?php echo esc_attr( absint( $form_data['id'] ) ); ?>-field_<?php echo esc_attr( $field['id'] ); ?>" cellspacing="0" cellpadding="0" class="everest-forms-field-scale-rating">
353 <thead>
354 <tr>
355 <th colspan="<?php echo $colspan; // WPCS: XSS ok. ?>">
356 <span class="lowest-rating"><?php echo $lowest_rating_text; // WPCS: XSS ok. ?></span>
357 <span class="highest-rating"><?php echo $highest_rating_text; // WPCS: XSS ok. ?></span>
358 </th>
359 </tr>
360 </thead>
361 <tbody>
362 <tr>
363 <?php
364 foreach ( $inputs as $key => $input ) {
365 if ( 'primary' !== $key ) {
366 echo '<td>';
367 printf(
368 '<input type="radio" %s %s %s conditional_rules="%s" conditional_id="%s">',
369 evf_html_attributes( $input['id'], $input['class'], $input['data'], $input['attr'] ),
370 $input['required'],
371 checked( $input['attr']['value'], $current, false ),
372 esc_attr( $conditional_rules ),
373 esc_attr( $conditional_id )
374 ); // WPCS: XSS ok.
375 echo '<label for="' . esc_attr( sanitize_html_class( $input['id'] ) ) . '">';
376 echo esc_html( sanitize_text_field( $input['label']['text'] ) );
377 echo '</label>';
378 echo '</td>';
379 }
380 }
381 ?>
382 </tr>
383 </tbody>
384 </table>
385 <?php
386 }
387
388 /**
389 * Validates field on form submit.
390 *
391 * @param int $field_id Field ID.
392 * @param array $field_submit Submitted form field data.
393 * @param array $form_data Form data.
394 */
395 public function validate( $field_id, $field_submit, $form_data ) {
396 $form_id = $form_data['id'];
397 $entry = isset( $form_data['entry'] ) ? $form_data['entry'] : array();
398 $visible = apply_filters( 'everest_forms_visible_fields', true, $form_data['form_fields'][ $field_id ], $entry, $form_data );
399 $required_message = isset( $form_data['form_fields'][ $field_id ]['required-field-message'], $form_data['form_fields'][ $field_id ]['required_field_message_setting'] ) && ! empty( $form_data['form_fields'][ $field_id ]['required-field-message'] ) && 'individual' == $form_data['form_fields'][ $field_id ]['required_field_message_setting'] ? $form_data['form_fields'][ $field_id ]['required-field-message'] : get_option( 'everest_forms_required_validation' );
400
401 if ( false === $visible ) {
402 return;
403 }
404 if ( ! empty( $form_data['form_fields'][ $field_id ]['required'] ) && empty( $field_submit ) && '0' !== $field_submit ) {
405 EVF()->task->errors[ $form_id ][ $field_id ] = $required_message;
406 update_option( 'evf_validation_error', 'yes' );
407 }
408 }
409
410 /**
411 * Formats field.
412 *
413 * @param int $field_id Field ID.
414 * @param array $field_submit Submitted form field data.
415 * @param array $form_data Form data.
416 * @param mixed $meta_key Meta Key.
417 */
418 public function format( $field_id, $field_submit, $form_data, $meta_key ) {
419 $value = '' !== $field_submit ? absint( $field_submit ) : '';
420 $name = ! empty( $form_data['form_fields'][ $field_id ]['label'] ) ? $form_data['form_fields'][ $field_id ]['label'] : '';
421
422 EVF()->task->form_fields[ $field_id ] = array(
423 'name' => sanitize_text_field( $name ),
424 'value' => sanitize_text_field( $value ),
425 'id' => $field_id,
426 'type' => $this->type,
427 'meta_key' => $meta_key,
428 );
429 }
430 }
431