PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.1.6
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.1.6
1.10.1.1 1.10.1 1.10.0.5 trunk 1.1.4 1.1.4.2 1.1.5 1.1.5.1 1.1.6 1.1.6.1 1.1.7 1.1.7.1 1.1.7.2 1.1.8 1.1.8.1 1.1.8.2 1.1.8.3 1.1.8.4 1.10.0.1 1.10.0.2 1.10.0.3 1.10.0.4 1.2.0 1.2.0.1 1.2.1 1.2.2 1.2.2.1 1.2.2.2 1.2.3 1.2.3.1 1.2.3.2 1.2.4 1.2.4.1 1.2.5 1.2.5.1 1.2.6 1.2.7 1.2.8 1.2.8.1 1.2.9 1.3.0 1.3.1 1.3.1.1 1.3.1.2 1.3.2 1.3.3 1.3.5 1.3.6 1.3.6.1 1.3.6.2 1.3.7.2 1.3.7.3 1.3.7.4 1.3.8 1.3.9.1 1.4.0.1 1.4.1.1 1.4.2 1.4.2.1 1.4.2.2 1.4.3 1.4.4 1.4.4.1 1.4.5 1.4.5.1 1.4.5.2 1.4.5.3 1.4.6 1.4.7.1 1.4.7.2 1.4.8.1 1.4.9 1.5.0.1 1.5.0.3 1.5.0.4 1.5.1 1.5.1.1 1.5.1.3 1.5.2.1 1.5.2.2 1.5.2.3 1.5.3 1.5.3.1 1.5.4.1 1.5.4.2 1.5.5 1.5.5.1 1.5.6 1.5.6.2 1.5.7 1.5.8.2 1.5.9.1 1.5.9.4 1.5.9.5 1.6.0.1 1.6.0.2 1.6.1 1.6.2.2 1.6.2.3 1.6.3.1 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.7 1.6.7.1 1.6.7.2 1.6.7.3 1.6.8 1.6.8.1 1.6.9 1.7.0 1.7.1.1 1.7.1.2 1.7.2 1.7.2.1 1.7.3 1.7.4 1.7.4.1 1.7.4.2 1.7.5.1 1.7.5.2 1.7.5.3 1.7.5.5 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.7.9.1 1.8.0.1 1.8.0.2 1.8.1.1 1.8.1.2 1.8.1.3 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.3.1 1.8.4 1.8.4.1 1.8.5.2 1.8.5.3 1.8.5.4 1.8.6.2 1.8.6.3 1.8.6.4 1.8.7.2 1.8.8.2 1.8.8.3 1.8.9.1 1.8.9.2 1.8.9.4 1.8.9.5 1.8.9.6 1.9.0.1 1.9.0.2 1.9.0.3 1.9.0.4 1.9.1.1 1.9.1.2 1.9.1.3 1.9.1.4 1.9.1.5 1.9.1.6 1.9.2.1 1.9.2.2 1.9.2.3 1.9.3.1 1.9.3.2 1.9.4.1 1.9.4.2 1.9.5 1.9.5.1 1.9.5.2 1.9.6 1.9.6.1 1.9.6.2 1.9.7.1 1.9.7.2 1.9.7.3 1.9.8.1 1.9.8.2 1.9.8.4 1.9.8.7 1.9.9.2 1.9.9.3 1.9.9.4
wpforms-lite / includes / class-frontend.php
wpforms-lite / includes Last commit date
admin 10 years ago emails 10 years ago fields 10 years ago templates 10 years ago class-fields.php 10 years ago class-form.php 10 years ago class-frontend.php 10 years ago class-install.php 10 years ago class-logging.php 10 years ago class-process.php 10 years ago class-smart-tags.php 10 years ago class-templates.php 10 years ago class-widget.php 10 years ago functions.php 10 years ago
class-frontend.php
712 lines
1 <?php
2 /**
3 * Form front-end rendering.
4 *
5 * @package WPForms
6 * @author WPForms
7 * @since 1.0.0
8 * @license GPL-2.0+
9 * @copyright Copyright (c) 2016, WPForms LLC
10 */
11 class WPForms_Frontend {
12
13 /**
14 * Contains form data to be referenced later.
15 *
16 * @since 1.0.0
17 * @var array
18 */
19 public $forms;
20
21 /**
22 * Primary class constructor.
23 *
24 * @since 1.0.0
25 */
26 public function __construct() {
27
28 $this->forms = array();
29
30 // Actions
31 add_action( 'wpforms_frontend_output_success', array( $this, 'confirmation' ), 10, 2 );
32 add_action( 'wpforms_frontend_output', array( $this, 'head' ), 5, 5 );
33 add_action( 'wpforms_frontend_output', array( $this, 'fields' ), 10, 5 );
34 add_action( 'wpforms_frontend_output', array( $this, 'honeypot' ), 15, 5 );
35 add_action( 'wpforms_frontend_output', array( $this, 'recaptcha' ), 20, 5 );
36 add_action( 'wpforms_frontend_output', array( $this, 'foot' ), 25, 5 );
37 add_action( 'wp_enqueue_scripts', array( $this, 'assets_header' ) );
38 add_action( 'wp_footer', array( $this, 'assets_footer' ) );
39 add_action( 'wp_footer', array( $this, 'footer_end' ), 99 );
40
41 // Register shortcode
42 add_shortcode( 'wpforms', array( $this, 'shortcode' ) );
43 }
44
45 /**
46 * Primary function to render a form on the frontend.
47 *
48 * @since 1.0.0
49 * @param int $id
50 * @param boolean $title
51 * @param boolean $description
52 */
53 public function output( $id, $title = false, $description = false ) {
54
55 // Grab the form data, if not found then we bail
56 $form = wpforms()->form->get( (int) $id );
57 if ( ! $form )
58 return;
59
60 // Fetch basic information
61 $form_data = wpforms_decode( $form->post_content, true );
62 $form_id = absint( $form->ID );
63 $settings = $form_data['settings'];
64 $action = esc_url_raw( remove_query_arg( 'wpforms' ) );
65 $class[] = wpforms_setting( 'disable-css', '1' ) == '1' ? 'wpforms-container-full' : '';
66 $errors = empty( wpforms()->process->errors[$form->ID] ) ? array() : wpforms()->process->errors[$form->ID];
67 $success = false;
68
69 // If the form does not contain any fields do not proceed
70 if ( empty( $form_data['fields'] ) ) {
71 echo '<!-- WPForms: no fields, form hidden -->';
72 return;
73 }
74
75 // Before output hook
76 do_action( 'wpforms_frontend_output_before', $form_data, $form );
77
78 // Check for return hash OR error free completed form and confirmation before we continue
79 if ( !empty( $_GET['wpforms_return'] ) ) {
80 $success = wpforms()->process->validate_return_hash( $_GET['wpforms_return'] );
81 if ( $success ) {
82 $form_data = wpforms()->form->get( $success, array( 'content_only' => true ) );
83 }
84 } elseif ( !empty( $_POST['wpforms']['id'] ) && $form->ID == $_POST['wpforms']['id'] && empty( $errors ) ) {
85 $success = true;
86 }
87 if ( $success && !empty( $form_data ) ) {
88
89 do_action( 'wpforms_frontend_output_success', $form_data );
90
91 // Debug
92 wpforms_debug_data( $_POST );
93
94 return;
95 }
96
97 // Allow filter to return early if some condition is not met.
98 if ( ! apply_filters( 'wpforms_frontend_load', true, $form_data, $form ) ) {
99 return;
100 }
101
102 // Prep the form action URL, allow filter
103 if ( !empty( $settings['confirmation_type'] ) && 'message' == $settings['confirmation_type'] && !empty( $settings['confirmation_message_scroll'] ) ) {
104 $action .= '#wpforms-' . $form_id;
105 }
106 $action = apply_filters( 'wpforms_frontend_form_action', $action, $form_data, $form );
107
108 // Allow form container classes to be filtered
109 $class = array_map( 'sanitize_html_class', apply_filters( 'wpforms_frontend_container_class', $class, $form_data ) );
110
111 // Begin to build the output
112 echo '<div class="wpforms-container ' . implode( ' ', $class ) . '" id="wpforms-' . $form_id . '">';
113
114 echo '<form method="post" enctype="multipart/form-data" id="wpforms-form-' . $form_id . '" action="' . $action . '" class="wpforms-validate wpforms-form" data-formid="' . $form_id . '">';
115
116 do_action( 'wpforms_frontend_output', $form_data, $form, $title, $description, $errors );
117
118 echo '</form>';
119
120 echo '</div>';
121
122 // After output hook
123 do_action( 'wpforms_frontend_output_after', $form_data, $form );
124
125 $this->forms[$form_id] = $form_data;
126
127 // Debug
128 wpforms_debug_data( $form_data );
129 }
130
131 /**
132 * Display form confirmation message.
133 *
134 * @since 1.0.0
135 * @param array $form_data
136 * @param mixed $title
137 * @param mixed $description
138 */
139 function confirmation( $form_data ) {
140
141 if ( !empty( $form_data['settings']['confirmation_type'] ) && 'message' == $form_data['settings']['confirmation_type'] ) {
142
143 // Load confirmatiom specific asssets
144 $this->assets_confirmation();
145
146 $message = apply_filters( 'wpforms_frontend_confirmation_message', $form_data['settings']['confirmation_message'], $form_data );
147
148 $class = wpforms_setting( 'disable-css', '1' ) == '1' ? 'wpforms-confirmation-container-full' : 'wpforms-confirmation-container';
149
150 echo '<div class="' . $class . '" id="wpforms-confirmation-' . absint( $form_data['id'] ) . '">';
151
152 echo wpautop( $message );
153
154 echo '</div>';
155 }
156 }
157
158 /**
159 * Form head area.
160 *
161 * @since 1.0.0
162 * @param array $form_data
163 * @param object $form
164 * @param mixed $title
165 * @param mixed $description
166 */
167 public function head( $form_data, $form, $title, $description, $errors ) {
168
169 // Output title and/or desc
170 if ( $title || $description ) {
171
172 echo '<div class="wpforms-head-container">';
173
174 if ( $title && !empty( $form->post_title ) ) {
175 echo '<div class="wpforms-title">' . esc_html( $form->post_title ) . '</div>';
176 }
177
178 if ( $description && !empty( $form->post_excerpt ) ) {
179 echo '<div class="wpforms-description">' . $form->post_excerpt . '</div>';
180 }
181
182 echo '</div>';
183 }
184
185 // Output errors if they exist
186 if ( !empty( $errors['header'] ) ) {
187
188 echo '<div class="wpforms-error-container">';
189
190 echo esc_html( $errors['header'] );
191
192 echo '</div>';
193 }
194 }
195
196 /**
197 * Form field area.
198 *
199 * @since 1.0.0
200 * @param array $form_data
201 * @param object $form
202 * @param mixed $title
203 * @param mixed $description
204 */
205 public function fields( $form_data, $form, $title, $description ) {
206
207 if ( empty( $form_data['fields'] ) )
208 return;
209
210 $fields = $form_data['fields'];
211 $pagebreak = wpforms_has_pagebreak( $form_data );
212 $page = 0;
213
214 // Form fields area
215 echo '<div class="wpforms-field-container">';
216
217 if ( $pagebreak ) {
218 echo '<div class="wpforms-page wpforms-page-1 wpforms-active">';
219 }
220
221 foreach ( $fields as $field ) {
222
223 if ( $field['type'] == 'pagebreak' ) {
224 $page++;
225 $form_data['page_total'] = $pagebreak;
226 $form_data['page_current'] = $page;
227 }
228
229 $field = apply_filters( 'wpforms_field_data', $field, $form_data );
230
231 // Basic generic attributes for easy filtering
232 $field_atts = array(
233 'field_class' => array(
234 'wpforms-field',
235 'wpforms-field-' . sanitize_html_class( $field['type'] ),
236 ),
237 'field_id' => array(
238 'wpforms-' . absint( $form_data['id'] ) . '-field_' . absint( $field['id'] ) . '-container',
239 ),
240 'field_style' => '',
241 'label_class' => array(
242 'wpforms-field-label',
243 ),
244 'label_id' => array(),
245 'description_class' => array(
246 'wpforms-field-description'
247 ),
248 'description_id' => array(),
249 'input_id' => array(
250 'wpforms-' . absint( $form_data['id'] ) . '-field_' . absint( $field['id'] ),
251 ),
252 'input_class' => array(),
253 'input_data' => array(),
254 );
255
256 // Check user defined classes
257 if ( !empty( $field['css'] ) ) {
258 $user_classes = explode( ' ', str_replace('.', '', $field['css'] ) );
259 foreach( $user_classes as $user_class ) {
260 $field_atts['field_class'][] = sanitize_html_class( $user_class );
261 }
262 }
263 // Check size
264 if ( !empty( $field['size'] ) ) {
265 $field_atts['input_class'][] = 'wpforms-field-' . sanitize_html_class( $field['size'] );
266 }
267 // Check if required
268 if ( !empty( $field['required'] ) ) {
269 $field_atts['input_class'][] = 'wpforms-field-required';
270 }
271 // Check if there are errors
272 if ( !empty( wpforms()->process->errors[$form_data['id']][$field['id']] ) ) {
273 $field_atts['input_class'][] = 'wpforms-error';
274 }
275
276 $field_atts = apply_filters( 'wpforms_field_atts', $field_atts, $field, $form_data );
277
278 echo '<div class="' . implode( ' ', $field_atts['field_class'] ) . '" id="' . implode( ' ', $field_atts['field_id'] ) . '" style="' . esc_html( $field_atts['field_style'] ) . '">';
279
280 // Display label if we have one
281 if ( !empty( $field['label'] ) ) {
282
283 // Check special flat that allows fields to disable labels on front-end
284 if ( empty( $field['label_disable'] ) ) {
285
286 // If user has decided to hide the label, hide it using a special
287 // CSS class in an attempt to keep it readable by screen readers
288 if ( !empty( $field['label_hide'] ) ) {
289 $field_atts['label_class'][] = 'wpforms-label-hide';
290 }
291
292 echo '<label for="wpforms-' . absint( $form_data['id'] ) . '-field_' . absint( $field['id'] ) . '" class="' . implode( ' ', $field_atts['label_class'] ) . '" id="' . implode( ' ', $field_atts['label_id'] ) . '">';
293
294 echo esc_html( $field['label'] );
295
296 if ( !empty( $field['required'] ) ) {
297 echo apply_filters( 'wpforms_field_required_label', ' <span class="wpforms-required-label">*</span>' );
298 }
299
300 echo '</label>';
301
302 }
303 }
304
305 // Trigger the method to output this field type
306 do_action( "wpforms_display_field_{$field['type']}", $field, $field_atts, $form_data );
307
308 // Display errors if we have one
309 if ( !empty( wpforms()->process->errors[$form_data['id']][$field['id']] ) ) {
310
311 $error = wpforms()->process->errors[$form_data['id']][$field['id']];
312
313 // For some advanced fields with multiple inputs (such
314 // as address or name fields) we handle the displaying
315 // the error within the field class. In these instances
316 // the field error container will be an array. So below
317 // we only show the error message for normal fields.
318 if ( !is_array( $error ) ) {
319 echo '<label id="wpforms-field_' . intval( $field['id'] ) . '-error" class="wpforms-error" for="wpforms-field_' . intval( $field['id'] ) . '">' . esc_html( wpforms()->process->errors[$form_data['id']][$field['id']] ) . '</label>';
320 }
321 }
322
323 // Display description if we have one
324 if ( !empty( $field['description'] ) ) {
325
326 echo '<div class="' . implode( ' ', $field_atts['description_class'] ) . '" id="' . implode( ' ', $field_atts['description_id'] ) . '">';
327
328 echo $field['description'];
329
330 echo '</div>';
331 }
332
333 echo '</div>';
334
335 // Page break
336 if ( $field['type'] == 'pagebreak' ) {
337
338 echo '</div>';
339
340 $next = $page+1;
341 $last = $next == $pagebreak ? 'last' : '';
342 printf ('<div class="wpforms-page wpforms-page-%s %s" style="display:none;">', $next, $last );
343 }
344 }
345
346 // End of final page break
347 if ( $pagebreak ) {
348
349 $prev = !empty( $form_data['settings']['pagebreak_prev'] ) ? esc_html( $form_data['settings']['pagebreak_prev'] ) : __('Previous', 'wpforms' );
350 echo '<div class="wpforms-field wpforms-field-pagebreak">';
351 printf(
352 '<button class="wpforms-page-button wpforms-page-prev" data-action="prev" data-page="%d" data-formid="%d">%s</button>',
353 $page+1,
354 $form_data['id'],
355 $prev
356 );
357 echo '</div>';
358
359 echo '</div>';
360 }
361
362 echo '</div>';
363 }
364
365 /**
366 * Anti-spam honeypot output if configured.
367 *
368 * @since 1.0.0
369 * @param array $form_data
370 * @param object $form
371 * @param mixed $title
372 * @param mixed $description
373 */
374 public function honeypot( $form_data, $form, $title, $description, $errors ) {
375
376 if ( empty( $form_data['settings']['honeypot'] ) || '1' != $form_data['settings']['honeypot'] )
377 return;
378
379 $names = array( 'Name', 'Phone', 'Comment', 'Message', 'Email', 'Website' );
380
381 echo '<div class="wpforms-field wpforms-field-hp" id="wpform-field-hp">';
382
383 echo '<label for="wpforms-field_hp" class="wpforms-field-label" id="">' . esc_html( $names[ array_rand( $names ) ] ) . '</label>';
384
385 echo '<input type="text" name="wpforms[hp]" id="wpforms-field_hp" class="wpforms-field-medium">';
386
387 echo '</div>';
388 }
389
390 /**
391 * reCAPTCHA output if configured.
392 *
393 * @since 1.0.0
394 * @param array $form_data
395 * @param object $form
396 * @param mixed $title
397 * @param mixed $description
398 */
399 public function recaptcha( $form_data, $form, $title, $description, $errors ) {
400
401 // Check that recaptcha is configured in the settings
402 $site_key = wpforms_setting( 'recaptcha-site-key', '' );
403 $secret_key = wpforms_setting( 'recaptcha-secret-key', '' );
404 if ( empty( $site_key ) || empty( $secret_key ) )
405 return;
406
407 // Check that the recaptcha is configured for the specific form
408 if ( !isset( $form_data['settings']['recaptcha'] ) || '1' != $form_data['settings']['recaptcha'] )
409 return;
410
411 echo '<div class="wpforms-recaptcha-container">';
412
413 echo '<div class="g-recaptcha" data-sitekey="' . esc_attr( wpforms_setting( 'recaptcha-site-key', '' ) ) . '"></div>';
414
415 if ( !empty( wpforms()->process->errors[$form_data['id']]['recaptcha'] ) ) {
416 echo '<label id="wpforms-field_recaptcah-error" class="wpforms-error">' . esc_html( wpforms()->process->errors[$form_data['id']]['recaptcha'] ) . '</label>';
417 }
418
419 echo '</div>';
420 }
421
422 /**
423 * Form footer arera.
424 *
425 * @since 1.0.0
426 * @param array $form_data
427 * @param object $form
428 * @param mixed $title
429 * @param mixed $description
430 */
431 public function foot( $form_data, $form, $title, $description, $errors ) {
432
433 $settings = $form_data['settings'];
434 $submit = apply_filters( 'wpforms_field_submit' , esc_html( $settings['submit_text'] ), $form_data );
435 $submit_classes = array();
436 $visible = wpforms_has_pagebreak( $form_data ) ? 'style="display:none;"' : '';
437
438 // Check user defined submit button classes
439 if ( !empty( $settings['submit_class'] ) ) {
440 $user_classes = explode( ' ', str_replace('.', '', $settings['submit_class'] ) );
441 foreach( $user_classes as $user_class ) {
442 $submit_classes[] = sanitize_html_class( $user_class );
443 }
444 }
445
446 // Output errors if they exist
447 if ( !empty( $errors['footer'] ) ) {
448
449 echo '<div class="wpforms-error-container">';
450
451 echo esc_html( $errors['footer'] );
452
453 echo '</div>';
454 }
455
456 // Submit button area
457 echo '<div class="wpforms-submit-container" ' . $visible . '>';
458
459 echo '<input type="hidden" name="wpforms[id]" value="' . $form->ID . '">';
460
461 echo wp_nonce_field( 'wpforms-submit-' . $form->ID, 'wpforms[nonce]', true, false );
462
463 echo '<button type="submit" name="wpforms[submit]" class="wpforms-submit ' . implode( ' ', $submit_classes ) . '" id="wpforms-submit-' . $form->ID . '" value="wpforms-submit">' . $submit . '</button>';
464
465 echo '</div>';
466 }
467
468 /**
469 * Load the necessary CSS for single pages/posts earlier if possible.
470 *
471 * If we are viewing a singular page, then we can check the content early
472 * to see if the shortcode was used. If not we fallback and load the assets
473 * later on during the page (widgets, archives, etc).
474 *
475 * @since 1.0.0
476 */
477 public function assets_header() {
478
479 if ( !is_singular() ) {
480 return;
481 }
482
483 global $post;
484
485 if ( has_shortcode( $post->post_content, 'wpforms' ) ) {
486
487 $this->assets_css();
488 }
489 }
490
491 /**
492 * Load the CSS assets for frontend output.
493 *
494 * @since 1.0.0
495 */
496 public function assets_css() {
497
498 do_action( 'wpforms_frontend_css', $this->forms );
499
500 // jquery date/time library CSS
501 if ( true == wpforms_has_field_type( 'date-time', $this->forms, true ) ) :
502 wp_enqueue_style(
503 'wpforms-pickadate-core',
504 WPFORMS_PLUGIN_URL . 'assets/css/pickadate.classic.css',
505 array(),
506 '3.5.6'
507 );
508 wp_enqueue_style(
509 'wpforms-pickadate-date',
510 WPFORMS_PLUGIN_URL . 'assets/css/pickadate.classic.date.css',
511 array(),
512 '3.5.6'
513 );
514 wp_enqueue_style(
515 'wpforms-pickadate-time',
516 WPFORMS_PLUGIN_URL . 'assets/css/pickadate.classic.time.css',
517 array(),
518 '3.5.6'
519 );
520 endif;
521
522 // Load CSS per global setting
523 if ( wpforms_setting( 'disable-css', '1' ) == '1' ) {
524 wp_enqueue_style(
525 'wpforms-full',
526 WPFORMS_PLUGIN_URL . 'assets/css/wpforms-full.css',
527 array(),
528 WPFORMS_VERSION
529 );
530 }
531 if ( wpforms_setting( 'disable-css', '1' ) == '2' ) {
532 wp_enqueue_style(
533 'wpforms-base',
534 WPFORMS_PLUGIN_URL . 'assets/css/wpforms-base.css',
535 array(),
536 WPFORMS_VERSION
537 );
538 }
539 }
540
541 /**
542 * Load the JS assets for frontend output.
543 *
544 * @since 1.0.0
545 */
546 public function assets_js() {
547
548 do_action( 'wpforms_frontend_js', $this->forms );
549
550 // Load jquery validation library - http://jqueryvalidation.org/
551 wp_enqueue_script(
552 'wpforms-validation',
553 WPFORMS_PLUGIN_URL . 'assets/js/jquery.validate.min.js',
554 array( 'jquery' ),
555 '1.13.1',
556 true
557 );
558
559 // Load jquery date/time library - http://http://amsul.ca/pickadate.js/
560 //die( print_r( $this->forms ) );
561 if ( true == wpforms_has_field_type( 'date-time', $this->forms, true ) ) :
562 wp_enqueue_script(
563 'wpforms-pickadate-core',
564 WPFORMS_PLUGIN_URL . 'assets/js/jquery.picker.js',
565 array( 'jquery' ),
566 '3.5.6',
567 true
568 );
569 wp_enqueue_script(
570 'wpforms-pickadate-date',
571 WPFORMS_PLUGIN_URL . 'assets/js/jquery.picker.date.js',
572 array( 'jquery' ),
573 '3.5.6',
574 true
575 );
576 wp_enqueue_script(
577 'wpforms-pickadate-time',
578 WPFORMS_PLUGIN_URL . 'assets/js/jquery.picker.time.js',
579 array( 'jquery' ),
580 '3.5.6',
581 true
582 );
583 endif;
584
585 // Load jquery input mask library - https://github.com/RobinHerbots/jquery.inputmask
586 if ( true == wpforms_has_field_type( 'phone', $this->forms, true ) ) :
587 wp_enqueue_script(
588 'wpforms-maskedinput',
589 WPFORMS_PLUGIN_URL . 'assets/js/jquery.inputmask.bundle.min.js',
590 array( 'jquery' ),
591 '3.2.8',
592 true
593 );
594 endif;
595
596 // Load CC payment library - https://github.com/stripe/jquery.payment/
597 if ( true == wpforms_has_field_type( 'credit-card', $this->forms, true ) ) :
598 wp_enqueue_script(
599 'wpforms-payment',
600 WPFORMS_PLUGIN_URL . 'assets/js/jquery.payment.min.js',
601 array( 'jquery' ),
602 WPFORMS_VERSION,
603 true
604 );
605 endif;
606
607 // Load base JS
608 wp_enqueue_script(
609 'wpforms',
610 WPFORMS_PLUGIN_URL . 'assets/js/wpforms.js',
611 array( 'jquery' ),
612 WPFORMS_VERSION,
613 true
614 );
615
616
617 // Load reCAPTCHA support if form supports it
618 $site_key = wpforms_setting( 'recaptcha-site-key', '' );
619 $secret_key = wpforms_setting( 'recaptcha-secret-key', '' );
620 if ( !empty( $site_key ) && !empty( $secret_key ) ) {
621 wp_enqueue_script(
622 'wpforms-recaptcha',
623 'https://www.google.com/recaptcha/api.js',
624 array(),
625 '2.0.0',
626 true
627 );
628 }
629 }
630
631 /**
632 * Load the necessary assets for the confirmation message.
633 *
634 * @since 1.1.2
635 */
636 public function assets_confirmation() {
637
638 // Base CSS only
639 if ( wpforms_setting( 'disable-css', '1' ) == '1' ) {
640 wp_enqueue_style(
641 'wpforms-full',
642 WPFORMS_PLUGIN_URL . 'assets/css/wpforms-full.css',
643 array(),
644 WPFORMS_VERSION
645 );
646 }
647
648 // Special confirmation JS
649 wp_enqueue_script(
650 'wpforms-confirmation',
651 WPFORMS_PLUGIN_URL . 'assets/js/wpforms-confirmation.js',
652 array( 'jquery' ),
653 WPFORMS_VERSION,
654 true
655 );
656
657 do_action( 'wpforms_frontend_confirmation' );
658 }
659
660 /**
661 * Load the assets in footer if needed (archives, widgets, etc).
662 *
663 * @since 1.0.0
664 */
665 public function assets_footer() {
666
667 if ( empty( $this->forms ) )
668 return;
669
670 $this->assets_css();
671 $this->assets_js();
672
673 do_action( 'wpforms_wp_footer', $this->forms );
674 }
675
676 /**
677 * Hook at fires at a later priority in wp_footer
678 *
679 * @since 1.0.5
680 */
681 public function footer_end() {
682
683 if ( empty( $this->forms ) )
684 return;
685
686 do_action( 'wpforms_wp_footer_end', $this->forms );
687 }
688
689 /**
690 * Shortcode wrapper for the outputting a form.
691 *
692 * @since 1.0.0
693 * @param array $atts
694 * @return array
695 */
696 public function shortcode( $atts ) {
697
698 $atts = shortcode_atts( array(
699 'id' => false,
700 'title' => false,
701 'description' => false,
702 ), $atts, 'output' );
703
704 ob_start();
705
706 $this->output( $atts['id'], $atts['title'], $atts['description'] );
707
708 $output = ob_get_clean();
709
710 return $output;
711 }
712 }