From d504440371344413aa931ccd83a9ea40af288208 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 24 Dec 2015 20:10:57 -0500 Subject: [PATCH] Ajaxing the form. --- index.html | 9 ++++----- js/form-handling.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 js/form-handling.js diff --git a/index.html b/index.html index afaf54c..289d564 100644 --- a/index.html +++ b/index.html @@ -86,18 +86,17 @@

You can also send me an email at c.marcandre[at]gmail.com, or fill the form below!

-
+

About you:

-

My name is , I'm a . You can contact me at .

+

My name is , I'm a . You can contact me at .

I'd like to tell you about ...

-

+

- +
-
diff --git a/js/form-handling.js b/js/form-handling.js new file mode 100644 index 0000000..8a8bb11 --- /dev/null +++ b/js/form-handling.js @@ -0,0 +1,22 @@ +var $contactForm = $('#contactme'); + +$contactForm.submit(function(e) { + e.preventDefault(); + $.ajax({ + url: '//formspree.io/c.marcandre@gmail.com', + method: 'POST', + data: $(this).serialize(), + dataType: 'json', + beforeSend: function() { + $contactForm.append('
Sending messageā€¦
'); + }, + success: function(data) { + $contactForm.find('.alert--loading').hide(); + $contactForm.append('
Message sent!
'); + }, + error: function(err) { + $contactForm.find('.alert--loading').hide(); + $contactForm.append('
Ops, there was an error.
'); + } + }); +}); \ No newline at end of file