-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
77 lines (67 loc) · 2.88 KB
/
contact.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<form id="contact" class="contact" method="post" action="/mail.php">
<h2>
<span class="alpha">Say hello!</span>
<span class="contact__subtitle gamma muted">(Or something else)</span>
</h2>
<label for="contact-name" class="accessibility">Name</label>
<input id="contact-name" name="contact-name" type="text" class="text-input contact__name" placeholder="Name">
<label for="contact-email" class="accessibility">Email</label>
<input id="contact-email" name="contact-email" type="email" class="text-input contact__email" placeholder="Email">
<label for="contact-message" class="accessibility">Message</label>
<textarea id="contact-message" name="contact-message" class="contact__message text-input" placeholder="Enter your message here."></textarea>
<button type="submit" class="btn btn--large float--right contact__submit">Submit</button>
<div id="contact-loader" class="spinner contact-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
<div id="contact-result" class="form__result">
<p></p>
<a href="#" class="result__close btn btn--large btn--secondary">
Okay
</a>
</div>
</form>
<script>
//
// Contact form
//
$(function() {
var form = $('#contact'),
formLoader = $('#contact-loader'),
formResult = $('#contact-result'),
formResultText = $('#contact-result > p');
$(form).submit(function(event) {
event.preventDefault();
$(formLoader).show();
var formData = $(form).serialize();
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
})
.done(function(response) {
$(formResult).removeClass('form__result--error');
$(formResult).addClass('form__result--visible form__result--success');
$(formResultText).text(response);
$('#contact-name').val('');
$('#contact-email').val('');
$('#contact-message').val('');
})
.fail(function(data) {
$(formResult).removeClass('form__result--success');
$(formResult).addClass('form__result--visible form__result--error');
if (data.responseText !== '') {
$(formResultText).text(data.responseText);
} else {
$(formResultText).text('Sorry, an error occurred. :(')
}
});
});
$('.result__close').click(function(e) {
e.preventDefault();
$(formLoader).hide();
$(formResult).removeClass('form__result--visible');
});
});
</script>