summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorNoah Jewell <njewe42@tscstudents.net>2017-04-11 19:43:10 +0000
committerNoah Jewell <njewe42@tscstudents.net>2017-04-11 19:43:10 +0000
commitbfd7a72ccd30d98a2614e3a6af0a59c311f8c7e1 (patch)
treefe2a4faa4cb8da25880e14eb486e7f08ed816b55 /js
parent139b76d195c1095c12f77eb34ba98cea55161183 (diff)
Upload new file
Diffstat (limited to 'js')
-rw-r--r--js/contact_me.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/js/contact_me.js b/js/contact_me.js
new file mode 100644
index 0000000..c3d8ecc
--- /dev/null
+++ b/js/contact_me.js
@@ -0,0 +1,72 @@
+// Contact Form Scripts
+
+$(function() {
+
+ $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
+ preventSubmit: true,
+ submitError: function($form, event, errors) {
+ // additional error messages or events
+ },
+ submitSuccess: function($form, event) {
+ event.preventDefault(); // prevent default submit behaviour
+ // get values from FORM
+ var name = $("input#name").val();
+ var email = $("input#email").val();
+ var phone = $("input#phone").val();
+ var message = $("textarea#message").val();
+ var firstName = name; // For Success/Failure Message
+ // Check for white space in name for Success/Fail message
+ if (firstName.indexOf(' ') >= 0) {
+ firstName = name.split(' ').slice(0, -1).join(' ');
+ }
+ $.ajax({
+ url: "././mail/contact_me.php",
+ type: "POST",
+ data: {
+ name: name,
+ phone: phone,
+ email: email,
+ message: message
+ },
+ cache: false,
+ success: function() {
+ // Success message
+ $('#success').html("<div class='alert alert-success'>");
+ $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
+ .append("</button>");
+ $('#success > .alert-success')
+ .append("<strong>Your message has been sent. </strong>");
+ $('#success > .alert-success')
+ .append('</div>');
+
+ //clear all fields
+ $('#contactForm').trigger("reset");
+ },
+ error: function() {
+ // Fail message
+ $('#success').html("<div class='alert alert-danger'>");
+ $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
+ .append("</button>");
+ $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
+ $('#success > .alert-danger').append('</div>');
+ //clear all fields
+ $('#contactForm').trigger("reset");
+ },
+ });
+ },
+ filter: function() {
+ return $(this).is(":visible");
+ },
+ });
+
+ $("a[data-toggle=\"tab\"]").click(function(e) {
+ e.preventDefault();
+ $(this).tab("show");
+ });
+});
+
+
+/*When clicking on Full hide fail/success boxes */
+$('#name').focus(function() {
+ $('#success').html('');
+});