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-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 4 weeks ago class-evf-field-checkbox.php 2 months ago class-evf-field-color.php 4 weeks ago class-evf-field-country.php 2 months ago class-evf-field-credit-card.php 4 weeks ago class-evf-field-date-time.php 4 weeks 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 4 weeks ago class-evf-field-number.php 1 year ago class-evf-field-password.php 4 weeks ago class-evf-field-payment-authorize-net.php 4 weeks ago class-evf-field-payment-checkbox.php 4 weeks ago class-evf-field-payment-coupon.php 4 weeks ago class-evf-field-payment-gateway-selector.php 4 weeks ago class-evf-field-payment-quantity.php 4 weeks ago class-evf-field-payment-radio.php 4 weeks ago class-evf-field-payment-single.php 4 weeks ago class-evf-field-payment-square.php 1 year ago class-evf-field-payment-subscription-plan.php 4 weeks ago class-evf-field-payment-subtotal.php 4 weeks ago class-evf-field-payment-total.php 4 weeks ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 2 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 4 weeks ago class-evf-field-radio.php 2 months ago class-evf-field-range-slider.php 4 weeks ago class-evf-field-rating.php 2 months ago class-evf-field-recaptcha.php 4 months ago class-evf-field-repeater.php 4 weeks ago class-evf-field-reset.php 4 weeks ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 4 weeks 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 2 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 4 weeks ago
class-evf-field-rating.php
486 lines
1 <?php
2 /**
3 * Rating field
4 *
5 * @package EverestForms\Fields
6 * @since 1.2.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Rating Class.
13 */
14 class EVF_Field_Rating extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Rating', 'everest-forms' );
21 $this->type = 'rating';
22 $this->icon = 'evf-icon evf-icon-star';
23 $this->order = 10;
24 $this->group = 'survey';
25 $this->settings = array(
26 'basic-options' => array(
27 'field_options' => array(
28 'label',
29 'description',
30 'number_of_stars',
31 'required',
32 'required_field_message_setting',
33 'required_field_message',
34 ),
35 ),
36 'advanced-options' => array(
37 'field_options' => array(
38 'meta',
39 'rating_icon',
40 'icon_color',
41 'label_hide',
42 'css',
43 ),
44 ),
45 );
46
47 parent::__construct();
48 }
49
50 /**
51 * Hook in tabs.
52 */
53 public function init_hooks() {
54 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
55 add_filter( 'everest_forms_html_field_value', array( $this, 'html_rating_value' ), 10, 4 );
56 add_filter( 'everest_forms_field_exporter_' . $this->type, array( $this, 'field_exporter' ) );
57 }
58
59 /**
60 * Returns a SVG for use in the rating field.
61 *
62 * @param string $icon_type Type of the icon.
63 * @param string $icon_color Color of the icon.
64 */
65 private function get_icon_svg( $icon_type = 'full-star', $icon_color = '' ) {
66 $svg_icons = array(
67 'full-star' => '<svg width="32" height="32" viewBox="0 0 32 32" style="fill:' . $icon_color . '"><path d="M20.33 11.45L16 2.69l-4.33 8.76L2 12.86l7 6.82-1.65 9.64L16 24.77l8.65 4.55L23 19.68l7-6.82-9.67-1.41z"/></svg>',
68 'heart' => '<svg width="32" height="32" viewBox="0 0 32 32" style="fill:' . $icon_color . '"><path d="M27.66 16.94L16 28 4.34 16.94a7.31 7.31 0 0 1 0-10.72A8.21 8.21 0 0 1 10 4a6.5 6.5 0 0 1 5 2l1 1s.88-.89 1-1a6.5 6.5 0 0 1 5-2 8.21 8.21 0 0 1 5.66 2.22 7.31 7.31 0 0 1 0 10.72z"/></svg>',
69 'thumb' => '<svg width="32" height="32" viewBox="0 0 32 32" style="fill:' . $icon_color . '"><path d="M30 14.88a3.42 3.42 0 0 0-3.36-3.36h-4.85l.14-.42a2.42 2.42 0 0 1 .2-.39c.08-.14.14-.24.17-.31.21-.4.37-.72.48-1a7.39 7.39 0 0 0 .33-1.05A5.71 5.71 0 0 0 23 4a3.48 3.48 0 0 0-3-2 1.61 1.61 0 0 0-1.43.89C18.34 3.13 17 7 17 7a5.44 5.44 0 0 1-1 2c-.57.75-2.6 3-3.2 3.71s-1.05 1-1.33 1C10 13.74 10 15.71 10 16v9c0 .3 0 2.2 1.52 2.2a12.7 12.7 0 0 1 2.76.77A15.6 15.6 0 0 0 21 30a8.9 8.9 0 0 0 5.74-1.92C30 25 30 15.88 30 14.88zM5 14a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0v-7a3 3 0 0 0-3-3zm0 11a1 1 0 1 1 1-1 1 1 0 0 1-1 1z"/></svg>',
70 'smiley' => '<svg width="32" height="32" viewBox="0 0 32 32" style="fill:' . $icon_color . '"><path d="M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2zm4 8a2 2 0 1 1-2 2 2 2 0 0 1 2-2zm-8 0a2 2 0 1 1-2 2 2 2 0 0 1 2-2zm4 14a9.23 9.23 0 0 1-8.16-4.89l1.32-.71a7.76 7.76 0 0 0 13.68 0l1.32.71A9.23 9.23 0 0 1 16 24z"/></svg>',
71 'bulb' => '<svg width="32" height="32" viewBox="0 0 32 32" style="fill:' . $icon_color . '"><path d="M16 2.25A9.76 9.76 0 0 0 6.25 12c0 3.21 2 5.68 3.52 7.48A6.28 6.28 0 0 1 11.25 23a.76.76 0 0 0 .75.75h8a.74.74 0 0 0 .74-.64 10 10 0 0 1 1.53-3.69c.24-.35.49-.7.75-1.06 1.28-1.77 2.73-3.79 2.73-6.36A9.76 9.76 0 0 0 16 2.25zM20 25.25h-8a.75.75 0 0 0 0 1.5h8a.75.75 0 0 0 0-1.5zM19 28.25h-6a.75.75 0 0 0 0 1.5h6a.75.75 0 0 0 0-1.5z"/></svg>',
72 );
73
74 if ( isset( $svg_icons[ $icon_type ] ) ) {
75 return $svg_icons[ $icon_type ];
76 }
77
78 return false;
79 }
80
81 /**
82 * Number of stars field option.
83 *
84 * @param array $field Field settings.
85 */
86 public function number_of_stars( $field ) {
87 // Input Mask.
88 $lbl = $this->field_element(
89 'label',
90 $field,
91 array(
92 'slug' => 'number_of_stars',
93 'value' => esc_html__( 'Number of Icons', 'everest-forms' ),
94 'tooltip' => esc_html__( 'Choose the number of icons.', 'everest-forms' ),
95 ),
96 false
97 );
98 $fld = $this->field_element(
99 'text',
100 $field,
101 array(
102 'type' => 'number',
103 'slug' => 'number_of_stars',
104 'class' => 'evf-number-of-stars',
105 'value' => ! empty( $field['number_of_stars'] ) ? esc_attr( $field['number_of_stars'] ) : '5',
106 'attrs' => array(
107 'min' => 2,
108 'max' => 100,
109 'pattern' => '[0-9]',
110 ),
111 ),
112 false
113 );
114 $this->field_element(
115 'row',
116 $field,
117 array(
118 'slug' => 'number_of_stars',
119 'content' => $lbl . $fld,
120 )
121 );
122 }
123
124 /**
125 * Rating icon field option.
126 *
127 * @param array $field Field settings.
128 */
129 public function rating_icon( $field ) {
130 $name = 'rating-icon';
131 $lbl = $this->field_element(
132 'label',
133 $field,
134 array(
135 'slug' => 'rating-icon',
136 'value' => esc_html__( 'Rating Icon', 'everest-forms' ),
137 'tooltip' => esc_html__( 'Select rating icon to display', 'everest-forms' ),
138 ),
139 false
140 );
141
142 $default = ! empty( $field[ $name ] ) ? $field[ $name ] : 'star';
143 $fld = '<div class="everest-forms-rating-icon-container" data-field-id="' . $field['id'] . '">';
144 $fld .= sprintf( '<input type="radio" id="rating-star-' . $field['id'] . '" name="form_fields[%s][%s]" value="star" %s/><label for="rating-star-' . $field['id'] . '">' . $this->get_icon_svg( 'full-star' ) . '</label>', $field['id'], $name, checked( 'star', $default, false ) );
145 $fld .= sprintf( '<input type="radio" id="rating-heart-' . $field['id'] . '" name="form_fields[%s][%s]" value="heart" %s/><label for="rating-heart-' . $field['id'] . '">' . $this->get_icon_svg( 'heart' ) . '</label>', $field['id'], $name, checked( 'heart', $default, false ) );
146 $fld .= sprintf( '<input type="radio" id="rating-thumb-' . $field['id'] . '" name="form_fields[%s][%s]" value="thumb" %s/><label for="rating-thumb-' . $field['id'] . '">' . $this->get_icon_svg( 'thumb' ) . '</label>', $field['id'], $name, checked( 'thumb', $default, false ) );
147 $fld .= sprintf( '<input type="radio" id="rating-smiley-' . $field['id'] . '" name="form_fields[%s][%s]" value="smiley" %s/><label for="rating-smiley-' . $field['id'] . '">' . $this->get_icon_svg( 'smiley' ) . '</label>', $field['id'], $name, checked( 'smiley', $default, false ) );
148 $fld .= sprintf( '<input type="radio" id="rating-bulb-' . $field['id'] . '" name="form_fields[%s][%s]" value="bulb" %s/><label for="rating-bulb-' . $field['id'] . '">' . $this->get_icon_svg( 'bulb' ) . '</label>', $field['id'], $name, checked( 'bulb', $default, false ) );
149 $fld .= '</div>';
150
151 $this->field_element(
152 'row',
153 $field,
154 array(
155 'slug' => 'rating-icon',
156 'content' => $lbl . $fld,
157 )
158 );
159 }
160
161 /**
162 * Icon color field option.
163 *
164 * @param array $field Field settings.
165 */
166 public function icon_color( $field ) {
167
168 $lbl = $this->field_element(
169 'label',
170 $field,
171 array(
172 'slug' => 'icon_color',
173 'value' => esc_html__( 'Icon Color', 'everest-forms' ),
174 'tooltip' => esc_html__( 'Select the primary color for the rating icon', 'everest-forms' ),
175 ),
176 false
177 );
178 $fld = $this->field_element(
179 'text',
180 $field,
181 array(
182 'slug' => 'icon_color',
183 'value' => ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : '#f2b01e',
184 'class' => 'evf-colorpicker',
185 'data' => array(
186 'default-color' => '#f2b01e',
187 ),
188 ),
189 false
190 );
191 $this->field_element(
192 'row',
193 $field,
194 array(
195 'slug' => 'icon_color',
196 'content' => $lbl . $fld,
197 )
198 );
199 }
200
201 /**
202 * Field preview inside the builder.
203 *
204 * @since 1.0.0
205 *
206 * @param array $field Field data and settings.
207 */
208 public function field_preview( $field ) {
209 // Define data.
210 $number_of_stars = ! empty( $field['number_of_stars'] ) ? esc_attr( $field['number_of_stars'] ) : 5;
211 $rating_icon = ! empty( $field['rating-icon'] ) ? esc_attr( $field['rating-icon'] ) : 'star';
212 $icon_color = ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : '#f2b01e';
213
214 switch ( $rating_icon ) {
215 case 'star':
216 $icon_class = 'star';
217 $icon = $this->get_icon_svg( 'full-star', $icon_color );
218 break;
219 case 'heart':
220 $icon_class = 'heart';
221 $icon = $this->get_icon_svg( 'heart', $icon_color );
222 break;
223 case 'thumb':
224 $icon_class = 'thumbs-up';
225 $icon = $this->get_icon_svg( 'thumb', $icon_color );
226 break;
227 case 'smiley':
228 $icon_class = 'smiley';
229 $icon = $this->get_icon_svg( 'smiley', $icon_color );
230 break;
231 case 'bulb':
232 $icon_class = 'lightbulb';
233 $icon = $this->get_icon_svg( 'bulb', $icon_color );
234 break;
235 }
236 // Label.
237 $this->field_preview_option( 'label', $field );
238
239 // Primary input.
240 for ( $i = 1; $i <= $number_of_stars; $i++ ) {
241 printf(
242 '<span class="%s rating-icon" style="margin-right:5px; display:%s; font-size:28px;">%s</span>',
243 esc_attr( $icon_class ),
244 'inline-block',
245 $icon // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
246 );
247 }
248
249 // Description.
250 $this->field_preview_option( 'description', $field );
251 }
252
253 /**
254 * Define additional field properties.
255 *
256 * @since 1.0.0
257 *
258 * @param array $properties Field properties.
259 * @param array $field Field settings.
260 * @param array $form_data Form data and settings.
261 *
262 * @return array of additional field properties.
263 */
264 public function field_properties( $properties, $field, $form_data ) {
265
266 // Number of stars.
267 $properties['inputs']['primary']['rating']['number_of_stars'] = ! empty( $field['number_of_stars'] ) ? esc_attr( $field['number_of_stars'] ) : 5;
268
269 // Rating icons size.
270 $properties['inputs']['primary']['rating']['size'] = '28';
271
272 // Rating icon color.
273 $properties['inputs']['primary']['rating']['color'] = ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : '#f2b01e';
274
275 // Rating icon SVG image.
276 $properties['inputs']['primary']['rating']['icon'] = $this->get_icon_svg( 'full-star', $properties['inputs']['primary']['rating']['color'] );
277
278 if ( ! empty( $field['rating-icon'] ) && 'heart' === $field['rating-icon'] ) {
279 $properties['inputs']['primary']['rating']['icon'] = $this->get_icon_svg( 'heart', $properties['inputs']['primary']['rating']['color'] );
280 } elseif ( ! empty( $field['rating-icon'] ) && 'thumb' === $field['rating-icon'] ) {
281 $properties['inputs']['primary']['rating']['icon'] = $this->get_icon_svg( 'thumb', $properties['inputs']['primary']['rating']['color'] );
282 } elseif ( ! empty( $field['rating-icon'] ) && 'smiley' === $field['rating-icon'] ) {
283 $properties['inputs']['primary']['rating']['icon'] = $this->get_icon_svg( 'smiley', $properties['inputs']['primary']['rating']['color'] );
284 } elseif ( ! empty( $field['rating-icon'] ) && 'bulb' === $field['rating-icon'] ) {
285 $properties['inputs']['primary']['rating']['icon'] = $this->get_icon_svg( 'bulb', $properties['inputs']['primary']['rating']['color'] );
286 }
287
288 return $properties;
289 }
290
291 /**
292 * Customize format for HTML email notifications and entry details.
293 *
294 * @param string $val Value.
295 * @param array $field_val Field value data object.
296 * @param array $form_data Form data settings.
297 * @param string $context Context usage.
298 *
299 * @return string
300 */
301 public function html_rating_value( $val, $field_val, $form_data = array(), $context = '' ) {
302 if ( is_serialized( $field_val ) ) {
303 $value = evf_maybe_unserialize( $field_val );
304
305 if ( is_array( $value ) && isset( $value['type'] ) && sanitize_text_field( wp_unslash( (string) $value['type'] ) ) === $this->type ) {
306 // Icons ref: https://emojipedia.org/.
307 $icon = isset( $value['icon'] ) ? sanitize_text_field( wp_unslash( (string) $value['icon'] ) ) : '';
308
309 switch ( $icon ) {
310 case 'smiley':
311 $emoji = '🙂';
312 break;
313 case 'heart':
314 $emoji = '❤️';
315 break;
316 case 'thumb':
317 $emoji = '👍';
318 break;
319 case 'bulb':
320 $emoji = '💡';
321 break;
322 default:
323 $emoji = '';
324 break;
325 }
326
327 $rating_value = isset( $value['value'] ) ? absint( $value['value'] ) : 0;
328 $number_of_rating = isset( $value['number_of_rating'] ) ? absint( $value['number_of_rating'] ) : 0;
329
330 if ( 'entry-table' === $context ) {
331 // For the entry list table, changed the text color of rating.
332 return sprintf(
333 '%1$s <span style="color:#ccc;">(%2$d/%3$d)</span>',
334 esc_html( str_repeat( $emoji, $rating_value ) ),
335 $rating_value,
336 $number_of_rating
337 );
338 }
339
340 if ( 'export-pdf' === $context || 'email-html' === $context ) {
341 return sprintf(
342 '<span>(%1$d/%2$d)</span>',
343 $rating_value,
344 $number_of_rating
345 );
346 }
347
348 return sprintf(
349 '%1$s (%2$d/%3$d)',
350 esc_html( str_repeat( $emoji, $rating_value ) ),
351 $rating_value,
352 $number_of_rating
353 );
354 }
355 }
356 return $val;
357 }
358
359 /**
360 * Filter callback for outputting formatted data.
361 *
362 * @param array $field Field Data.
363 */
364 public function field_exporter( $field ) {
365 $rating = '(' . absint( $field['value']['value'] ) . "/{$field['value']['number_of_rating']})";
366
367 return array(
368 'label' => ! empty( $field['name'] ) ? $field['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}",
369 'value' => $rating,
370 );
371 }
372
373 /**
374 * Field display on the form front-end.
375 *
376 * @since 1.0.0
377 *
378 * @param array $field Field Data.
379 * @param array $field_atts Field attributes.
380 * @param array $form_data All Form Data.
381 */
382 public function field_display( $field, $field_atts, $form_data ) {
383 // Define data.
384 $primary = $field['properties']['inputs']['primary'];
385 $rating = $primary['rating'];
386 $icon = $rating['icon'];
387 $value = isset( $primary['attr']['value'] ) ? $primary['attr']['value'] : 0;
388 $number_of_stars = ! empty( $rating['number_of_stars'] ) ? absint( $rating['number_of_stars'] ) : 5;
389
390 $icon = str_replace( 'width=""', 'width="' . absint( $rating['size'] ) . '"', $icon );
391 $icon = str_replace( 'height=""', 'height="' . absint( $rating['size'] ) . '"', $icon );
392 $icon = str_replace( 'style=""', 'style="height:' . absint( $rating['size'] ) . 'px;width:' . absint( $rating['size'] ) . 'px;"', $icon );
393
394 echo '<div id="evf-' . absint( $form_data['id'] ) . '-field_' . esc_attr( $field['id'] ) . '" class="everest-forms-field-rating-container">';
395
396 for ( $i = 1; $i <= $number_of_stars; $i++ ) {
397 printf(
398 '<label class="everest-forms-field-rating choice-%d %s" for="everest-forms-%d-field_%s_%d">',
399 absint( $i ),
400 $i <= $value ? 'selected' : '',
401 absint( $form_data['id'] ),
402 esc_attr( $field['id'] ),
403 absint( $i )
404 );
405
406 // Primary field.
407 $primary['id'] = sprintf(
408 'everest-forms-%d-field_%s_%d',
409 absint( $form_data['id'] ),
410 $field['id'],
411 $i
412 );
413
414 $primary['attr']['value'] = $i;
415
416 if ( ! empty( $rating['default'] ) && $i === $rating['default'] ) {
417 $primary['attr']['checked'] = 'checked';
418 } else {
419 $primary['attr']['checked'] = '';
420 }
421
422 printf(
423 '<input type="radio" %s %s>',
424 evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
425 esc_attr( $primary['required'] )
426 );
427
428 echo $icon; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
429
430 echo '</label>';
431 }
432
433 echo '</div>';
434 }
435
436 /**
437 * Edit form field display on the entry back-end.
438 *
439 * @since 1.7.0
440 *
441 * @param array $entry_field Entry field data.
442 * @param array $field Field data.
443 * @param array $form_data Form data and settings.
444 */
445 public function edit_form_field_display( $entry_field, $field, $form_data ) {
446 $value = isset( $entry_field['value']['value'] ) ? $entry_field['value']['value'] : '';
447
448 if ( '' !== $value ) {
449 $field['properties'] = $this->get_single_field_property_value( (string) $value, 'primary', $field['properties'], $field );
450 }
451
452 $this->field_display( $field, null, $form_data );
453 }
454
455 /**
456 * Formats field.
457 *
458 * @param int $field_id Field ID.
459 * @param array $field_submit Submitted field value.
460 * @param array $form_data Form data and settings.
461 * @param mixed $meta_key Meta Key.
462 */
463 public function format( $field_id, $field_submit, $form_data, $meta_key ) {
464 $name = ! empty( $form_data['form_fields'][ $field_id ]['label'] ) ? $form_data['form_fields'][ $field_id ]['label'] : '';
465 $value = ! empty( $field_submit ) ? absint( $field_submit ) : '';
466 $number_of_stars = absint( $form_data['form_fields'][ $field_id ]['number_of_stars'] );
467
468 if ( $value > $number_of_stars ) {
469 $value = '';
470 }
471
472 EVF()->task->form_fields[ $field_id ] = array(
473 'name' => make_clickable( $name ),
474 'value' => array(
475 'value' => $value,
476 'type' => $this->type,
477 'number_of_rating' => sanitize_text_field( $number_of_stars ),
478 'icon' => sanitize_text_field( $form_data['form_fields'][ $field_id ]['rating-icon'] ),
479 ),
480 'id' => $field_id,
481 'type' => $this->type,
482 'meta_key' => $meta_key,
483 );
484 }
485 }
486