PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.0.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.0.1
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 +151 -205 1.6.211.0.1 View file →
@@ -1,205 +1,151 @@
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 - // if ( $use_theme_css === $form_settings['use_theme_css'] ) {
71 - // wp_dequeue_style( 'weforms-css' );
72 - // }
73 - if ( isset( $atts['modal'] ) && 'true' == $atts['modal'] ) {
74 - wp_enqueue_script( 'weforms-modal-js', WEFORMS_ASSET_URI . '/modal/jquery.modal.js', [ 'jquery', 'weforms-form' ], false, false );
75 - wp_enqueue_style( 'weforms_modal_styles', WEFORMS_ASSET_URI . '/modal/jquery.modal.css' );
76 -
77 - $modal_class = 'modal';
78 - $modal_id = 'modal-form';
79 - $modal_style = 'style="display:none"';
80 - } else {
81 - $modal_class = $modal_id = $modal_style = '';
82 - } ?>
83 -
84 - <?php
85 - $script = "if ( typeof wpuf_conditional_items === 'undefined' ) {
86 - window.wpuf_conditional_items = [];
87 - }
88 - if ( typeof wpuf_plupload_items === 'undefined' ) {
89 - window.wpuf_plupload_items = [];
90 - }
91 - if ( typeof wpuf_map_items === 'undefined' ) {
92 - window.wpuf_map_items = [];
93 - }
94 - ";
95 - wp_add_inline_script( 'wpuf-form', $script );
96 - ?>
97 -
98 -
99 - <?php if ( isset( $_GET['success_message'] ) ) : ?>
100 - <?php
101 - $return_to_form = remove_query_arg(
102 - array(
103 - 'form_id',
104 - 'form_page',
105 - 'success_message',
106 - )
107 - );
108 - ?>
109 - <div class="wpuf-success">
110 - <?php echo wp_kses_post( $_GET['success_message'] ); ?>
111 - <br>
112 - <a href="<?php echo esc_url( $return_to_form ) ?>"><?php esc_html_e( 'Return to form', 'weforms' ); ?></a>
113 - </div>
114 - <?php else: ?>
115 - <form class="wpuf-form-add <?php echo esc_attr( $formid ); ?> <?php echo esc_attr( $modal_class ); ?> <?php echo
116 - esc_attr( $use_theme_css ); ?>" action="" method="post" <?php echo esc_attr( $modal_style ); ?> id="<?php echo
117 - esc_attr($modal_id); ?>">
118 -
119 - <ul class="wpuf-form form-label-<?php echo esc_attr( $form_settings['label_position'] ); ?>">
120 -
121 - <?php
122 - /**
123 - * @since 1.1.0
124 - */
125 - do_action( 'weforms_form_fields_top', $form, $form_fields );
126 -
127 - weforms()->fields->render_fields( $form_fields, $form->id, $atts );
128 -
129 - /*
130 - * @since 1.1.1
131 - */
132 - do_action( 'weforms_form_fields_before_submit_button', $form, $form_fields, $form_settings );
133 -
134 - $this->submit_button( $form->id, $form_settings );
135 -
136 - /*
137 - * @since 1.1.0
138 - */
139 - do_action( 'weforms_form_fields_bottom', $form, $form_fields ); ?>
140 - </ul>
141 -
142 - </form>
143 - <?php endif; ?>
144 - <?php
145 - if ( isset( $atts['modal'] ) && 'true' == esc_attr( $atts['modal'] ) ) {
146 - if ( isset( $atts['link'] ) ) {
147 - printf( wp_kses_post( '<p><a href="#modal-form" rel="modal:open">%s</a></p>', $atts['link'] ) );
148 - } else {
149 - if ( isset( $atts['button'] ) ) {
150 - $button_text = $atts['button'];
151 - } else {
152 - $button_text = esc_html_e( 'Open Form', 'weforms' );
153 - }
154 - printf( wp_kses_post( '<p><button><a href="#modal-form" rel="modal:open">%s</a></button></p>', $button_text ) );
155 - }
156 - }
157 -
158 - if ( $show_credit ) {
159 - printf( '<em>' . wp_kses_post( 'Powered by <a href="%s" target="_blank">weForms</a>', 'weforms' ) . '</em>', 'https://wordpress.org/plugins/weforms/' );
160 - }
161 -
162 - weforms_track_form_view( $form->id );
163 - }
164 -
165 - /**
166 - * Render submit button
167 - *
168 - * @param int $form_id
169 - * @param array $form_settings
170 - *
171 - * @return void
172 - */
173 - public function submit_button( $form_id, $form_settings ) {
174 - ?>
175 - <li class="wpuf-submit">
176 - <div class="wpuf-label">
177 - &nbsp;
178 - </div>
179 -
180 - <?php esc_attr( wp_nonce_field( 'wpuf_form_add' ) ); ?>
181 -
182 - <input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>">
183 - <input type="hidden" name="page_id" value="<?php echo get_the_ID(); ?>">
184 - <input type="hidden" name="action" value="weforms_frontend_submit">
185 -
186 - <?php
187 - if ( isset( $form_settings['show_frontend_report'] ) && $form_settings['show_frontend_report'] ) { ?>
188 - <input type="hidden" name="weforms-front-report" value="yes">
189 - <?php } else { ?>
190 - <input type="hidden" name="weforms-front-report" value="no">
191 - <?php } ?>
192 -
193 - <?php do_action( 'weforms_submit_btn', $form_id, $form_settings ); ?>
194 -
195 - <?php if ( 'wpuf-style' == $form_settings['use_theme_css'] ) : ?>
196 - <input type="submit" class="weforms_submit_btn wpuf_submit_<?php echo esc_attr( $form_id ); ?>" name="submit" value="<?php echo
197 - esc_attr( $form_settings['submit_text'] ); ?>" />
198 - <?php else : ?>
199 - <input type="submit" class="button button-primary wpuf_submit_<?php echo esc_attr( $form_id ); ?>" name="submit" value="<?php echo
200 - esc_attr( $form_settings['submit_text'] ); ?>" />
201 - <?php endif; ?>
202 - </li>
203 - <?php
204 - }
205 -}
1 +<?php
2 +
3 +/**
4 + * The frontend form class
5 + */
6 +class WeForms_Frontend extends WPUF_Render_Form {
7 +
8 + public function __construct() {
9 + add_shortcode( 'weforms', array( $this, 'render_shortcode' ) );
10 + }
11 +
12 + /**
13 + * Render contact form shortcode
14 + *
15 + * @param array $atts
16 + * @param string $contents
17 + *
18 + * @return string
19 + */
20 + public function render_shortcode( $atts, $contents = '' ) {
21 + extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
22 + ob_start();
23 +
24 + $is_open = wpuf_is_form_submission_open( $id );
25 +
26 + if ( is_wp_error( $is_open ) ) {
27 + return '<div class="wpuf-info">' . $is_open->get_error_message() . '</div>';
28 + }
29 +
30 + $form_settings = wpuf_get_form_settings( $id );
31 +
32 + // var_dump( $form_settings );
33 + $this->render_form( $id );
34 +
35 + return ob_get_clean();
36 + }
37 +
38 + /**
39 + * Handles the add post shortcode
40 + *
41 + * @param $atts
42 + */
43 + function render_form( $form_id, $post_id = NULL, $preview = false ) {
44 + $form_status = get_post_status( $form_id );
45 +
46 + if ( ! $form_status ) {
47 + echo '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'weforms' ) . '</div>';
48 + return;
49 + }
50 +
51 + if ( $form_status != 'publish' ) {
52 + echo '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'weforms' ) . '</div>';
53 + return;
54 + }
55 +
56 + $form_vars = wpuf_get_form_fields( $form_id );
57 + $form_settings = wpuf_get_form_settings( $form_id );
58 + ?>
59 +
60 + <form class="wpuf-form-add" action="" method="post">
61 +
62 + <ul class="wpuf-form form-label-<?php echo $form_settings['label_position']; ?>">
63 + <?php
64 + $this->render_items( $form_vars, $post_id, 'contact_form', $form_id, $form_settings );
65 + $this->submit_button( $form_id, $form_settings, $post_id );
66 + ?>
67 + </ul>
68 +
69 + </form>
70 +
71 + <?php
72 + weforms_track_form_view( $form_id );
73 + }
74 +
75 + function submit_button( $form_id, $form_settings, $post_id ) {
76 + ?>
77 + <li class="wpuf-submit">
78 + <div class="wpuf-label">
79 + &nbsp;
80 + </div>
81 +
82 + <?php wp_nonce_field( 'wpuf_form_add' ); ?>
83 +
84 + <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
85 + <input type="hidden" name="page_id" value="<?php echo get_post() ? get_the_ID() : '0'; ?>">
86 + <input type="hidden" name="action" value="wpuf_submit_contact">
87 +
88 + <input type="submit" name="submit" value="<?php echo $form_settings['submit_text']; ?>" />
89 + </li>
90 + <?php
91 + }
92 +
93 + function field_name( $form_field, $post_id, $type, $form_id ) {
94 + // var_dump( $form_field );
95 + ?>
96 + <div class="wpuf-fields">
97 + <div class="wpuf-name-field-wrap format-<?php echo $form_field['format']; ?>">
98 + <div class="wpuf-name-field-first-name">
99 + <input
100 + name="<?php echo $form_field['name'] ?>[first]"
101 + type="text"
102 + placeholder="<?php echo esc_attr( $form_field['first_name']['placeholder'] ); ?>"
103 + value="<?php echo esc_attr( $form_field['first_name']['default'] ); ?>"
104 + size="40"
105 + data-required="<?php echo $form_field['required'] ?>"
106 + data-type="text"
107 + class="textfield wpuf_<?php echo $form_field['name']; ?>_<?php echo $form_id; ?>"
108 + >
109 +
110 + <?php if ( ! $form_field['hide_subs'] ) : ?>
111 + <label class="wpuf-form-sub-label"><?php _e( 'First', 'weforms' ); ?></label>
112 + <?php endif; ?>
113 + </div>
114 +
115 + <?php if ( $form_field['format'] != 'first-last' ) : ?>
116 + <div class="wpuf-name-field-middle-name">
117 + <input
118 + name="<?php echo $form_field['name'] ?>[middle]"
119 + type="text" class="textfield"
120 + placeholder="<?php echo esc_attr( $form_field['middle_name']['placeholder'] ); ?>"
121 + value="<?php echo esc_attr( $form_field['middle_name']['default'] ); ?>"
122 + size="40"
123 + >
124 +
125 + <?php if ( ! $form_field['hide_subs'] ) : ?>
126 + <label class="wpuf-form-sub-label"><?php _e( 'Middle', 'weforms' ); ?></label>
127 + <?php endif; ?>
128 + </div>
129 + <?php else: ?>
130 + <input type="hidden" name="<?php echo $form_field['name'] ?>[middle]" value="">
131 + <?php endif; ?>
132 +
133 + <div class="wpuf-name-field-last-name">
134 + <input
135 + name="<?php echo $form_field['name'] ?>[last]"
136 + type="text" class="textfield"
137 + placeholder="<?php echo esc_attr( $form_field['last_name']['placeholder'] ); ?>"
138 + value="<?php echo esc_attr( $form_field['last_name']['default'] ); ?>"
139 + size="40"
140 + >
141 + <?php if ( ! $form_field['hide_subs'] ) : ?>
142 + <label class="wpuf-form-sub-label"><?php _e( 'Last', 'weforms' ); ?></label>
143 + <?php endif; ?>
144 + </div>
145 + </div>
146 + </div>
147 + <?php
148 +
149 + $this->conditional_logic( $form_field, $form_id );
150 + }
151 +}