-
Notifications
You must be signed in to change notification settings - Fork 0
/
asdf.html
110 lines (91 loc) · 2.34 KB
/
asdf.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<html>
<head>
<title> How is this Possible? </title>
<style type="text/css">
body {
background-image: url(tarnation.jpg);
}
.box {
position: relative;
top: 15vh;
width: calc(100% - 55vw);
margin: auto;
background: rgb(100,100,100);
padding-top: 2vh;
padding-bottom: 2vh;
border-radius: 2vw;
}
form > * {
font-size: 2vw;
display: block;
position: relative;
width: auto;
margin: auto;
margin-bottom: 3vh;
margin-top: 3vh;
}
h3 {
text-align: center;
font-family: Helvetica;
font-weight: bold;
color: white;
}
</style>
<script src="jquery-2.1.0.min.js"></script>
<script>
$(function() {
// Get the form.
var form = $('#ajax-contact');
// Get the messages div.
var formMessages = $('#form-messages');
// TODO: The rest of the code will go here...
});
// Set up an event listener for the contact form.
$(form).submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
// TODO
});
// Serialize the form data.
var formData = $(form).serialize();
// Submit the form using AJAX.
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
})
.done(function(response) {
// Make sure that the formMessages div has the 'success' class.
$(formMessages).removeClass('error');
$(formMessages).addClass('success');
// Set the message text.
$(formMessages).text(response);
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#message').val('');
})
.fail(function(data) {
// Make sure that the formMessages div has the 'error' class.
$(formMessages).removeClass('success');
$(formMessages).addClass('error');
// Set the message text.
if (data.responseText !== '') {
$(formMessages).text(data.responseText);
} else {
$(formMessages).text('Oops! An error occured and your message could not be sent.');
}
});
</script>
</head>
<body>
<div class="box">
<form id="ajax-contact" name="riddle" method="post" action="riddle.php">
<h3>How is this possible?</h3>
<textarea type="text" name="answer" rows="3" cols="30" required></textarea>
<input type="submit" name="Submit">
</form>
<div id="form-messages"></div>
</div>
</body>
</html>