PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.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
← All changes | includes/class-frontend-form.php +183 -182 1.6.131.3.3 View file →
@@ -1,182 +1,183 @@
1 -<?php
2 -
3 -/**
4 - * The frontend form class
5 - */
6 -class WeForms_Frontend_Form {
7 -
8 - public function __construct() {
9 - add_shortcode( 'weforms', [ $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( [ 'id' => 0 ], $atts ) );
34 -
35 - weforms()->scripts->register_frontend();
36 - weforms()->scripts->enqueue_frontend();
37 -
38 - ob_start();
39 -
40 - $form = weforms()->form->get( $id );
41 -
42 - if ( !$form->id ) {
43 - return $this->show_error( __( 'The form couldn\'t be found.', 'weforms' ) );
44 - }
45 -
46 - $is_open = $form->is_submission_open();
47 -
48 - if ( is_wp_error( $is_open ) ) {
49 - return $this->show_error( $is_open->get_error_message() );
50 - }
51 -
52 - $this->render_form( $form, $atts );
53 -
54 - return ob_get_clean();
55 - }
56 -
57 - /**
58 - * Render the form
59 - *
60 - * @param \WeForms_Form $form
61 - *
62 - * @return void
63 - */
64 - public function render_form( $form, $atts ) {
65 - $form_fields = $form->get_fields();
66 - $form_settings = $form->get_settings();
67 - $show_credit = weforms_get_settings( 'credit', false );
68 - $formid = 'weforms-' . $form->id;
69 - $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style';
70 -
71 - if ( isset( $atts['modal'] ) && 'true' == $atts['modal'] ) {
72 - wp_enqueue_script( 'weforms-modal-js', WEFORMS_ASSET_URI . '/modal/jquery.modal.js', [ 'jquery', 'weforms-form' ], false, false );
73 - wp_enqueue_style( 'weforms_modal_styles', WEFORMS_ASSET_URI . '/modal/jquery.modal.css' );
74 -
75 - $modal_class = 'modal';
76 - $modal_id = 'modal-form';
77 - $modal_style = 'style="display:none"';
78 - } else {
79 - $modal_class = $modal_id = $modal_style = '';
80 - } ?>
81 -
82 - <?php
83 - $script = "if ( typeof wpuf_conditional_items === 'undefined' ) {
84 - window.wpuf_conditional_items = [];
85 - }
86 - if ( typeof wpuf_plupload_items === 'undefined' ) {
87 - window.wpuf_plupload_items = [];
88 - }
89 - if ( typeof wpuf_map_items === 'undefined' ) {
90 - window.wpuf_map_items = [];
91 - }
92 - ";
93 - wp_add_inline_script( 'wpuf-form', $script );
94 - ?>
95 -
96 - <form class="wpuf-form-add <?php echo esc_attr( $formid ); ?> <?php echo esc_attr( $modal_class ); ?> <?php echo
97 - esc_attr( $use_theme_css ); ?>" action="" method="post" <?php echo esc_attr( $modal_style ); ?> id="<?php echo
98 - esc_attr($modal_id); ?>">
99 -
100 - <ul class="wpuf-form form-label-<?php echo esc_attr( $form_settings['label_position'] ); ?>">
101 -
102 - <?php
103 - /**
104 - * @since 1.1.0
105 - */
106 - do_action( 'weforms_form_fields_top', $form, $form_fields );
107 -
108 - weforms()->fields->render_fields( $form_fields, $form->id, $atts );
109 -
110 - /*
111 - * @since 1.1.1
112 - */
113 - do_action( 'weforms_form_fields_before_submit_button', $form, $form_fields, $form_settings );
114 -
115 - $this->submit_button( $form->id, $form_settings );
116 -
117 - /*
118 - * @since 1.1.0
119 - */
120 - do_action( 'weforms_form_fields_bottom', $form, $form_fields ); ?>
121 - </ul>
122 -
123 - </form>
124 -
125 - <?php
126 - if ( isset( $atts['modal'] ) && 'true' == esc_attr( $atts['modal'] ) ) {
127 - if ( isset( $atts['link'] ) ) {
128 - printf( wp_kses_post( '<p><a href="#modal-form" rel="modal:open">%s</a></p>', $atts['link'] ) );
129 - } else {
130 - if ( isset( $atts['button'] ) ) {
131 - $button_text = $atts['button'];
132 - } else {
133 - $button_text = esc_html_e( 'Open Form', 'weforms' );
134 - }
135 - printf( wp_kses_post( '<p><button><a href="#modal-form" rel="modal:open">%s</a></button></p>', $button_text ) );
136 - }
137 - }
138 -
139 - if ( $show_credit ) {
140 - printf( '<em>' . wp_kses_post( 'Powered by <a href="%s" target="_blank">weForms</a>', 'weforms' ) . '</em>', 'https://wordpress.org/plugins/weforms/' );
141 - }
142 -
143 - weforms_track_form_view( $form->id );
144 - }
145 -
146 - /**
147 - * Render submit button
148 - *
149 - * @param int $form_id
150 - * @param array $form_settings
151 - *
152 - * @return void
153 - */
154 - public function submit_button( $form_id, $form_settings ) {
155 - ?>
156 - <li class="wpuf-submit">
157 - <div class="wpuf-label">
158 - &nbsp;
159 - </div>
160 -
161 - <?php esc_attr( wp_nonce_field( 'wpuf_form_add' ) ); ?>
162 -
163 - <input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>">
164 - <input type="hidden" name="page_id" value="<?php echo get_the_ID(); ?>">
165 - <input type="hidden" name="action" value="weforms_frontend_submit">
166 -
167 - <?php
168 - if ( isset( $form_settings['show_frontend_report'] ) && $form_settings['show_frontend_report'] ) { ?>
169 - <input type="hidden" name="weforms-front-report" value="yes">
170 - <?php } else { ?>
171 - <input type="hidden" name="weforms-front-report" value="no">
172 - <?php } ?>
173 -
174 - <?php do_action( 'weforms_submit_btn', $form_id, $form_settings ); ?>
175 -
176 - <input type="submit" class="weforms_submit_btn wpuf_submit_<?php echo esc_attr( $form_id ); ?>" name="submit" value="<?php echo
177 - esc_attr( $form_settings['submit_text'] ); ?>" />
178 -
179 - </li>
180 - <?php
181 - }
182 -}
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 + $formid = 'weforms-' . $form->id;
68 + $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style';
69 +
70 + if ( isset( $atts['modal'] ) && 'true' == $atts['modal'] ) {
71 +
72 + wp_enqueue_script( 'weforms-modal-js', WEFORMS_ASSET_URI . '/modal/jquery.modal.js', array( 'jquery', 'weforms-form' ), false, false );
73 + wp_enqueue_style( 'weforms_modal_styles', WEFORMS_ASSET_URI . '/modal/jquery.modal.css' );
74 +
75 + $modal_class = 'modal';
76 + $modal_id = 'modal-form';
77 + $modal_style = 'style="display:none"';
78 +
79 + } else {
80 + $modal_class = $modal_id = $modal_style = '';
81 + }
82 +
83 + ?>
84 +
85 + <script type="text/javascript">
86 + if ( typeof wpuf_conditional_items === 'undefined' ) {
87 + window.wpuf_conditional_items = [];
88 + }
89 +
90 + if ( typeof wpuf_plupload_items === 'undefined' ) {
91 + window.wpuf_plupload_items = [];
92 + }
93 +
94 + if ( typeof wpuf_map_items === 'undefined' ) {
95 + window.wpuf_map_items = [];
96 + }
97 + </script>
98 +
99 + <form class="wpuf-form-add <?php echo $formid ?> <?php echo $modal_class; ?> <?php echo $use_theme_css; ?>" action="" method="post" <?php echo $modal_style; ?> id="<?php echo $modal_id; ?>">
100 +
101 + <ul class="wpuf-form form-label-<?php echo $form_settings['label_position']; ?>">
102 +
103 + <?php
104 + /**
105 + * @since 1.1.0
106 + */
107 + do_action( 'weforms_form_fields_top', $form, $form_fields );
108 +
109 + weforms()->fields->render_fields( $form_fields, $form->id, $atts );
110 +
111 + /**
112 + * @since 1.1.1
113 + */
114 + do_action( 'weforms_form_fields_before_submit_button', $form, $form_fields, $form_settings );
115 +
116 + $this->submit_button( $form->id, $form_settings );
117 +
118 + /**
119 + * @since 1.1.0
120 + */
121 + do_action( 'weforms_form_fields_bottom', $form, $form_fields );
122 + ?>
123 + </ul>
124 +
125 + </form>
126 +
127 + <?php
128 + if ( isset( $atts['modal'] ) && 'true' == $atts['modal'] ) {
129 + if ( isset( $atts['link'] ) ) {
130 + printf('<p><a href="#modal-form" rel="modal:open">%s</a></p>', $atts['link'] );
131 + } else {
132 + if ( isset( $atts['button'] ) ) {
133 + $button_text = $atts['button'];
134 + } else {
135 + $button_text = __( 'Open Form', 'weforms' );
136 + }
137 + printf('<p><button><a href="#modal-form" rel="modal:open">%s</a></button></p>', $button_text );
138 + }
139 + }
140 +
141 + if ( $show_credit ) {
142 + printf( '<em>' . __( 'Powered by <a href="%s" target="_blank">weForms</a>', 'weforms' ) . '</em>', 'https://wordpress.org/plugins/weforms/' );
143 + }
144 +
145 + weforms_track_form_view( $form->id );
146 + }
147 +
148 + /**
149 + * Render submit button
150 + *
151 + * @param integer $form_id
152 + * @param array $form_settings
153 + *
154 + * @return void
155 + */
156 + function submit_button( $form_id, $form_settings ) {
157 + ?>
158 + <li class="wpuf-submit">
159 + <div class="wpuf-label">
160 + &nbsp;
161 + </div>
162 +
163 + <?php wp_nonce_field( 'wpuf_form_add' ); ?>
164 +
165 + <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
166 + <input type="hidden" name="page_id" value="<?php echo get_the_ID(); ?>">
167 + <input type="hidden" name="action" value="weforms_frontend_submit">
168 +
169 + <?php
170 + if ( isset( $form_settings['show_frontend_report'] ) && $form_settings['show_frontend_report'] ) { ?>
171 + <input type="hidden" name="weforms-front-report" value="yes">
172 + <?php } else { ?>
173 + <input type="hidden" name="weforms-front-report" value="no">
174 + <?php } ?>
175 +
176 + <?php do_action( 'weforms_submit_btn', $form_id, $form_settings ); ?>
177 +
178 + <input type="submit" class="weforms_submit_btn" name="submit" value="<?php echo $form_settings['submit_text']; ?>" />
179 +
180 + </li>
181 + <?php
182 + }
183 +}