1 | // Contact Form Scripts |
---|
2 | |
---|
3 | $(function() { |
---|
4 | |
---|
5 | $("#contactForm input,#contactForm textarea").jqBootstrapValidation({ |
---|
6 | preventSubmit: true, |
---|
7 | submitError: function($form, event, errors) { |
---|
8 | // additional error messages or events |
---|
9 | }, |
---|
10 | submitSuccess: function($form, event) { |
---|
11 | event.preventDefault(); // prevent default submit behaviour |
---|
12 | // get values from FORM |
---|
13 | var name = $("input#name").val(); |
---|
14 | var email = $("input#email").val(); |
---|
15 | var phone = $("input#phone").val(); |
---|
16 | var message = $("textarea#message").val(); |
---|
17 | var firstName = name; // For Success/Failure Message |
---|
18 | // Check for white space in name for Success/Fail message |
---|
19 | if (firstName.indexOf(' ') >= 0) { |
---|
20 | firstName = name.split(' ').slice(0, -1).join(' '); |
---|
21 | } |
---|
22 | $.ajax({ |
---|
23 | url: "././mail/contact_me.php", |
---|
24 | type: "POST", |
---|
25 | data: { |
---|
26 | name: name, |
---|
27 | phone: phone, |
---|
28 | email: email, |
---|
29 | message: message |
---|
30 | }, |
---|
31 | cache: false, |
---|
32 | success: function() { |
---|
33 | // Success message |
---|
34 | $('#success').html("<div class='alert alert-success'>"); |
---|
35 | $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×") |
---|
36 | .append("</button>"); |
---|
37 | $('#success > .alert-success') |
---|
38 | .append("<strong>Your message has been sent. </strong>"); |
---|
39 | $('#success > .alert-success') |
---|
40 | .append('</div>'); |
---|
41 | |
---|
42 | //clear all fields |
---|
43 | $('#contactForm').trigger("reset"); |
---|
44 | }, |
---|
45 | error: function() { |
---|
46 | // Fail message |
---|
47 | $('#success').html("<div class='alert alert-danger'>"); |
---|
48 | $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×") |
---|
49 | .append("</button>"); |
---|
50 | $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!"); |
---|
51 | $('#success > .alert-danger').append('</div>'); |
---|
52 | //clear all fields |
---|
53 | $('#contactForm').trigger("reset"); |
---|
54 | }, |
---|
55 | }); |
---|
56 | }, |
---|
57 | filter: function() { |
---|
58 | return $(this).is(":visible"); |
---|
59 | }, |
---|
60 | }); |
---|
61 | |
---|
62 | $("a[data-toggle=\"tab\"]").click(function(e) { |
---|
63 | e.preventDefault(); |
---|
64 | $(this).tab("show"); |
---|
65 | }); |
---|
66 | }); |
---|
67 | |
---|
68 | |
---|
69 | /*When clicking on Full hide fail/success boxes */ |
---|
70 | $('#name').focus(function() { |
---|
71 | $('#success').html(''); |
---|
72 | }); |
---|