SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | ||
3 | class ET_Builder_Module_Contact_Form extends ET_Builder_Module { | |
4 | function init() { | |
5 | $this->name = esc_html__( 'Contact Form', 'et_builder' ); | |
6 | $this->slug = 'et_pb_contact_form'; | |
7 | $this->fb_support = true; | |
8 | $this->child_slug = 'et_pb_contact_field'; | |
9 | $this->child_item_text = esc_html__( 'Field', 'et_builder' ); | |
10 | ||
11 | $this->whitelisted_fields = array( | |
12 | 'captcha', | |
13 | 'email', | |
14 | 'title', | |
15 | 'admin_label', | |
16 | 'module_id', | |
17 | 'module_class', | |
18 | 'form_background_color', | |
19 | 'input_border_radius', | |
20 | 'submit_button_text', | |
21 | 'custom_message', | |
22 | 'use_redirect', | |
23 | 'redirect_url', | |
24 | 'success_message', | |
25 | 'box_shadow_style_submit', | |
26 | 'box_shadow_horizontal_submit', | |
27 | 'box_shadow_vertical_submit', | |
28 | 'box_shadow_blur_submit', | |
29 | 'box_shadow_spread_submit', | |
30 | 'box_shadow_color_submit', | |
31 | 'box_shadow_position_submit', | |
32 | ); | |
33 | ||
34 | $this->fields_defaults = array( | |
35 | 'captcha' => array( 'on' ), | |
36 | 'use_redirect' => array( 'off' ), | |
37 | ); | |
38 | ||
39 | $this->main_css_element = '%%order_class%%.et_pb_contact_form_container'; | |
40 | ||
41 | $this->options_toggles = array( | |
42 | 'general' => array( | |
43 | 'toggles' => array( | |
44 | 'main_content' => esc_html__( 'Text', 'et_builder' ), | |
45 | 'email' => esc_html__( 'Email', 'et_builder' ), | |
46 | 'elements' => esc_html__( 'Elements', 'et_builder' ), | |
47 | 'redirect' => esc_html__( 'Redirect', 'et_builder' ), | |
48 | 'background' => esc_html__( 'Background', 'et_builder' ), | |
49 | ), | |
50 | ), | |
51 | ); | |
52 | ||
53 | $this->advanced_options = array( | |
54 | 'border' => array( | |
55 | 'css' => array( | |
56 | 'main' => array( | |
57 | 'border_radii' => sprintf( '%1$s .input, %1$s .input[type="checkbox"] + label i, %1$s .input[type="radio"] + label i', $this->main_css_element ), | |
58 | 'border_styles' => sprintf( '%1$s .input, %1$s .input[type="checkbox"] + label i, %1$s .input[type="radio"] + label i', $this->main_css_element ), | |
59 | ), | |
60 | 'important' => 'plugin_only', | |
61 | ), | |
62 | 'label_prefix' => esc_html__( 'Inputs', 'et_builder' ), | |
63 | ), | |
64 | 'fonts' => array( | |
65 | 'title' => array( | |
66 | 'label' => esc_html__( 'Title', 'et_builder' ), | |
67 | 'css' => array( | |
68 | 'main' => "{$this->main_css_element} h1, {$this->main_css_element} h2.et_pb_contact_main_title, {$this->main_css_element} h3.et_pb_contact_main_title, {$this->main_css_element} h4.et_pb_contact_main_title, {$this->main_css_element} h5.et_pb_contact_main_title, {$this->main_css_element} h6.et_pb_contact_main_title", | |
69 | ), | |
70 | 'header_level' => array( | |
71 | 'default' => 'h1', | |
72 | ), | |
73 | ), | |
74 | 'form_field' => array( | |
75 | 'label' => esc_html__( 'Form Field', 'et_builder' ), | |
76 | 'css' => array( | |
77 | 'main' => array( | |
78 | "{$this->main_css_element} .input", | |
79 | "{$this->main_css_element} .input::-webkit-input-placeholder", | |
80 | "{$this->main_css_element} .input::-moz-placeholder", | |
81 | "{$this->main_css_element} .input:-ms-input-placeholder", | |
82 | "{$this->main_css_element} .input[type=checkbox] + label", | |
83 | "{$this->main_css_element} .input[type=radio] + label", | |
84 | ), | |
85 | 'important' => 'plugin_only', | |
86 | ), | |
87 | ), | |
88 | ), | |
89 | 'button' => array( | |
90 | 'button' => array( | |
91 | 'label' => esc_html__( 'Button', 'et_builder' ), | |
92 | 'css' => array( | |
93 | 'plugin_main' => "{$this->main_css_element}.et_pb_module .et_pb_button", | |
94 | ), | |
95 | 'no_rel_attr' => true, | |
96 | ), | |
97 | ), | |
98 | 'background' => array(), | |
99 | 'custom_margin_padding' => array( | |
100 | 'css' => array( | |
101 | 'important' => array( 'custom_margin' ), // needed to overwrite last module margin-bottom styling | |
102 | ), | |
103 | ), | |
104 | 'max_width' => array( | |
105 | 'css' => array( | |
106 | 'module_alignment' => '%%order_class%%.et_pb_contact_form_container.et_pb_module', | |
107 | ), | |
108 | ), | |
109 | 'text' => array( | |
110 | 'css' => array( | |
111 | 'text_orientation' => '%%order_class%% input, %%order_class%% textarea, %%order_class%% label', | |
112 | 'text_shadow' => '%%order_class%%, %%order_class%% input, %%order_class%% textarea, %%order_class%% label, %%order_class%% select', | |
113 | ), | |
114 | ), | |
115 | ); | |
116 | $this->custom_css_options = array( | |
117 | 'contact_title' => array( | |
118 | 'label' => esc_html__( 'Contact Title', 'et_builder' ), | |
119 | 'selector' => '.et_pb_contact_main_title', | |
120 | ), | |
121 | 'contact_button' => array( | |
122 | 'label' => esc_html__( 'Contact Button', 'et_builder' ), | |
123 | 'selector' => '.et_pb_contact_form_container .et_contact_bottom_container .et_pb_contact_submit.et_pb_button', | |
124 | 'no_space_before_selector' => true, | |
125 | ), | |
126 | 'contact_fields' => array( | |
127 | 'label' => esc_html__( 'Form Fields', 'et_builder' ), | |
128 | 'selector' => 'input', | |
129 | ), | |
130 | 'text_field' => array( | |
131 | 'label' => esc_html__( 'Message Field', 'et_builder' ), | |
132 | 'selector' => 'textarea.et_pb_contact_message', | |
133 | ), | |
134 | 'captcha_field' => array( | |
135 | 'label' => esc_html__( 'Captcha Field', 'et_builder' ), | |
136 | 'selector' => 'input.et_pb_contact_captcha', | |
137 | ), | |
138 | 'captcha_label' => array( | |
139 | 'label' => esc_html__( 'Captcha Text', 'et_builder' ), | |
140 | 'selector' => '.et_pb_contact_right p', | |
141 | ), | |
142 | ); | |
143 | } | |
144 | ||
145 | function get_fields() { | |
146 | $fields = array( | |
147 | 'captcha' => array( | |
148 | 'label' => esc_html__( 'Display Captcha', 'et_builder' ), | |
149 | 'type' => 'yes_no_button', | |
150 | 'option_category' => 'configuration', | |
151 | 'options' => array( | |
152 | 'on' => esc_html__( 'Yes', 'et_builder' ), | |
153 | 'off' => esc_html__( 'No', 'et_builder' ), | |
154 | ), | |
155 | 'toggle_slug' => 'elements', | |
156 | 'description' => esc_html__( 'Turn the captcha on or off using this option.', 'et_builder' ), | |
157 | ), | |
158 | 'email' => array( | |
159 | 'label' => esc_html__( 'Email', 'et_builder' ), | |
160 | 'type' => 'text', | |
161 | 'option_category' => 'basic_option', | |
162 | 'description' => et_get_safe_localization( sprintf( | |
163 | __( 'Input the email address where messages should be sent.<br /><br /> Note: email delivery and spam prevention are complex processes. We recommend using a delivery service such as <a href="%1$s">Mandrill</a>, <a href="%2$s">SendGrid</a>, or other similar service to ensure the deliverability of messages that are submitted through this form', 'et_builder' ), | |
164 | 'http://mandrill.com/', | |
165 | 'https://sendgrid.com/' | |
166 | ) ), | |
167 | 'toggle_slug' => 'email', | |
168 | ), | |
169 | 'title' => array( | |
170 | 'label' => esc_html__( 'Title', 'et_builder' ), | |
171 | 'type' => 'text', | |
172 | 'option_category' => 'basic_option', | |
173 | 'description' => esc_html__( 'Define a title for your contact form.', 'et_builder' ), | |
174 | 'toggle_slug' => 'main_content', | |
175 | ), | |
176 | 'custom_message' => array( | |
177 | 'label' => esc_html__( 'Message Pattern', 'et_builder' ), | |
178 | 'type' => 'textarea', | |
179 | 'option_category' => 'configuration', | |
180 | 'description' => et_get_safe_localization( __( 'Here you can define the custom pattern for the email Message. Fields should be included in following format - <strong>%%field_id%%</strong>. For example if you want to include the field with id = <strong>phone</strong> and field with id = <strong>message</strong>, then you can use the following pattern: <strong>My message is %%message%% and phone number is %%phone%%</strong>. Leave blank for default.', 'et_builder' ) ), | |
181 | 'toggle_slug' => 'email', | |
182 | ), | |
183 | 'use_redirect' => array( | |
184 | 'label' => esc_html__( 'Enable Redirect URL', 'et_builder' ), | |
185 | 'type' => 'yes_no_button', | |
186 | 'option_category' => 'configuration', | |
187 | 'options' => array( | |
188 | 'off' => esc_html__( 'No', 'et_builder' ), | |
189 | 'on' => esc_html__( 'Yes', 'et_builder' ), | |
190 | ), | |
191 | 'affects' => array( | |
192 | 'redirect_url', | |
193 | ), | |
194 | 'toggle_slug' => 'redirect', | |
195 | 'description' => esc_html__( 'Redirect users after successful form submission.', 'et_builder' ), | |
196 | ), | |
197 | 'redirect_url' => array( | |
198 | 'label' => esc_html__( 'Redirect URL', 'et_builder' ), | |
199 | 'type' => 'text', | |
200 | 'option_category' => 'configuration', | |
201 | 'depends_show_if' => 'on', | |
202 | 'toggle_slug' => 'redirect', | |
203 | 'description' => esc_html__( 'Type the Redirect URL', 'et_builder' ), | |
204 | ), | |
205 | 'success_message' => array( | |
206 | 'label' => esc_html__( 'Success Message', 'et_builder' ), | |
207 | 'type' => 'text', | |
208 | 'option_category' => 'configuration', | |
209 | 'description' => esc_html__( 'Type the message you want to display after successful form submission. Leave blank for default', 'et_builder' ), | |
210 | 'toggle_slug' => 'main_content', | |
211 | ), | |
212 | 'submit_button_text' => array( | |
213 | 'label' => esc_html__( 'Submit Button Text', 'et_builder' ), | |
214 | 'type' => 'text', | |
215 | 'option_category' => 'basic_option', | |
216 | 'description' => esc_html__( 'Define the text of the form submit button.', 'et_builder' ), | |
217 | 'toggle_slug' => 'main_content', | |
218 | ), | |
219 | 'form_background_color' => array( | |
220 | 'label' => esc_html__( 'Form Field Background Color', 'et_builder' ), | |
221 | 'type' => 'color-alpha', | |
222 | 'custom_color' => true, | |
223 | 'toggle_slug' => 'form_field', | |
224 | 'tab_slug' => 'advanced', | |
225 | ), | |
226 | 'disabled_on' => array( | |
227 | 'label' => esc_html__( 'Disable on', 'et_builder' ), | |
228 | 'type' => 'multiple_checkboxes', | |
229 | 'options' => array( | |
230 | 'phone' => esc_html__( 'Phone', 'et_builder' ), | |
231 | 'tablet' => esc_html__( 'Tablet', 'et_builder' ), | |
232 | 'desktop' => esc_html__( 'Desktop', 'et_builder' ), | |
233 | ), | |
234 | 'additional_att' => 'disable_on', | |
235 | 'option_category' => 'configuration', | |
236 | 'description' => esc_html__( 'This will disable the module on selected devices', 'et_builder' ), | |
237 | 'tab_slug' => 'custom_css', | |
238 | 'toggle_slug' => 'visibility', | |
239 | ), | |
240 | 'admin_label' => array( | |
241 | 'label' => esc_html__( 'Admin Label', 'et_builder' ), | |
242 | 'type' => 'text', | |
243 | 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ), | |
244 | 'toggle_slug' => 'admin_label', | |
245 | ), | |
246 | 'module_id' => array( | |
247 | 'label' => esc_html__( 'CSS ID', 'et_builder' ), | |
248 | 'type' => 'text', | |
249 | 'option_category' => 'configuration', | |
250 | 'tab_slug' => 'custom_css', | |
251 | 'toggle_slug' => 'classes', | |
252 | 'option_class' => 'et_pb_custom_css_regular', | |
253 | ), | |
254 | 'module_class' => array( | |
255 | 'label' => esc_html__( 'CSS Class', 'et_builder' ), | |
256 | 'type' => 'text', | |
257 | 'option_category' => 'configuration', | |
258 | 'tab_slug' => 'custom_css', | |
259 | 'toggle_slug' => 'classes', | |
260 | 'option_class' => 'et_pb_custom_css_regular', | |
261 | ), | |
262 | ); | |
263 | ||
264 | return $fields; | |
265 | } | |
266 | ||
267 | function predefined_child_modules() { | |
268 | $output = sprintf( | |
269 | '[et_pb_contact_field field_title="%1$s" field_type="input" field_id="Name" required_mark="on" fullwidth_field="off" /][et_pb_contact_field field_title="%2$s" field_type="email" field_id="Email" required_mark="on" fullwidth_field="off" /][et_pb_contact_field field_title="%3$s" field_type="text" field_id="Message" required_mark="on" fullwidth_field="on" /]', | |
270 | esc_attr__( 'Name', 'et_builder' ), | |
271 | esc_attr__( 'Email Address', 'et_builder' ), | |
272 | esc_attr__( 'Message', 'et_builder' ) | |
273 | ); | |
274 | ||
275 | return $output; | |
276 | } | |
277 | ||
278 | function shortcode_callback( $atts, $content = null, $function_name ) { | |
279 | $module_id = $this->shortcode_atts['module_id']; | |
280 | $module_class = $this->shortcode_atts['module_class']; | |
281 | $captcha = $this->shortcode_atts['captcha']; | |
282 | $email = $this->shortcode_atts['email']; | |
283 | $title = $this->shortcode_atts['title']; | |
284 | $form_field_text_color = $this->shortcode_atts['form_field_text_color']; | |
285 | $form_background_color = $this->shortcode_atts['form_background_color']; | |
286 | $button_custom = $this->shortcode_atts['custom_button']; | |
287 | $custom_icon = $this->shortcode_atts['button_icon']; | |
288 | $submit_button_text = $this->shortcode_atts['submit_button_text']; | |
289 | $custom_message = $this->shortcode_atts['custom_message']; | |
290 | $use_redirect = $this->shortcode_atts['use_redirect']; | |
291 | $redirect_url = $this->shortcode_atts['redirect_url']; | |
292 | $success_message = $this->shortcode_atts['success_message']; | |
293 | $header_level = $this->shortcode_atts['title_level']; | |
294 | ||
295 | global $et_pb_contact_form_num; | |
296 | ||
297 | $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name ); | |
298 | $video_background = $this->video_background(); | |
299 | $parallax_image_background = $this->get_parallax_image_background(); | |
300 | ||
301 | if ( '' !== $form_field_text_color ) { | |
302 | ET_Builder_Element::set_style( $function_name, array( | |
303 | 'selector' => '%%order_class%% .input[type="checkbox"]:checked + label i:before', | |
304 | 'declaration' => sprintf( | |
305 | 'color: %1$s%2$s;', | |
306 | esc_html( $form_field_text_color ), | |
307 | et_is_builder_plugin_active() ? ' !important' : '' | |
308 | ), | |
309 | ) ); | |
310 | ||
311 | ET_Builder_Element::set_style( $function_name, array( | |
312 | 'selector' => '%%order_class%% .input[type="radio"]:checked + label i:before', | |
313 | 'declaration' => sprintf( | |
314 | 'background-color: %1$s%2$s;', | |
315 | esc_html( $form_field_text_color ), | |
316 | et_is_builder_plugin_active() ? ' !important' : '' | |
317 | ), | |
318 | ) ); | |
319 | } | |
320 | ||
321 | if ( '' !== $form_background_color ) { | |
322 | ET_Builder_Element::set_style( $function_name, array( | |
323 | 'selector' => '%%order_class%% .input, %%order_class%% .input[type="checkbox"] + label i, %%order_class%% .input[type="radio"] + label i', | |
324 | 'declaration' => sprintf( | |
325 | 'background-color: %1$s%2$s;', | |
326 | esc_html( $form_background_color ), | |
327 | et_is_builder_plugin_active() ? ' !important' : '' | |
328 | ), | |
329 | ) ); | |
330 | } | |
331 | ||
332 | $success_message = '' !== $success_message ? $success_message : esc_html__( 'Thanks for contacting us', 'et_builder' ); | |
333 | ||
334 | $et_pb_contact_form_num = $this->shortcode_callback_num(); | |
335 | ||
336 | $content = $this->shortcode_content; | |
337 | ||
338 | $et_error_message = ''; | |
339 | $et_contact_error = false; | |
340 | $current_form_fields = isset( $_POST['et_pb_contact_email_fields_' . $et_pb_contact_form_num] ) ? $_POST['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : ''; | |
341 | $hidden_form_fields = isset( $_POST['et_pb_contact_email_hidden_fields_' . $et_pb_contact_form_num] ) ? $_POST['et_pb_contact_email_hidden_fields_' . $et_pb_contact_form_num] : false; | |
342 | $contact_email = ''; | |
343 | $processed_fields_values = array(); | |
344 | ||
345 | $nonce_result = isset( $_POST['_wpnonce-et-pb-contact-form-submitted'] ) && wp_verify_nonce( $_POST['_wpnonce-et-pb-contact-form-submitted'], 'et-pb-contact-form-submit' ) ? true : false; | |
346 | ||
347 | // check that the form was submitted and et_pb_contactform_validate field is empty to protect from spam | |
348 | if ( $nonce_result && isset( $_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num] ) && empty( $_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num] ) ) { | |
349 | if ( '' !== $current_form_fields ) { | |
350 | $fields_data_json = str_replace( '\\', '' , $current_form_fields ); | |
351 | $fields_data_array = json_decode( $fields_data_json, true ); | |
352 | ||
353 | // check whether captcha field is not empty | |
354 | if ( 'on' === $captcha && ( ! isset( $_POST['et_pb_contact_captcha_' . $et_pb_contact_form_num] ) || empty( $_POST['et_pb_contact_captcha_' . $et_pb_contact_form_num] ) ) ) { | |
355 | $et_error_message .= sprintf( '<p class="et_pb_contact_error_text">%1$s</p>', esc_html__( 'Make sure you entered the captcha.', 'et_builder' ) ); | |
356 | $et_contact_error = true; | |
357 | } | |
358 | ||
359 | // check all fields on current form and generate error message if needed | |
360 | if ( ! empty( $fields_data_array ) ) { | |
361 | foreach( $fields_data_array as $index => $value ) { | |
362 | // check all the required fields, generate error message if required field is empty | |
363 | if ( 'required' === $value['required_mark'] && empty( $_POST[ $value['field_id'] ] ) ) { | |
364 | $et_error_message .= sprintf( '<p class="et_pb_contact_error_text">%1$s</p>', esc_html__( 'Make sure you fill in all required fields.', 'et_builder' ) ); | |
365 | $et_contact_error = true; | |
366 | continue; | |
367 | } | |
368 | ||
369 | // additional check for email field | |
370 | if ( 'email' === $value['field_type'] && 'required' === $value['required_mark'] && ! empty( $_POST[ $value['field_id'] ] ) ) { | |
371 | $contact_email = sanitize_email( $_POST[ $value['field_id'] ] ); | |
372 | if ( ! is_email( $contact_email ) ) { | |
373 | $et_error_message .= sprintf( '<p class="et_pb_contact_error_text">%1$s</p>', esc_html__( 'Invalid Email.', 'et_builder' ) ); | |
374 | $et_contact_error = true; | |
375 | } | |
376 | } | |
377 | ||
378 | // prepare the array of processed field values in convenient format | |
379 | if ( false === $et_contact_error ) { | |
380 | $processed_fields_values[ $value['original_id'] ]['value'] = isset( $_POST[ $value['field_id'] ] ) ? $_POST[ $value['field_id'] ] : ''; | |
381 | $processed_fields_values[ $value['original_id'] ]['label'] = $value['field_label']; | |
382 | } | |
383 | } | |
384 | } | |
385 | } else { | |
386 | $et_error_message .= sprintf( '<p class="et_pb_contact_error_text">%1$s</p>', esc_html__( 'Make sure you fill in all required fields.', 'et_builder' ) ); | |
387 | $et_contact_error = true; | |
388 | } | |
389 | } else { | |
390 | if ( false === $nonce_result && isset( $_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num] ) && empty( $_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num] ) ) { | |
391 | $et_error_message .= sprintf( '<p class="et_pb_contact_error_text">%1$s</p>', esc_html__( 'Please refresh the page and try again.', 'et_builder' ) ); | |
392 | } | |
393 | $et_contact_error = true; | |
394 | } | |
395 | ||
396 | // generate digits for captcha | |
397 | $et_pb_first_digit = rand( 1, 15 ); | |
398 | $et_pb_second_digit = rand( 1, 15 ); | |
399 | ||
400 | if ( ! $et_contact_error && $nonce_result ) { | |
401 | $et_email_to = '' !== $email | |
402 | ||
403 | : get_site_option( 'admin_email' ); | |
404 | ||
405 | $et_site_name = get_option( 'blogname' ); | |
406 | ||
407 | $contact_name = isset( $processed_fields_values['name'] ) ? stripslashes( sanitize_text_field( $processed_fields_values['name']['value'] ) ) : ''; | |
408 | ||
409 | if ( '' !== $custom_message ) { | |
410 | $message_pattern = et_builder_convert_line_breaks( $custom_message, "\r\n" ); | |
411 | ||
412 | // insert the data from contact form into the message pattern | |
413 | foreach ( $processed_fields_values as $key => $value ) { | |
414 | $message_pattern = str_ireplace( "%%{$key}%%", $value['value'], $message_pattern ); | |
415 | } | |
416 | ||
417 | if ( false !== $hidden_form_fields ) { | |
418 | $hidden_form_fields = str_replace( '\\', '' , $hidden_form_fields ); | |
419 | $hidden_form_fields = json_decode( $hidden_form_fields ); | |
420 | ||
421 | if ( is_array( $hidden_form_fields ) ) { | |
422 | foreach ( $hidden_form_fields as $hidden_field_label ) { | |
423 | $message_pattern = str_ireplace( "%%{$hidden_field_label}%%", '', $message_pattern ); | |
424 | } | |
425 | } | |
426 | } | |
427 | } else { | |
428 | // use default message pattern if custom pattern is not defined | |
429 | $message_pattern = isset( $processed_fields_values['message']['value'] ) ? $processed_fields_values['message']['value'] : ''; | |
430 | ||
431 | // Add all custom fields into the message body by default | |
432 | foreach ( $processed_fields_values as $key => $value ) { | |
433 | if ( ! in_array( $key, array( 'message', 'name', 'email' ) ) ) { | |
434 | $message_pattern .= "\r\n"; | |
435 | $message_pattern .= sprintf( | |
436 | '%1$s: %2$s', | |
437 | '' !== $value['label'] ? $value['label'] : $key, | |
438 | $value['value'] | |
439 | ); | |
440 | } | |
441 | } | |
442 | } | |
443 | ||
444 | $http_host = str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ); | |
445 | ||
446 | $headers[] = "From: \"{$contact_name}\" <mail@{$http_host}>"; | |
447 | $headers[] = "Reply-To: \"{$contact_name}\" <{$contact_email}>"; | |
448 | ||
449 | add_filter( 'et_get_safe_localization', 'et_allow_ampersand' ); | |
450 | ||
451 | $email_message = trim( stripslashes( wp_strip_all_tags( $message_pattern ) ) ); | |
452 | ||
453 | wp_mail( apply_filters( 'et_contact_page_email_to', $et_email_to ), | |
454 | et_get_safe_localization( sprintf( | |
455 | __( 'New Message From %1$s%2$s', 'et_builder' ), | |
456 | sanitize_text_field( html_entity_decode( $et_site_name, ENT_QUOTES, 'UTF-8' ) ), | |
457 | ( '' !== $title ? sprintf( _x( ' - %s', 'contact form title separator', 'et_builder' ), sanitize_text_field( html_entity_decode( $title, ENT_QUOTES, 'UTF-8' ) ) ) : '' ) | |
458 | ) ), | |
459 | ! empty( $email_message ) ? $email_message : ' ', | |
460 | apply_filters( 'et_contact_page_headers', $headers, $contact_name, $contact_email ) | |
461 | ); | |
462 | ||
463 | remove_filter( 'et_get_safe_localization', 'et_allow_ampersand' ); | |
464 | ||
465 | $et_error_message = sprintf( '<p>%1$s</p>', esc_html( $success_message ) ); | |
466 | } | |
467 | ||
468 | $form = ''; | |
469 | ||
470 | $et_pb_captcha = sprintf( ' | |
471 | <div class="et_pb_contact_right"> | |
472 | <p class="clearfix"> | |
473 | <span class="et_pb_contact_captcha_question">%1$s</span> = <input type="text" size="2" class="input et_pb_contact_captcha" data-first_digit="%3$s" data-second_digit="%4$s" value="" name="et_pb_contact_captcha_%2$s" data-required_mark="required"> | |
474 | </p> | |
475 | </div> <!-- .et_pb_contact_right -->', | |
476 | sprintf( '%1$s + %2$s', esc_html( $et_pb_first_digit ), esc_html( $et_pb_second_digit ) ), | |
477 | esc_attr( $et_pb_contact_form_num ), | |
478 | esc_attr( $et_pb_first_digit ), | |
479 | esc_attr( $et_pb_second_digit ) | |
480 | ); | |
481 | ||
482 | if ( '' === trim( $content ) ) { | |
483 | $content = do_shortcode( $this->predefined_child_modules() ); | |
484 | } | |
485 | ||
486 | if ( $et_contact_error ) { | |
487 | // Make sure submit button text is not just a space | |
488 | $submit_button_text = trim( $submit_button_text ); | |
489 | ||
490 | // We can't use `empty( trim() )` because that throws | |
491 | // an error on old(er) PHP versions | |
492 | if ( empty( $submit_button_text ) ) { | |
493 | $submit_button_text = __( 'Submit', 'et_builder' ); | |
494 | } | |
495 | ||
496 | $form = sprintf( ' | |
497 | <div class="et_pb_contact"> | |
498 | <form class="et_pb_contact_form clearfix" method="post" action="%1$s"> | |
499 | %8$s | |
500 | <input type="hidden" value="et_contact_proccess" name="et_pb_contactform_submit_%7$s"> | |
501 | <input type="text" value="" name="et_pb_contactform_validate_%7$s" class="et_pb_contactform_validate_field" /> | |
502 | <div class="et_contact_bottom_container"> | |
503 | %2$s | |
504 | <button type="submit" class="et_pb_contact_submit et_pb_button%6$s"%5$s>%3$s</button> | |
505 | </div> | |
506 | %4$s | |
507 | </form> | |
508 | </div> <!-- .et_pb_contact -->', | |
509 | esc_url( get_permalink( get_the_ID() ) ), | |
510 | ( 'on' === $captcha ? $et_pb_captcha : '' ), | |
511 | esc_html( $submit_button_text ), | |
512 | wp_nonce_field( 'et-pb-contact-form-submit', '_wpnonce-et-pb-contact-form-submitted', true, false ), | |
513 | '' !== $custom_icon && 'on' === $button_custom ? sprintf( | |
514 | ' data-icon="%1$s"', | |
515 | esc_attr( et_pb_process_font_icon( $custom_icon ) ) | |
516 | ) : '', | |
517 | '' !== $custom_icon && 'on' === $button_custom ? ' et_pb_custom_button_icon' : '', | |
518 | esc_attr( $et_pb_contact_form_num ), | |
519 | $content | |
520 | ); | |
521 | } | |
522 | ||
523 | $output = sprintf( ' | |
524 | <div id="%4$s" class="et_pb_module et_pb_contact_form_container clearfix%5$s%8$s%10$s%12$s" data-form_unique_num="%6$s"%7$s> | |
525 | %11$s | |
526 | %9$s | |
527 | %1$s | |
528 | <div class="et-pb-contact-message">%2$s</div> | |
529 | %3$s | |
530 | </div> <!-- .et_pb_contact_form_container --> | |
531 | ', | |
532 | ( '' !== $title ? sprintf( '<%2$s class="et_pb_contact_main_title">%1$s</%2$s>', esc_html( $title ), et_pb_process_header_level( $header_level, 'h1' ) ) : '' ), | |
533 | '' !== $et_error_message ? $et_error_message : '', | |
534 | $form, | |
535 | ( '' !== $module_id | |
536 | ? esc_attr( $module_id ) | |
537 | : esc_attr( 'et_pb_contact_form_' . $et_pb_contact_form_num ) | |
538 | ), | |
539 | ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ), | |
540 | esc_attr( $et_pb_contact_form_num ), | |
541 | 'on' === $use_redirect && '' !== $redirect_url ? sprintf( ' data-redirect_url="%1$s"', esc_attr( $redirect_url ) ) : '', | |
542 | '' !== $video_background ? ' et_pb_section_video et_pb_preload' : '', | |
543 | $video_background, | |
544 | '' !== $parallax_image_background ? ' et_pb_section_parallax' : '', | |
545 | $parallax_image_background, | |
546 | $this->get_text_orientation_classname() | |
547 | ); | |
548 | ||
549 | return $output; | |
550 | } | |
551 | ||
552 | public function process_box_shadow( $function_name ) { | |
553 | $boxShadow = ET_Builder_Module_Fields_Factory::get( 'BoxShadow' ); | |
554 | ||
555 | $selectors = array( | |
556 | '%%order_class%% .et_pb_contact_field input', | |
557 | '%%order_class%% .et_pb_contact_field select', | |
558 | '%%order_class%% .et_pb_contact_field textarea', | |
559 | '%%order_class%% .et_pb_contact_field .et_pb_contact_field_options_list label > i', | |
560 | '%%order_class%% input.et_pb_contact_captcha', | |
561 | ); | |
562 | self::set_style( $function_name, array( | |
563 | 'selector' => implode( ', ', $selectors ), | |
564 | 'declaration' => $boxShadow->get_value( $this->shortcode_atts ) | |
565 | ) | |
566 | ); | |
567 | ||
568 | if ( | |
569 | isset( $this->shortcode_atts['custom_button'] ) | |
570 | && | |
571 | $this->shortcode_atts['custom_button'] === 'on' | |
572 | ) { | |
573 | self::set_style( $function_name, array( | |
574 | 'selector' => '%%order_class%% .et_pb_contact_submit', | |
575 | 'declaration' => $boxShadow->get_value( $this->shortcode_atts, array( 'suffix' => '_button' ) ) | |
576 | ) | |
577 | ); | |
578 | } | |
579 | } | |
580 | } | |
581 | ||
582 | new ET_Builder_Module_Contact_Form; |