PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.0.6
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.0.6
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 / shortcodes / class-evf-shortcode-form.php
everest-forms / includes / shortcodes Last commit date
class-evf-shortcode-form.php 1 year ago
class-evf-shortcode-form.php
1275 lines
1 <?php
2 /**
3 * Form Shortcode
4 *
5 * Used on the show frontend form.
6 *
7 * @package EverestForms\Shortcodes\Form
8 * @version 1.0.0
9 * @since 1.3.2
10 */
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Form Shortcode class.
16 */
17 class EVF_Shortcode_Form {
18
19 /**
20 * Contains information for multi-part forms.
21 *
22 * Forms that do not contain parts return false, otherwise returns an array
23 * that contains the number of total parts and part counter used when
24 * displaying part rows.
25 *
26 * @since 1.3.2
27 *
28 * @var array
29 */
30 public static $parts = array();
31
32 /**
33 * Hooks in tab.
34 */
35 public static function hooks() {
36 add_filter( 'amp_skip_post', array( 'EVF_Shortcode_Form', 'amp_skip_post' ) );
37 add_action( 'everest_forms_frontend_output_success', 'evf_print_notices', 10, 2 );
38 add_action( 'everest_forms_frontend_output', array( 'EVF_Shortcode_Form', 'header' ), 5, 4 );
39 add_action( 'everest_forms_frontend_output', array( 'EVF_Shortcode_Form', 'fields' ), 10, 3 );
40 add_action( 'everest_forms_display_field_before', array( 'EVF_Shortcode_Form', 'wrapper_start' ), 5, 2 );
41 add_action( 'everest_forms_display_field_before', array( 'EVF_Shortcode_Form', 'label' ), 15, 2 );
42 add_action( 'everest_forms_display_field_before', array( 'EVF_Shortcode_Form', 'description' ), 20, 2 );
43 add_action( 'everest_forms_display_field_after', array( 'EVF_Shortcode_Form', 'messages' ), 3, 2 );
44 add_action( 'everest_forms_display_field_after', array( 'EVF_Shortcode_Form', 'description' ), 5, 2 );
45 add_action( 'everest_forms_display_field_after', array( 'EVF_Shortcode_Form', 'wrapper_end' ), 15, 2 );
46 add_action( 'everest_forms_frontend_output', array( 'EVF_Shortcode_Form', 'honeypot' ), 15, 3 );
47 if ( ! apply_filters( 'everest_forms_recaptcha_disabled', false ) ) {
48 add_action( 'everest_forms_frontend_output', array( 'EVF_Shortcode_Form', 'recaptcha' ), 20, 3 );
49 }
50 add_action( 'everest_forms_frontend_output', array( 'EVF_Shortcode_Form', 'footer' ), 25, 3 );
51
52 // reCaptcha Language.
53 add_filter( 'everest_forms_frontend_recaptcha_url', array( __CLASS__, 'evf_recaptcha_language' ), 10, 1 );
54
55 // Enable for submission waiting time.
56 add_filter( 'everest_forms_display_fields_before', array( 'EVF_Shortcode_Form', 'evf_form_submission_waiting_time' ) );
57 }
58
59 /**
60 * Get the amp-state ID for a given form.
61 *
62 * @param int $form_id Form ID.
63 * @return string State ID.
64 */
65 protected static function get_form_amp_state_id( $form_id ) {
66 return sprintf( 'evf_form_state_%d', $form_id );
67 }
68
69 /**
70 * Disable AMP if query param is detected.
71 *
72 * This allows the full form to be accessible for Pro users or sites
73 * that do not have SSL.
74 *
75 * @since 1.5.3
76 *
77 * @param bool $skip Skip AMP mode, display full post.
78 *
79 * @return bool
80 */
81 public static function amp_skip_post( $skip ) {
82
83 return isset( $_GET['nonamp'] ) ? true : $skip; // phpcs:ignore WordPress.Security.NonceVerification
84 }
85
86
87 /**
88 * Form footer area.
89 *
90 * @param array $form_data Form data and settings.
91 * @param bool $title Whether to display form title.
92 * @param bool $description Whether to display form description.
93 */
94 public static function footer( $form_data, $title, $description ) {
95 $form_id = absint( $form_data['id'] );
96 $settings = isset( $form_data['settings'] ) ? $form_data['settings'] : array();
97 $submit = apply_filters( 'everest_forms_field_submit', isset( $settings['submit_button_text'] ) ? $settings['submit_button_text'] : __( 'Submit', 'everest-forms' ), $form_data );
98 $submit_btn = evf_string_translation( $form_data['id'], 'submit_button', $submit );
99 $process = '';
100 $classes = isset( $form_data['settings']['submit_button_class'] ) ? evf_sanitize_classes( $form_data['settings']['submit_button_class'] ) : '';
101 $parts = ! empty( self::$parts[ $form_id ] ) ? self::$parts[ $form_id ] : array();
102 $visible = ! empty( $parts ) ? 'style="display:none"' : '';
103 $attrs = array( 'aria-live' => 'assertive' );
104 $data_attrs = array();
105 $evf_amp_classes = array();
106
107 // Visibility class.
108 $visibility_class = apply_filters( 'everest_forms_field_submit_visibility_class', array(), $parts, $form_data );
109
110 // Check for submit button processing-text.
111 if ( ! isset( $settings['submit_button_processing_text'] ) ) {
112 $process = 'data-process-text="' . esc_attr__( 'Processing&hellip;', 'everest-forms' ) . '"';
113 } elseif ( ! empty( $settings['submit_button_processing_text'] ) ) {
114 if ( evf_is_amp() ) {
115 $attrs['[text]'] = sprintf(
116 '%s.submitting ? %s : %s',
117 self::get_form_amp_state_id( $form_id ),
118 wp_json_encode( $settings['submit_button_processing_text'], JSON_UNESCAPED_UNICODE ),
119 wp_json_encode( $submit, JSON_UNESCAPED_UNICODE )
120 );
121 } else {
122 $process = 'data-process-text="' . esc_attr( evf_string_translation( $form_data['id'], 'processing_text', $settings['submit_button_processing_text'] ) ) . '"';
123 }
124 }
125
126 // Submit button area.
127 $conditional_id = 'evf-submit-' . $form_id;
128 if ( isset( $form_data['settings']['submit']['connection_1']['conditional_logic_status'] ) && '1' === $form_data['settings']['submit']['connection_1']['conditional_logic_status'] ) {
129 $con_rules = array(
130 'conditional_option' => isset( $form_data['settings']['submit']['connection_1']['conditional_option'] ) ? $form_data['settings']['submit']['connection_1']['conditional_option'] : '',
131 'conditionals' => isset( $form_data['settings']['submit']['connection_1']['conditionals'] ) ? $form_data['settings']['submit']['connection_1']['conditionals'] : '',
132 );
133 } else {
134 $con_rules = '';
135 }
136
137 $conditional_rules = wp_json_encode( $con_rules );
138
139 echo '<div class="evf-submit-container ' . esc_attr( implode( ' ', $visibility_class ) ) . '" >';
140
141 echo '<input type="hidden" name="everest_forms[id]" value="' . absint( $form_id ) . '">';
142
143 echo '<input type="hidden" name="everest_forms[author]" value="' . absint( get_the_author_meta( 'ID' ) ) . '">';
144
145 if ( is_singular() ) {
146 echo '<input type="hidden" name="everest_forms[post_id]" value="' . absint( get_the_ID() ) . '">';
147 }
148
149 do_action( 'everest_forms_display_submit_before', $form_data );
150
151 printf(
152 "<button type='submit' name='everest_forms[submit]' class='everest-forms-submit-button button evf-submit %s' id='evf-submit-%d' value='evf-submit' %s conditional_rules='%s' conditional_id='%s' %s %s>%s</button>",
153 esc_attr( $classes ),
154 esc_attr( $form_id ),
155 ! isset( $settings['submit_button_processing_text'] ) ? 'data-process-text="' . esc_attr__( 'Processing&hellip;', 'everest-forms' ) . '"' : ( ! empty( $settings['submit_button_processing_text'] ) ? 'data-process-text="' . esc_attr( evf_string_translation( $form_data['id'], 'processing_text', $settings['submit_button_processing_text'] ) ) . '"' : '' ),
156 esc_attr( $conditional_rules ),
157 esc_attr( $conditional_id ),
158 ( ! empty( self::$parts[ $form_id ] ) ? 'style="display:none"' : '' ),
159 evf_html_attributes(
160 sprintf( 'evf-submit-%d', absint( $form_id ) ),
161 $evf_amp_classes,
162 $data_attrs,
163 $attrs
164 ),
165 esc_html( $submit_btn )
166 );
167
168 do_action( 'everest_forms_display_submit_after', $form_data );
169
170 echo '</div>';
171
172 if ( evf_is_amp() ) {
173 printf( '<div submit-success><template type="amp-mustache"><div class=" everest-forms-notice everest-forms-notice--success {{#redirecting}}evf-redirection-message{{/redirecting}}">{{{message}}}</div></template></div>' );
174 return;
175 }
176 }
177
178 /**
179 * Message.
180 *
181 * @param array $field Field.
182 * @param array $form_data Form data.
183 */
184 public static function messages( $field, $form_data ) {
185 $error = $field['properties']['error'];
186
187 if ( empty( $error['value'] ) || is_array( $error['value'] ) ) {
188 return;
189 }
190
191 printf(
192 '<label %s>%s</label>',
193 evf_html_attributes( $error['id'], $error['class'], $error['data'], $error['attr'] ),
194 esc_html( $error['value'] )
195 );
196 }
197
198 /**
199 * Description.
200 *
201 * @param array $field Field.
202 * @param array $form_data Form data.
203 */
204 public static function description( $field, $form_data ) {
205 $action = current_action();
206
207 $description = $field['properties']['description'];
208
209 // If the description is empty don't proceed.
210 if ( empty( $description['value'] ) ) {
211 return;
212 }
213
214 // Determine positioning.
215 if ( 'everest_forms_display_field_before' === $action && 'before' !== $description['position'] ) {
216 return;
217 }
218 if ( 'everest_forms_display_field_after' === $action && 'after' !== $description['position'] ) {
219 return;
220 }
221
222 if ( 'before' === $description['position'] ) {
223 $description['class'][] = 'evf-field-description-before';
224 }
225
226 printf(
227 '<div %s>%s</div>',
228 evf_html_attributes( $description['id'], $description['class'], $description['data'], $description['attr'] ),
229 wp_kses_post( evf_string_translation( $form_data['id'], $field['id'], $description['value'], '-description' ) )
230 );
231 }
232
233 /**
234 * Label.
235 *
236 * @param array $field Field.
237 * @param array $form_data Form data.
238 */
239 public static function label( $field, $form_data ) {
240
241 $label = $field['properties']['label'];
242 // If the label is empty or disabled don't proceed.
243 if ( empty( $label['value'] ) || $label['disabled'] ) {
244 return;
245 }
246
247 $required = $label['required'] ? apply_filters( 'everest_forms_field_required_label', '<abbr class="required" title="' . esc_attr__( 'Required', 'everest-forms' ) . '">' . apply_filters( 'everest_form_get_required_type', '*', $field, $form_data ) . '</abbr>' ) : '';
248 $custom_tags = apply_filters( 'everest_forms_field_custom_tags', false, $field, $form_data );
249
250 printf(
251 '<label %s><span class="evf-label">%s</span> %s</label>',
252 evf_html_attributes( $label['id'], $label['class'], $label['data'], $label['attr'] ),
253 wp_kses(
254 evf_string_translation(
255 $form_data['id'],
256 $field['id'],
257 wp_kses(
258 $label['value'],
259 array(
260 'a' => array(
261 'href' => array(),
262 'class' => array(),
263 ),
264 'span' => array(
265 'class' => array(),
266 ),
267 'em' => array(),
268 'small' => array(),
269 'strong' => array(),
270 )
271 )
272 ),
273 array(
274 'a' => array(
275 'href' => array(),
276 'class' => array(),
277 ),
278 'span' => array(
279 'class' => array(),
280 ),
281 'em' => array(),
282 'small' => array(),
283 'strong' => array(),
284 )
285 ),
286 wp_kses_post( $required ),
287 wp_kses_post( $custom_tags )
288 );
289 }
290
291 /**
292 * Wrapper end.
293 *
294 * @param array $field Field.
295 * @param array $form_data Form data.
296 */
297 public static function wrapper_end( $field, $form_data ) {
298 echo '</div>';
299 }
300
301 /**
302 * Wrapper start.
303 *
304 * @param array $field Field.
305 * @param array $form_data Form data.
306 */
307 public static function wrapper_start( $field, $form_data ) {
308 $container = $field['properties']['container'];
309 $container['data']['field-id'] = esc_attr( $field['id'] );
310 printf(
311 '<div %s>',
312 evf_html_attributes( $container['id'], $container['class'], $container['data'], $container['attr'] )
313 );
314 }
315
316 /**
317 * Form header for displaying form title and description if enabled.
318 *
319 * @param array $form_data Form data and settings.
320 * @param bool $title Whether to display form title.
321 * @param bool $description Whether to display form description.
322 * @param array $errors List of all errors during form submission.
323 */
324 public static function header( $form_data, $title, $description, $errors ) {
325 $settings = isset( $form_data['settings'] ) ? $form_data['settings'] : array();
326
327 // Check if title and/or description is enabled.
328 if ( true === $title || true === $description ) {
329 echo '<div class="evf-title-container">';
330
331 if ( true === $title && ! empty( $settings['form_title'] ) ) {
332 echo '<div class="everest-forms--title">' . esc_html( evf_string_translation( $form_data['id'], 'form_title', $settings['form_title'] ) ) . '</div>';
333 }
334
335 if ( true === $description && ! empty( $settings['form_description'] ) ) {
336 echo '<div class="everest-forms--description">' . esc_textarea( evf_string_translation( $form_data['id'], 'form_description', $settings['form_description'] ) ) . '</div>';
337 }
338
339 echo '</div>';
340 }
341
342 // Output header errors if they exist.
343 if ( ! empty( $errors['header'] ) ) {
344 evf_add_notice( $errors['header'], 'error' );
345 }
346 }
347
348 /**
349 * Form field area.
350 *
351 * @param array $form_data Form data and settings.
352 * @param bool $title Whether to display form title.
353 * @param bool $description Whether to display form description.
354 */
355 public static function fields( $form_data, $title, $description ) {
356 $structure = isset( $form_data['structure'] ) ? $form_data['structure'] : array();
357
358 // Bail if empty form fields.
359 if ( empty( $form_data['form_fields'] ) ) {
360 return;
361 }
362
363 // Form fields area.
364 echo '<div class="evf-field-container">';
365
366 wp_nonce_field( 'everest-forms_process_submit', '_wpnonce' . $form_data['id'] );
367
368 /**
369 * Hook: everest_forms_display_fields_before.
370 *
371 * @hooked EverestForms_MultiPart::display_fields_before() Multi-Part markup open.
372 */
373 do_action( 'everest_forms_display_fields_before', $form_data );
374
375 foreach ( $structure as $row_key => $row ) {
376 /**
377 * Hook: everest_forms_display_repeater_fields.
378 *
379 * @hooked EVF_Repeater_Fields->display_repeater_fields() Display Repeater Fields.
380 */
381 $is_repeater = apply_filters( 'everest_forms_display_repeater_fields', false, $row, $form_data, true );
382
383 /**
384 * Hook: everest_forms_display_row_before.
385 */
386 do_action( 'everest_forms_display_row_before', $row_key, $form_data );
387
388 $conditions = array();
389
390 if ( ! empty( $form_data['settings']['form_rows'][ 'connection_' . $row_key ] ) && ! empty( $form_data['settings']['form_rows'][ 'connection_' . $row_key ]['conditional_logic_status'] ) ) {
391 $conditions = ! empty( $form_data['settings']['form_rows'][ 'connection_' . $row_key ] ) ? $form_data['settings']['form_rows'][ 'connection_' . $row_key ] : array();
392 }
393
394 echo '<div class="evf-frontend-row" data-row="' . esc_attr( $row_key ) . '"' . esc_attr( $is_repeater ) . ' conditional_rules="' . ( isset( $conditions ) ? esc_attr( wp_json_encode( $conditions ) ) : '' ) . '">'; // @codingStandardsIgnoreLine
395
396 foreach ( $row as $grid_key => $grid ) {
397 $number_of_grid = count( $row );
398
399 echo '<div class="evf-frontend-grid evf-grid-' . absint( $number_of_grid ) . '" data-grid="' . esc_attr( $grid_key ) . '">';
400
401 if ( ! is_array( $grid ) ) {
402 $grid = array();
403 }
404
405 foreach ( $grid as $field_key ) {
406 $field = isset( $form_data['form_fields'][ $field_key ] ) ? $form_data['form_fields'][ $field_key ] : array();
407 $field = apply_filters( 'everest_forms_field_data', $field, $form_data );
408
409 if ( empty( $field ) || in_array( $field['type'], evf()->form_fields->get_pro_form_field_types(), true ) ) {
410 continue;
411 }
412
413 $should_display_field = apply_filters( "everest_forms_should_display_field_{$field['type']}", true, $field, $form_data );
414
415 if ( true !== $should_display_field ) {
416 continue;
417 }
418
419 // Get field attributes.
420 $attributes = self::get_field_attributes( $field, $form_data );
421
422 do_action( 'everest_forms_display_before_field_wrapper', $field, $form_data );
423
424 // Get field properties.
425 $properties = self::get_field_properties( $field, $form_data, $attributes );
426
427 // Add properties to the field so it's available everywhere.
428 $field['properties'] = $properties;
429
430 do_action( 'everest_forms_display_field_before', $field, $form_data );
431
432 do_action( "everest_forms_display_field_{$field['type']}", $field, $attributes, $form_data );
433
434 do_action( 'everest_forms_display_field_after', $field, $form_data );
435
436 do_action( 'everest_forms_display_after_field_wrapper', $field, $form_data );
437 }
438
439 echo '</div>';
440 }
441
442 /**
443 * Hook: everest_forms_add_remove_buttons.
444 *
445 * @hooked EVF_Repeater_Fields->add_remove_buttons() Show Add and Remove buttons.
446 */
447 do_action( 'everest_forms_add_remove_buttons', $row, $form_data, $is_repeater );
448
449 echo '</div>';
450
451 /**
452 * Hook: everest_forms_display_row_after.
453 *
454 * @hooked EverestForms_MultiPart::display_row_after() Multi-Part markup (close previous part, open next).
455 */
456 do_action( 'everest_forms_display_row_after', $row_key, $form_data );
457 }
458
459 /**
460 * Hook: everest_forms_display_fields_after.
461 *
462 * @hooked EverestForms_MultiPart::display_fields_after() Multi-Part markup open.
463 */
464 do_action( 'everest_forms_display_fields_after', $form_data );
465
466 echo '</div>';
467 }
468
469 /**
470 * Anti-spam honeypot output if configured.
471 *
472 * @since 1.4.9
473 * @param array $form_data Form data and settings.
474 */
475 public static function honeypot( $form_data ) {
476 $names = array( 'Name', 'Phone', 'Comment', 'Message', 'Email', 'Website' );
477
478 // Output the honeypot container.
479 if ( isset( $form_data['settings']['honeypot'] ) && '1' === $form_data['settings']['honeypot'] ) {
480 echo '<div class="evf-honeypot-container evf-field-hp">';
481
482 echo '<label for="evf-' . esc_attr( $form_data['id'] ) . '-field-hp" class="evf-field-label">' . esc_attr( $names[ array_rand( $names ) ] ) . '</label>';
483
484 echo '<input type="text" name="everest_forms[hp]" id="evf-' . esc_attr( $form_data['id'] ) . '-field-hp" class="input-text">';
485
486 echo '</div>';
487 }
488 }
489
490 /**
491 * Google reCAPTCHA output if configured.
492 *
493 * @param array $form_data Form data and settings.
494 */
495 public static function recaptcha( $form_data ) {
496 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', 'v2' );
497 $invisible_recaptcha = get_option( 'everest_forms_recaptcha_v2_invisible', 'no' );
498
499 if ( 'v2' === $recaptcha_type && 'no' === $invisible_recaptcha ) {
500 $site_key = get_option( 'everest_forms_recaptcha_v2_site_key' );
501 $secret_key = get_option( 'everest_forms_recaptcha_v2_secret_key' );
502 } elseif ( 'v2' === $recaptcha_type && 'yes' === $invisible_recaptcha ) {
503 $site_key = get_option( 'everest_forms_recaptcha_v2_invisible_site_key' );
504 $secret_key = get_option( 'everest_forms_recaptcha_v2_invisible_secret_key' );
505 } elseif ( 'v3' === $recaptcha_type ) {
506 $site_key = get_option( 'everest_forms_recaptcha_v3_site_key' );
507 $secret_key = get_option( 'everest_forms_recaptcha_v3_secret_key' );
508 } elseif ( 'hcaptcha' === $recaptcha_type ) {
509 $site_key = get_option( 'everest_forms_recaptcha_hcaptcha_site_key' );
510 $secret_key = get_option( 'everest_forms_recaptcha_hcaptcha_secret_key' );
511 } elseif ( 'turnstile' === $recaptcha_type ) {
512 $site_key = get_option( 'everest_forms_recaptcha_turnstile_site_key' );
513 $secret_key = get_option( 'everest_forms_recaptcha_turnstile_secret_key' );
514 $theme = get_option( 'everest_forms_recaptcha_turnstile_theme' );
515 $lang = get_option( 'everest_forms_recaptcha_recaptcha_language', 'en-GB' );
516 }
517
518 if ( ! $site_key || ! $secret_key ) {
519 return;
520 }
521 // Check that the CAPTCHA is configured for the specific form.
522 if (
523 ! isset( $form_data['settings']['recaptcha_support'] ) ||
524 '1' !== $form_data['settings']['recaptcha_support']
525 ) {
526 return;
527 }
528 if ( evf_is_amp() ) {
529 if ( 'v3' === $recaptcha_type ) {
530 printf(
531 '<amp-recaptcha-input name="everest_forms[recaptcha]" data-sitekey="%s" data-action="%s" layout="nodisplay"></amp-recaptcha-input>',
532 esc_attr( $site_key ),
533 esc_attr( 'evf_' . $form_data['id'] )
534 );
535 }
536 return; // Only v3 is supported in AMP.
537 }
538
539 if ( isset( $form_data['settings']['recaptcha_support'] ) && '1' === $form_data['settings']['recaptcha_support'] ) {
540 $form_id = isset( $form_data['id'] ) ? absint( $form_data['id'] ) : 0;
541 $visible = ! empty( self::$parts[ $form_id ] ) ? 'style="display:none;"' : '';
542 $data = apply_filters(
543 'everest_forms_frontend_recaptcha',
544 array(
545 'sitekey' => trim( sanitize_text_field( $site_key ) ),
546 ),
547 $form_data
548 );
549
550 // Load reCAPTCHA support if form supports it.
551 if ( $site_key && $secret_key ) {
552 if ( 'v2' === $recaptcha_type ) {
553 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://www.google.com/recaptcha/api.js?onload=EVFRecaptchaLoad&render=explicit', $recaptcha_type, $form_id );
554
555 if ( 'yes' === $invisible_recaptcha ) {
556 $data['size'] = 'invisible';
557 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = grecaptcha.render(el,{callback:function(){EVFRecaptchaCallback(el);}},true); el.closest("form").querySelector("button[type=submit]").recaptchaID = recaptchaID;});};
558 var EVFRecaptchaCallback = function (el) {
559 var $form = el.closest("form");
560 if( typeof jQuery !== "undefined" ){
561 if( "1" === jQuery( $form ).attr( "data-ajax_submission" ) ) {
562 el.closest( "form" ).querySelector( "button[type=submit]" ).recaptchaID = "verified";
563 jQuery( $form ).find( ".evf-submit" ).trigger( "click" );
564 } else {
565 $form.submit();
566 }
567 grecaptcha.reset();
568 }
569 };
570 ';
571 } else {
572 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = grecaptcha.render(el,{callback:function(){EVFRecaptchaCallback(el);}},true);jQuery(el).attr( "data-recaptcha-id", recaptchaID);});};';
573 $recaptcha_inline .= 'var EVFRecaptchaCallback = function(el){jQuery(el).parent().find(".evf-recaptcha-hidden").val("1").trigger("change").valid();};';
574 }
575 } elseif ( 'v3' === $recaptcha_type ) {
576 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://www.google.com/recaptcha/api.js?render=' . $site_key, $recaptcha_type, $form_id );
577 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){grecaptcha.execute("' . esc_html( $site_key ) . '",{action:"everest_form"}).then(function(token){var f=document.getElementsByName("everest_forms[recaptcha]");for(var i=0;i<f.length;i++){f[i].value = token;}});};grecaptcha.ready(EVFRecaptchaLoad);setInterval(EVFRecaptchaLoad, 110000);';
578 $recaptcha_inline .= 'grecaptcha.ready(function(){grecaptcha.execute("' . esc_html( $site_key ) . '",{action:"everest_form"}).then(function(token){var f=document.getElementsByName("everest_forms[recaptcha]");for(var i=0;i<f.length;i++){f[i].value = token;}});});';
579 } elseif ( 'hcaptcha' === $recaptcha_type ) {
580 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://hcaptcha.com/1/api.js??onload=EVFRecaptchaLoad&render=explicit', $recaptcha_type, $form_id );
581 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = hcaptcha.render(el,{callback:function(){EVFRecaptchaCallback(el);}},true);jQuery(el).attr( "data-recaptcha-id", recaptchaID);});};';
582 $recaptcha_inline .= 'var EVFRecaptchaCallback = function(el){jQuery(el).parent().find(".evf-recaptcha-hidden").val("1").trigger("change").valid();};';
583 } elseif ( 'turnstile' === $recaptcha_type ) {
584 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=EVFTurnstileLoad&render=explicit', $recaptcha_type, $form_id );
585 $recaptcha_inline = 'var EVFTurnstileLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = turnstile.render(el,{theme:"' . $theme . '",language:"' . $lang . '",callback:function(){EVFRecaptchaCallback(el);}},true);jQuery(el).attr( "data-recaptcha-id", recaptchaID);});};';
586 $recaptcha_inline .= 'var EVFRecaptchaCallback = function(el){jQuery(el).parent().find(".evf-recaptcha-hidden").val("1").trigger("change").valid();};';
587 }
588
589 // Enqueue reCaptcha scripts.
590 wp_enqueue_script(
591 'evf-recaptcha',
592 $recaptcha_api,
593 'v3' === $recaptcha_type ? array() : array( 'jquery' ),
594 'v3' === $recaptcha_type ? '3.0.0' : '2.0.0',
595 true
596 );
597
598 // Load reCaptcha callback once.
599 static $count = 1;
600 if ( 1 === $count ) {
601 wp_add_inline_script( 'evf-recaptcha', $recaptcha_inline );
602 $count++;
603 }
604
605 // Output the reCAPTCHA container.
606 $class = ( 'v3' === $recaptcha_type || ( 'v2' === $recaptcha_type && 'yes' === $invisible_recaptcha ) ) ? 'recaptcha-hidden' : '';
607 echo '<div class="evf-recaptcha-container ' . esc_attr( $class ) . '" style="display:' . ( ! empty( self::$parts[ $form_id ] ) ? 'none' : 'block' ) . '">';
608
609 if ( 'v2' === $recaptcha_type || 'hcaptcha' === $recaptcha_type || 'turnstile' === $recaptcha_type ) {
610 echo '<div ' . evf_html_attributes( '', array( 'g-recaptcha' ), $data ) . '></div>';
611
612 if ( 'hcaptcha' === $recaptcha_type && 'no' === $invisible_recaptcha || 'turnstile' === $recaptcha_type ) {
613 echo '<input type="text" name="g-recaptcha-hidden" class="evf-recaptcha-hidden" style="position:absolute!important;clip:rect(0,0,0,0)!important;height:1px!important;width:1px!important;border:0!important;overflow:hidden!important;padding:0!important;margin:0!important;" required>';
614 }
615 } else {
616 echo '<input type="hidden" name="everest_forms[recaptcha]" value="">';
617 }
618
619 echo '</div>';
620 }
621 }
622 }
623
624 /**
625 * Get field attributes.
626 *
627 * @param array $field Field.
628 * @param array $form_data Form data.
629 *
630 * @return array
631 */
632 private static function get_field_attributes( $field, $form_data ) {
633 $form_id = absint( $form_data['id'] );
634 $field_id = esc_attr( $field['id'] );
635 $attributes = array(
636 'field_class' => array( 'evf-field', 'evf-field-' . sanitize_html_class( $field['type'] ), 'form-row' ),
637 'field_id' => array( sprintf( 'evf-%d-field_%s-container', $form_id, $field_id ) ),
638 'field_style' => '',
639 'label_class' => array( 'evf-field-label' ),
640 'label_id' => '',
641 'description_class' => array( 'evf-field-description' ),
642 'description_id' => array(),
643 'input_id' => array( sprintf( 'evf-%d-field_%s', $form_id, $field_id ) ),
644 'input_class' => array(),
645 'input_data' => array(),
646 );
647
648 // Check user field defined classes.
649 if ( ! empty( $field['css'] ) ) {
650 $attributes['field_class'] = array_merge( $attributes['field_class'], evf_sanitize_classes( $field['css'], true ) );
651 }
652
653 // Check for input column layouts.
654 if ( ! empty( $field['input_columns'] ) ) {
655 if ( 'inline' === $field['input_columns'] ) {
656 $attributes['field_class'][] = 'everest-forms-list-inline';
657 } elseif ( '' !== $field['input_columns'] ) {
658 $attributes['field_class'][] = 'everest-forms-list-' . $field['input_columns'] . '-columns';
659 }
660 }
661
662 // Input class.
663 if ( ! in_array( $field['type'], array( 'checkbox', 'radio', 'payment-checkbox', 'payment-multiple' ), true ) ) {
664 $attributes['input_class'][] = 'input-text';
665 }
666
667 // Check label visibility.
668 if ( ! empty( $field['label_hide'] ) ) {
669 $attributes['label_class'][] = 'evf-label-hide';
670 }
671
672 // Check size.
673 if ( ! empty( $field['size'] ) ) {
674 $attributes['input_class'][] = 'evf-field-' . sanitize_html_class( $field['size'] );
675 }
676
677 // Check if required.
678 if ( ! empty( $field['required'] ) ) {
679 $attributes['field_class'][] = 'validate-required';
680 }
681
682 // Check if extra validation required.
683 if ( in_array( $field['type'], array( 'email', 'phone' ), true ) ) {
684 $attributes['field_class'][] = 'validate-' . esc_attr( $field['type'] );
685 }
686
687 // Check if there are errors.
688 if ( isset( evf()->task->errors[ $form_id ][ $field_id ] ) ) {
689 $attributes['input_class'][] = 'evf-error';
690 $attributes['field_class'][] = 'everest-forms-invalid';
691 }
692
693 // This filter is deprecated, filter the properties (below) instead.
694 $attributes = apply_filters( 'evf_field_atts', $attributes, $field, $form_data );
695
696 return $attributes;
697 }
698
699 /**
700 * Return base properties for a specific field.
701 *
702 * @param array $field Field data and settings.
703 * @param array $form_data Form data and settings.
704 * @param array $attributes List of field attributes.
705 *
706 * @return array
707 */
708 public static function get_field_properties( $field, $form_data, $attributes = array() ) {
709 if ( empty( $attributes ) ) {
710 $attributes = self::get_field_attributes( $field, $form_data );
711 }
712
713 // This filter is for backwards compatibility purposes.
714 $types = array( 'text', 'textarea', 'number', 'email', 'hidden', 'url', 'html', 'title', 'password', 'phone', 'address', 'checkbox', 'radio', 'select' );
715 if ( in_array( $field['type'], $types, true ) ) {
716 $field = apply_filters( "everest_forms_{$field['type']}_field_display", $field, $attributes, $form_data );
717 }
718
719 $form_id = absint( $form_data['id'] );
720 $field_id = sanitize_text_field( $field['id'] );
721
722 // Field container data.
723 $container_data = array();
724
725 // Embed required-field-message to the container if the field is required.
726 if ( isset( $field['required'] ) && ( '1' === $field['required'] || true === $field['required'] ) ) {
727 $has_sub_fields = false;
728 $sub_field_messages = array();
729 $required_validation = get_option( 'everest_forms_required_validation' );
730 if ( in_array( $field['type'], array( 'number', 'email', 'url', 'phone' ), true ) ) {
731 $required_validation = get_option( 'everest_forms_' . $field['type'] . '_validation' );
732 }
733
734 if ( 'likert' === $field['type'] ) {
735 $has_sub_fields = true;
736 $likert_rows = isset( $field['likert_rows'] ) ? $field['likert_rows'] : array();
737 $row_keys = array();
738 foreach ( $likert_rows as $row_key => $row_label ) {
739 $row_keys[] = $row_key;
740 $row_slug = 'required-field-message-' . $row_key;
741
742 $error_message = isset( $field[ $row_slug ] ) ? evf_string_translation( $form_data['id'], $field['id'], $field[ $row_slug ], '-' . $row_slug ) : $required_validation;
743 $sub_field_messages[ $row_key ] = htmlspecialchars( wp_kses( html_entity_decode( $error_message ), array() ) );
744 }
745 $container_data['row-keys'] = wp_json_encode( $row_keys );
746 } elseif ( 'address' === $field['type'] ) {
747 $has_sub_fields = true;
748 $sub_field_messages = array(
749 'address1' => isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ? $required_validation : evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message-address1'], '-required-field-message-address1' ),
750 'city' => isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ? $required_validation : evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message-city'], '-required-field-message-city' ),
751 'state' => isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ? $required_validation : evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message-state'], '-required-field-message-state' ),
752 'postal' => isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ? $required_validation : evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message-postal'], '-required-field-message-postal' ),
753 'country' => isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ? $required_validation : evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message-country'], '-required-field-message-country' ),
754 );
755 }
756
757 if ( true === $has_sub_fields ) {
758 foreach ( $sub_field_messages as $sub_field_type => $error_message ) {
759 $container_data[ 'required-field-message-' . $sub_field_type ] = htmlspecialchars( wp_kses( html_entity_decode( $error_message ), array() ) );
760
761 }
762 } else {
763 if ( isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ) {
764 $container_data['required-field-message'] = htmlspecialchars( wp_kses( html_entity_decode( $required_validation ), array() ) );
765
766 } elseif ( isset( $field['required-field-message'] ) && '' !== $field['required-field-message'] ) {
767 $required_data = evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message'], '-required-field-message' );
768 $container_data['required-field-message'] = htmlspecialchars( wp_kses( html_entity_decode( $required_data ), array() ) );
769 } else {
770 $container_data['required-field-message'] = htmlspecialchars( wp_kses( html_entity_decode( $required_validation ), array() ) );
771 }
772 }
773 }
774 $errors = isset( evf()->task->errors[ $form_id ][ $field_id ] ) ? evf()->task->errors[ $form_id ][ $field_id ] : '';
775 $defaults = isset( $_POST['everest_forms']['form_fields'][ $field_id ] ) && ( ! is_array( $_POST['everest_forms']['form_fields'][ $field_id ] ) && ! empty( $_POST['everest_forms']['form_fields'][ $field_id ] ) ) ? $_POST['everest_forms']['form_fields'][ $field_id ] : ''; // @codingStandardsIgnoreLine
776 $properties = apply_filters(
777 'everest_forms_field_properties_' . $field['type'],
778 array(
779 'container' => array(
780 'attr' => array(
781 'style' => $attributes['field_style'],
782 ),
783 'class' => $attributes['field_class'],
784 'data' => $container_data,
785 'id' => implode( '', array_slice( $attributes['field_id'], 0 ) ),
786 ),
787 'label' => array(
788 'attr' => array(
789 'for' => sprintf( 'evf-%d-field_%s', $form_id, $field_id ),
790 ),
791 'class' => $attributes['label_class'],
792 'data' => array(),
793 'disabled' => ! empty( $field['label_disable'] ) ? true : false,
794 'hidden' => ! empty( $field['label_hide'] ) ? true : false,
795 'id' => $attributes['label_id'],
796 'required' => ! empty( $field['required'] ) ? true : false,
797 'value' => ! empty( $field['label'] ) ? $field['label'] : '',
798 ),
799 'inputs' => array(
800 'primary' => array(
801 'attr' => array(
802 'name' => "everest_forms[form_fields][{$field_id}]",
803 'value' => isset( $field['default_value'] ) ? apply_filters( 'everest_forms_process_smart_tags', $field['default_value'], $form_data ) : $defaults,
804 'placeholder' => isset( $field['placeholder'] ) ? evf_string_translation( $form_data['id'], $field['id'], $field['placeholder'], '-placeholder' ) : '',
805 ),
806 'class' => $attributes['input_class'],
807 'data' => $attributes['input_data'],
808 'id' => implode( array_slice( $attributes['input_id'], 0 ) ),
809 'required' => ! empty( $field['required'] ) ? 'required' : '',
810 ),
811 ),
812 'error' => array(
813 'attr' => array(
814 'for' => sprintf( 'evf-%d-field_%s', $form_id, $field_id ),
815 ),
816 'class' => array( 'evf-error' ),
817 'data' => array(),
818 'id' => '',
819 'value' => ! empty( $errors ) ? $errors : '',
820 ),
821 'description' => array(
822 'attr' => array(),
823 'class' => $attributes['description_class'],
824 'data' => array(),
825 'id' => implode( '', array_slice( $attributes['description_id'], 0 ) ),
826 'position' => 'after',
827 'value' => ! empty( $field['description'] ) ? $field['description'] : '',
828 ),
829 ),
830 $field,
831 $form_data
832 );
833
834 return apply_filters( 'everest_forms_field_properties', $properties, $field, $form_data );
835 }
836
837 /**
838 * Output the shortcode.
839 *
840 * @param array $atts Attributes.
841 */
842 public static function output( $atts ) {
843 wp_enqueue_script( 'everest-forms' );
844 wp_enqueue_script( 'everest-forms-survey-polls-quiz-script' );
845
846 // Load jQuery flatpickr libraries. https://github.com/flatpickr/flatpickr.
847 if ( isset( $atts['id'] ) && evf_is_field_exists( $atts['id'], 'date-time' ) ) {
848 wp_enqueue_style( 'flatpickr' );
849 wp_enqueue_script( 'flatpickr' );
850 }
851
852 // Load jQuery mailcheck library - https://github.com/mailcheck/mailcheck.
853 if ( isset( $atts['id'] ) && evf_is_field_exists( $atts['id'], 'email' ) && (bool) apply_filters( 'everest_forms_mailcheck_enabled', true ) ) {
854 wp_enqueue_script( 'mailcheck' );
855 }
856
857 // Add custom CSS/JS
858 if ( isset( $atts['id'] ) ) {
859 self::add_custom_css_js( $atts['id'] );
860 }
861
862 $atts = shortcode_atts(
863 array(
864 'id' => false,
865 'type' => false,
866 'size' => false,
867 'text' => false,
868 'title' => false,
869 'description' => false,
870 ),
871 $atts,
872 'output'
873 );
874
875 // Scripts load action.
876 do_action( 'everest_forms_shortcode_scripts', $atts );
877
878 ob_start();
879 self::view( $atts );
880 echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
881 }
882
883 /**
884 * Form view.
885 *
886 * @param array $atts Attributes.
887 */
888 private static function view( $atts ) {
889 $id = isset( $atts['id'] ) ? $atts['id'] : false;
890 $title = isset( $atts['title'] ) ? $atts['title'] : false;
891 $description = isset( $atts['description'] ) ? $atts['description'] : false;
892 $popup_type = isset( $atts['type'] ) ? $atts['type'] : false;
893 $popup_text = isset( $atts['text'] ) ? $atts['text'] : false;
894 if ( empty( $id ) ) {
895 return;
896 }
897
898 // Grab the form data, if not found then we bail.
899 $form = evf()->form->get( (int) $id );
900
901 if ( empty( $form ) || 'publish' !== $form->post_status ) {
902 return;
903 }
904
905 // Basic form information.
906 $form_data = apply_filters( 'everest_forms_frontend_form_data', evf_decode( $form->post_content ) );
907 $form_id = absint( $form->ID );
908 $settings = isset( $form_data['settings'] ) ? $form_data['settings'] : array();
909 $action = esc_url_raw( remove_query_arg( 'evf-forms' ) );
910 $title = filter_var( $title, FILTER_VALIDATE_BOOLEAN );
911 $description = filter_var( $description, FILTER_VALIDATE_BOOLEAN );
912 $errors = isset( evf()->task->errors[ $form_id ] ) ? evf()->task->errors[ $form_id ] : array();
913 $form_enabled = isset( $form_data['form_enabled'] ) ? absint( $form_data['form_enabled'] ) : 1;
914 $kff_enabled = isset( $settings['keyboard_friendly_form'] ) ? absint( $settings['keyboard_friendly_form'] ) : 0;
915 $disable_message = isset( $form_data['settings']['form_disable_message'] ) ? evf_string_translation( $form_data['id'], 'form_disable_message', $form_data['settings']['form_disable_message'] ) : __( 'This form is disabled.', 'everest-forms' );
916 if ( ( isset( $form_data['payments']['stripe']['enable_stripe'] ) && '1' === $form_data['payments']['stripe']['enable_stripe'] ) || ( isset( $form_data['payments']['square']['enable_square'] ) && '1' === $form_data['payments']['square']['enable_square'] ) ) {
917 $ajax_form_submission = isset( $settings['ajax_form_submission'] ) ? 1 : 0;
918 } else {
919 $ajax_form_submission = isset( $settings['ajax_form_submission'] ) ? $settings['ajax_form_submission'] : 0;
920 }
921
922 if ( 0 !== evf_string_to_bool( $ajax_form_submission ) ) {
923 wp_enqueue_script( 'everest-forms-ajax-submission' );
924 }
925
926 // If the form is disabled or does not contain any fields do not proceed.
927 if ( empty( $form_data['form_fields'] ) ) {
928 echo '<!-- Everest Forms: no fields, form hidden -->';
929 return;
930 } elseif ( 1 !== $form_enabled ) {
931 if ( ! empty( $disable_message ) ) {
932 printf( '<p class="everst-forms-form-disable-notice everest-forms-notice everest-forms-notice--info">%s</p>', esc_textarea( $disable_message ) );
933 }
934 return;
935 }
936
937 // We need to stop output processing in case we are on AMP page.
938 if ( evf_is_amp( false ) && ( ! current_theme_supports( 'amp' ) || apply_filters( 'evfforms_amp_pro', class_exists( 'EverestForms_Pro' ) ) || ! is_ssl() || ! defined( 'AMP__VERSION' ) || version_compare( AMP__VERSION, '1.2', '<' ) ) ) {
939
940 $full_page_url = home_url( add_query_arg( 'nonamp', '1' ) . '#evfforms-' . absint( $form->ID ) );
941
942 /**
943 * Allow modifying the text or url for the full page on the AMP pages.
944 *
945 * @since 1.4.1.1
946 * @since 1.7.1 Added $form_id, $full_page_url, and $form_data arguments.
947 *
948 * @param int $form_id Form id.
949 * @param array $form_data Form data and settings.
950 *
951 * @return string
952 */
953 $text = (string) apply_filters(
954 'evf_frontend_shortcode_amp_text',
955 sprintf( /* translators: %s - URL to a non-amp version of a page with the form. */
956 __( '<a href="%s">Go to the full page</a> to view and submit the form.', 'everest-forms' ),
957 esc_url( $full_page_url )
958 ),
959 $form_id,
960 $full_page_url,
961 $form_data
962 );
963
964 printf(
965 '<p class="evf-shortcode-amp-text">%s</p>',
966 wp_kses_post( $text )
967 );
968
969 return;
970 }
971
972 // Before output hook.
973 do_action( 'everest_forms_frontend_output_before', $form_data, $form );
974
975 // Check for return hash.
976 if (
977 ! empty( $_GET['everest_forms_return'] ) // phpcs:ignore WordPress.Security.NonceVerification
978 && evf()->task->is_valid_hash
979 && absint( evf()->task->form_data['id'] ) === $form_id
980 ) {
981 $query_args = base64_decode( $_GET['everest_forms_return'] ); // phpcs:ignore
982 parse_str( $query_args, $query_arg );
983 $message = isset( $form_data['settings']['successful_form_submission_message'] ) ? $form_data['settings']['successful_form_submission_message'] : esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'everest-forms' );
984 $pdf_submission = isset( $form_data['settings']['pdf_submission']['enable_pdf_submission'] ) && 0 !== $form_data['settings']['pdf_submission']['enable_pdf_submission'] ? $form_data['settings']['pdf_submission'] : '';
985 if ( defined( 'EVF_PDF_SUBMISSION_VERSION' ) && ( 'yes' === get_option( 'everest_forms_pdf_download_after_submit', 'no' ) || ( isset( $pdf_submission['everest_forms_pdf_download_after_submit'] ) && 'yes' === $pdf_submission['everest_forms_pdf_download_after_submit'] ) ) ) {
986 global $__everest_form_id;
987 global $__everest_form_entry_id;
988 $__everest_form_id = $form_id;
989 $__everest_form_entry_id = isset( $query_arg['entry_id'] ) ? $query_arg['entry_id'] : 0;
990 }
991
992 if ( 'same' === $form_data['settings']['redirect_to'] ) {
993 evf_add_notice( $message, 'success' );
994 }
995
996 do_action( 'everest_forms_frontend_output_success', evf()->task->form_data, evf()->task->form_fields, evf()->task->entry_id );
997 return;
998 }
999
1000 $success = apply_filters( 'everest_forms_success', false, $form_id );
1001 if ( $success && ! empty( $form_data ) ) {
1002 do_action( 'everest_forms_frontend_output_success', $form_data );
1003 return;
1004 }
1005
1006 // Allow filter to return early if some condition is not meet.
1007 if ( ! apply_filters( 'everest_forms_frontend_load', true, $form_data ) ) {
1008 do_action( 'everest_forms_frontend_not_loaded', $form_data, $form );
1009 return;
1010 }
1011
1012 /**
1013 * BW compatiable for multi-parts form.
1014 *
1015 * @todo Remove in Major EVF version 1.6.0
1016 */
1017 if ( defined( 'EVF_MULTI_PART_PLUGIN_FILE' ) ) {
1018 include_once ABSPATH . 'wp-admin/includes/plugin.php';
1019 $plugin_data = get_plugin_data( EVF_MULTI_PART_PLUGIN_FILE, false, false );
1020
1021 if ( version_compare( $plugin_data['Version'], '1.3.0', '<' ) ) {
1022 $settings_defaults = array(
1023 'indicator' => 'progress',
1024 'indicator_color' => '#7e3bd0',
1025 'nav_align' => 'center',
1026 );
1027
1028 if ( isset( $form_data['settings']['enable_multi_part'] ) && evf_string_to_bool( $form_data['settings']['enable_multi_part'] ) ) {
1029 $settings = isset( $form_data['settings']['multi_part'] ) ? $form_data['settings']['multi_part'] : array();
1030
1031 if ( ! empty( $form_data['multi_part'] ) ) {
1032 self::$parts = array(
1033 'total' => count( $form_data['multi_part'] ),
1034 'current' => 1,
1035 'parts' => array_values( $form_data['multi_part'] ),
1036 'settings' => wp_parse_args( $settings, $settings_defaults ),
1037 );
1038 }
1039 } else {
1040 self::$parts = array(
1041 'total' => '',
1042 'current' => '',
1043 'parts' => array(),
1044 'settings' => $settings_defaults,
1045 );
1046 }
1047 }
1048 }
1049
1050 // Allow Multi-Part to be customized.
1051 $parts = ! empty( self::$parts[ $form_id ] ) ? self::$parts[ $form_id ] : array();
1052 self::$parts[ $form_id ] = apply_filters( 'everest_forms_parts_data', $parts, $form_data, $form_id );
1053
1054 // Allow final action to be customized.
1055 $action = apply_filters( 'everest_forms_frontend_form_action', $action, $form_data );
1056
1057 // Allow form container classes to be filtered and user defined classes.
1058 $classes = apply_filters( 'everest_forms_frontend_container_class', array(), $form_data );
1059 if ( ! empty( $settings['form_class'] ) ) {
1060 $classes = array_merge( $classes, explode( ' ', $settings['form_class'] ) );
1061 }
1062 if ( ! empty( $settings['layout_class'] ) ) {
1063 $classes = array_merge( $classes, explode( ' ', $settings['layout_class'] ) );
1064 }
1065 $classes = evf_sanitize_classes( $classes, true );
1066
1067 $form_atts = array(
1068 'id' => sprintf( 'evf-form-%d', absint( $form_id ) ),
1069 'class' => array( 'everest-form' ),
1070 'data' => array(
1071 'formid' => absint( $form_id ),
1072 'ajax_submission' => $ajax_form_submission,
1073 'keyboard_friendly_form' => $kff_enabled,
1074 ),
1075 'atts' => array(
1076 'method' => 'post',
1077 'enctype' => 'multipart/form-data',
1078 'action' => esc_url( $action ),
1079 ),
1080 );
1081
1082 if ( evf_is_amp() ) {
1083
1084 // Set submitting state.
1085 if ( ! isset( $form_atts['atts']['on'] ) ) {
1086 $form_atts['atts']['on'] = '';
1087 } else {
1088 $form_atts['atts']['on'] .= ';';
1089 }
1090 $form_atts['atts']['on'] .= sprintf(
1091 'submit:AMP.setState( %1$s ); submit-success:AMP.setState( %2$s ); submit-error:AMP.setState( %2$s );',
1092 wp_json_encode(
1093 array(
1094 self::get_form_amp_state_id( $form_id ) => array(
1095 'submitting' => true,
1096 ),
1097 )
1098 ),
1099 wp_json_encode(
1100 array(
1101 self::get_form_amp_state_id( $form_id ) => array(
1102 'submitting' => false,
1103 ),
1104 )
1105 )
1106 );
1107
1108 // Upgrade the form to be an amp-form to avoid sanitizer conversion.
1109 if ( isset( $form_atts['atts']['action'] ) ) {
1110 $form_atts['atts']['action-xhr'] = $form_atts['atts']['action'];
1111 unset( $form_atts['atts']['action'] );
1112
1113 $form_atts['atts']['verify-xhr'] = $form_atts['atts']['action-xhr'];
1114 }
1115 }
1116
1117 $form_atts = apply_filters( 'everest_forms_frontend_form_atts', $form_atts, $form_data );
1118 // Begin to build the output.
1119 do_action( 'everest_forms_frontend_output_container_before', $form_data, $form );
1120
1121 printf( '<div class="evf-container %s" id="evf-%d">', esc_attr( $classes ), absint( $form_id ) );
1122
1123 do_action( 'everest_forms_frontend_output_form_before', $form_data, $form, $errors );
1124 if ( isset( $atts['type'] ) && 'popup-button' === $popup_type ) {
1125 printf( "<button class='everest-forms-modal-link everest-forms-modal-link-%s'>%s</button>", esc_attr( $atts['id'] ), esc_html( $popup_text ) );
1126 do_action( 'everest_form_popup', $atts );
1127 } elseif ( isset( $atts['type'] ) && 'popup-link' === $popup_type ) {
1128 printf( "<a href='javascript:void(0);' class='everest-forms-modal-link everest-forms-modal-link-%s'>%s</a>", esc_attr( $atts['id'] ), esc_html( $popup_text ) );
1129 do_action( 'everest_form_popup', $atts );
1130 } elseif ( isset( $atts['type'] ) && 'popup' === $popup_type ) {
1131 do_action( 'everest_form_popup', $atts );
1132 } else {
1133 echo '<form ' . evf_html_attributes( $form_atts['id'], $form_atts['class'], $form_atts['data'], $form_atts['atts'] ) . '>';
1134 if ( evf_is_amp() ) {
1135 $state = array(
1136 'submitting' => false,
1137 );
1138 printf(
1139 '<amp-state id="%s"><script type="application/json">%s</script></amp-state>',
1140 self::get_form_amp_state_id( $form_id ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1141 wp_json_encode( $state )
1142 );
1143 }
1144 do_action( 'everest_forms_frontend_output', $form_data, $title, $description, $errors );
1145
1146 echo '</form>';
1147 }
1148
1149 do_action( 'everest_forms_frontend_output_form_after', $form_data, $form );
1150
1151 echo '</div><!-- .evf-container -->';
1152
1153 // After output hook.
1154 do_action( 'everest_forms_frontend_output_after', $form_data, $form );
1155
1156 // Debug information.
1157 if ( is_super_admin() ) {
1158 evf_debug_data( $form_data );
1159 }
1160 }
1161
1162 /**
1163 * ReCaptcha Langauge.
1164 *
1165 * @param url $url Recaptcha URL.
1166 *
1167 * @return $url
1168 */
1169 public static function evf_recaptcha_language( $url ) {
1170 return esc_url_raw( add_query_arg( array( 'hl' => get_option( 'everest_forms_recaptcha_recaptcha_language', 'en-GB' ) ), $url ) );
1171 }
1172
1173 /**
1174 * Adds custom CSS and JavaScript code.
1175 *
1176 * @param int $form_id Form ID.
1177 * @since 2.0.2
1178 * @return void
1179 */
1180 public static function add_custom_css_js( $form_id ) {
1181 $form_id = absint( $form_id );
1182 if ( $form_id <= 0 ) {
1183 return;
1184 }
1185
1186 $form = evf()->form->get( $form_id );
1187 // Check the form_data exist or not.
1188 if ( ! $form ) {
1189 return;
1190 }
1191
1192 $hook = false;
1193
1194 if ( ! did_action( 'wp_head' ) ) {
1195 $hook = 'wp_head';
1196 } elseif ( ! did_action( 'wp_footer' ) ) {
1197 $hook = 'wp_footer';
1198 }
1199
1200 $form_data = apply_filters( 'everest_forms_frontend_form_data', evf_decode( $form->post_content ) );
1201 $settings = isset( $form_data['settings'] ) ? $form_data['settings'] : array();
1202
1203 if ( isset( $settings['evf-enable-custom-css'] ) && evf_string_to_bool( $settings['evf-enable-custom-css'] ) ) {
1204 $custom_css = isset( $settings['evf-custom-css'] ) ? $settings['evf-custom-css'] : '';
1205 $custom_css = preg_match( '#</?\w+#', $custom_css ) ? '' : $custom_css;
1206 if ( ! empty( $custom_css ) ) {
1207 if ( $hook ) {
1208 add_action(
1209 $hook,
1210 function () use ( $custom_css, $form_id ) {
1211 ?>
1212 <style id="<?php echo esc_attr( 'evf-custom-css-' . $form_id ); ?>">
1213 <?php echo esc_attr( $custom_css ); ?>
1214 </style>
1215 <?php
1216 }
1217 );
1218 } else {
1219 ?>
1220 <style id="<?php echo esc_attr( 'evf-custom-css-' . $form_id ); ?>">
1221 <?php echo esc_attr( $custom_css ); ?>
1222 </style>
1223 <?php
1224 }
1225 }
1226 }
1227
1228 if ( isset( $settings['evf-enable-custom-js'] ) && evf_string_to_bool( $settings['evf-enable-custom-js'] ) ) {
1229 $custom_js = isset( $settings['evf-custom-js'] ) ? wp_specialchars_decode( wp_kses_decode_entities( $settings['evf-custom-js'] ) ) : '';
1230 if ( ! empty( $custom_js ) ) {
1231 $custom_js = sprintf(
1232 '( function( $ ) {
1233 $(document).ready( function() {
1234 try {
1235 %s
1236 }
1237 catch( err ) {}
1238 });
1239 })( jQuery )',
1240 $custom_js
1241 );
1242
1243 wp_register_script(
1244 'evf-custom',
1245 '',
1246 array( 'jquery' ),
1247 EVF_VERSION,
1248 true
1249 );
1250
1251 wp_add_inline_script( 'evf-custom', $custom_js );
1252 wp_enqueue_script( 'evf-custom' );
1253 }
1254 }
1255 }
1256
1257 /**
1258 * Function to enable the minimum form submission waiting time.
1259 *
1260 * @since 3.0.2
1261 *
1262 * @param array $form_data Form Data.
1263 */
1264 public static function evf_form_submission_waiting_time( $form_data ) {
1265 $form_submission_waiting_time_enable = isset( $form_data['settings']['form_submission_min_waiting_time'] ) ? $form_data['settings']['form_submission_min_waiting_time'] : '';
1266 $submission_duration = isset( $form_data['settings']['form_submission_min_waiting_time_input'] ) ? $form_data['settings']['form_submission_min_waiting_time_input'] : '';
1267
1268 if ( '1' === $form_submission_waiting_time_enable ) {
1269 echo "<input type='hidden' id='evf_submission_start_time' name='evf_submission_start_time'/>";
1270 } else {
1271 return '';
1272 }
1273 }
1274 }
1275