PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.3
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-frontend-form.php

class-frontend-form.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.3, at includes/class-frontend-form.php

169 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The frontend form class
5 */
6 class WeForms_Frontend_Form {
7
8 public function __construct() {
9 add_shortcode( 'weforms', array( $this, 'render_shortcode' ) );
10 }
11
12 /**
13 * Show form error
14 *
15 * @param string $message
16 * @param string $type
17 *
18 * @return string
19 */
20 public function show_error( $message, $type = 'info' ) {
21 return sprintf( '<div class="wpuf-%s">%s</div>', $type, $message );
22 }
23
24 /**
25 * Render contact form shortcode
26 *
27 * @param array $atts
28 * @param string $contents
29 *
30 * @return string
31 */
32 public function render_shortcode( $atts, $contents = '' ) {
33 extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
34
35 weforms()->scripts->enqueue_frontend();
36
37 ob_start();
38
39 $form = weforms()->form->get( $id );
40
41 if ( ! $form->id ) {
42 return $this->show_error( __( 'The form couldn\'t be found.', 'weforms' ) );
43 }
44
45 $is_open = $form->is_submission_open();
46
47 if ( is_wp_error( $is_open ) ) {
48 return $this->show_error( $is_open->get_error_message() );
49 }
50
51 $this->render_form( $form, $atts );
52
53 return ob_get_clean();
54 }
55
56 /**
57 * Render the form
58 *
59 * @param \WeForms_Form $form
60 *
61 * @return void
62 */
63 function render_form( $form, $atts ) {
64 $form_fields = $form->get_fields();
65 $form_settings = $form->get_settings();
66 $show_credit = weforms_get_settings( 'credit', false );
67
68 if ( isset( $atts['modal'] ) && 'true' == $atts['modal'] ) {
69
70 wp_enqueue_script( 'weforms-modal-js', WEFORMS_ASSET_URI . '/modal/jquery.modal.js', array( 'jquery', 'wpuf-form' ), false, false );
71 wp_enqueue_style( 'weforms_modal_styles', WEFORMS_ASSET_URI . '/modal/jquery.modal.css' );
72
73 $modal_class = 'modal';
74 $modal_id = 'modal-form';
75 $modal_style = 'style="display:none"';
76 } else {
77 $modal_class = $modal_id = $modal_style = '';
78 }
79 ?>
80
81 <script type="text/javascript">
82 if ( typeof wpuf_conditional_items === 'undefined' ) {
83 window.wpuf_conditional_items = [];
84 }
85
86 if ( typeof wpuf_plupload_items === 'undefined' ) {
87 window.wpuf_plupload_items = [];
88 }
89
90 if ( typeof wpuf_map_items === 'undefined' ) {
91 window.wpuf_map_items = [];
92 }
93 </script>
94
95 <form class="wpuf-form-add <?php echo $modal_class; ?>" action="" method="post" <?php echo $modal_style; ?> id="<?php echo $modal_id; ?>">
96
97 <ul class="wpuf-form form-label-<?php echo $form_settings['label_position']; ?>">
98
99 <?php
100 /**
101 * @since 1.1.0
102 */
103 do_action( 'weforms_form_fields_top', $form, $form_fields );
104
105 weforms()->fields->render_fields( $form_fields, $form->id, $atts );
106
107 /**
108 * @since 1.1.1
109 */
110 do_action( 'weforms_form_fields_before_submit_button', $form, $form_fields, $form_settings );
111
112 $this->submit_button( $form->id, $form_settings );
113
114 /**
115 * @since 1.1.0
116 */
117 do_action( 'weforms_form_fields_bottom', $form, $form_fields );
118 ?>
119 </ul>
120
121 </form>
122
123 <?php
124 if ( isset( $atts['modal'] ) && 'true' == $atts['modal'] ) {
125 if ( isset( $atts['link'] ) ) {
126 printf('<p><a href="#modal-form" rel="modal:open">%s</a></p>', $atts['link'] );
127 } else {
128 if ( isset( $atts['button'] ) ) {
129 $button_text = $atts['button'];
130 } else {
131 $button_text = __( 'Open Form', 'weforms' );
132 }
133 printf('<p><button><a href="#modal-form" rel="modal:open">%s</a></button></p>', $button_text );
134 }
135 }
136
137 if ( $show_credit ) {
138 printf( '<em>' . __( 'Powered by <a href="%s" target="_blank">weForms</a>', 'weforms' ) . '</em>', 'https://wordpress.org/plugins/weforms/' );
139 }
140
141 weforms_track_form_view( $form->id );
142 }
143
144 /**
145 * Render submit button
146 *
147 * @param integer $form_id
148 * @param array $form_settings
149 *
150 * @return void
151 */
152 function submit_button( $form_id, $form_settings ) {
153 ?>
154 <li class="wpuf-submit">
155 <div class="wpuf-label">
156 &nbsp;
157 </div>
158
159 <?php wp_nonce_field( 'wpuf_form_add' ); ?>
160
161 <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
162 <input type="hidden" name="page_id" value="<?php echo get_the_ID(); ?>">
163 <input type="hidden" name="action" value="weforms_frontend_submit">
164
165 <input type="submit" class="weforms_submit_btn" name="submit" value="<?php echo $form_settings['submit_text']; ?>" />
166 </li>
167 <?php
168 }
169 }