PluginProbe
Property Hive / 2.2.5
Property Hive v2.2.5
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / assets / js / frontend / make-enquiry.js

make-enquiry.js in Property Hive 2.2.5, at assets/js/frontend/make-enquiry.js

92 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var is_submitting = false;
2 var form_obj;
3 jQuery( function($){
4
5 // Enquiry form being submitted
6 jQuery('body').on('submit', 'form[name=\'ph_property_enquiry\']', function()
7 {
8 if ( !is_submitting )
9 {
10 form_obj = jQuery(this);
11
12 if ( propertyhive_make_property_enquiry_params.captcha_service == 'recaptcha-v3' && typeof grecaptcha !== 'undefined' )
13 {
14 grecaptcha.execute(propertyhive_make_property_enquiry_params.recaptcha_site_key, { action: 'submit' }).then(function(token)
15 {
16 jQuery('#g-recaptcha-response').val(token);
17 ph_submit_property_enquiry(); // Submit form after getting the new token
18 });
19 }
20 else
21 {
22 ph_submit_property_enquiry(); // If reCAPTCHA is undefined, still submit
23 }
24 }
25
26 return false;
27 });
28
29 });
30
31 function ph_submit_property_enquiry()
32 {
33 is_submitting = true;
34
35 var data = form_obj.serialize() + '&' + jQuery.param({ 'action': 'propertyhive_make_property_enquiry' });
36
37 form_obj.find('#enquirySuccess').hide();
38 form_obj.find('#enquiryValidation').hide().text(propertyhive_make_property_enquiry_params.default_validation_error_message);
39 form_obj.find('#enquiryError').hide();
40
41 jQuery.post( propertyhive_make_property_enquiry_params.ajax_url, data, function(response) {
42
43 if (response.success == true)
44 {
45 if ( propertyhive_make_property_enquiry_params.redirect_url && propertyhive_make_property_enquiry_params.redirect_url != '' )
46 {
47 window.location.href = propertyhive_make_property_enquiry_params.redirect_url;
48 }
49 else
50 {
51 form_obj.find('#enquirySuccess').fadeIn();
52 form_obj.trigger('ph:success');
53
54 form_obj.trigger("reset");
55 }
56 }
57 else
58 {
59 console.log(response);
60 if (response.reason == 'validation')
61 {
62 if ( response.errors && response.errors.length > 0 )
63 {
64 let error_html = '';
65 for ( var i in response.errors )
66 {
67 if ( error_html != '' ) { error_html += ', '; }
68 error_html += response.errors[i];
69 }
70 form_obj.find('#enquiryValidation').text(error_html);
71 }
72 form_obj.find('#enquiryValidation').fadeIn();
73 form_obj.trigger('ph:validation');
74 }
75 else if (response.reason == 'nosend')
76 {
77 form_obj.find('#enquiryError').fadeIn();
78 form_obj.trigger('ph:nosend');
79 }
80 }
81
82 is_submitting = false;
83
84 if ( propertyhive_make_property_enquiry_params.captcha_service == 'recaptcha' )
85 {
86 // Reset reCAPTCHA for v2 (checkbox version)
87 if (typeof grecaptcha !== 'undefined' && typeof grecaptcha.reset === 'function') {
88 grecaptcha.reset();
89 }
90 }
91 });
92 }