-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontact.html
210 lines (198 loc) · 5.8 KB
/
contact.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<html>
<head>
<link rel="shortcut icon" href="favicon.png">
<style>
body{
width: 414px;
font-family: Arial;
font-size: 14px;
padding-top: 100px;
padding-left: 460px;
background: url("img/bg2.jpg");
}
h1{
font-family: verdana;
font-size: 40px;
font-weight: bold;
color: white;
text-align: center;
}
h3{
font-family: verdana;
font-size: 25px;
color: white;
}
#after_submit, #email_validation, #name_validation {
display:none;
}
#after_submit{
background-color: #c0ffc0;
line-height: 31px;
margin-bottom: 10px;
padding-left: 20px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
label, #after_submit{
color: #6c6c6c;
}
input{
line-height: 31px;
}
input, textarea{
width: 288px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
background-color: rgba(255,255,255,.6);
border: solid 1px #b6c7cb;
}
#contact_form{
height: 317px;
background-color: #e1e9eb;
border: solid 1px #e5e5e5;
padding: 10px 20px 50px 20px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#submit_button{
width: 109px;
height: 34px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
background-color: #86c5fa;
-webkit-box-shadow: inset 0 2px rgba(255,255,255,.29);
-moz-box-shadow: inset 0 2px rgba(255,255,255,.29);
box-shadow: inset 0 2px rgba(255,255,255,.29);
border: solid 1px #77a4cb;
font-weight: bold;
color: #fff;
margin-left: 7px;
}
label.required:after {
content:'*';
color:red;
}
.error {
background-color:#FFDFDF;
color:red;
}
.error_message{
font-style: italic;
font-size: 10px;
}
.row {
margin:5px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
var errors = false;
$('.required').parent().find('.input').on('blur', function() {
var error_div = $(this).parent().find('.error_message');
var field_container = $(this).parent();
if (!$.empty_field_validation($(this).val())) {
error_div.html('This field is required.');
error_div.css('display', 'block');
field_container.addClass('error');
errors = true;
} else {
error_div.html('');
error_div.css('display', 'none');
field_container.removeClass('error');
errors = false;
}
});
$('#email').on('blur', function(){
var error_div = $(this).parent().find('.error_message');
var field_container = $(this).parent();
if (!$.email_validation($(this).val())) {
error_div.html('Expected Input: email');
error_div.css('display', 'block');
field_container.addClass('error');
errors = true;
} else {
error_div.html('');
error_div.css('display', 'none');
field_container.removeClass('error');
errors = false;
}
});
$('#contact_form').submit(function(event) {
event.preventDefault();
$('.required').parent().find('.input').trigger('blur');
if (!errors)
$.ajax({
url: '/echo/json/',
data: {
json: JSON.stringify($(this).serializeObject())
},
type: 'post',
success: function(data) {
var message = 'Hi '+data.name+'. Your registration is completed.';
$('#after_submit').html(message);
$('#after_submit').css('display', 'block');
},
error: function() {
var message = 'Hi '+data.name+'. Your registration could not be sent or received. Please try again later';
$('#after_submit').html(message);
$('#after_submit').css('display', 'block');
}
});
else
alert("You didn't completed the form correctly. Check it out and try again!");
});
});
$.empty_field_validation = function(field_value) {
if (field_value.trim() == '') return false;
return true;
}
$.email_validation = function(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
</script>
</head>
<body>
<h1>Contact Us</h1>
<div id="after_submit"></div>
<form id="contact_form" action="#" method="POST" enctype="multipart/form-data">
<div class="row">
<label class="required" for="name">Your name:</label><br />
<input id="name" class="input" name="name" type="text" value="" size="30" /><br />
<span id="name_validation" class="error_message"></span>
</div>
<div class="row">
<label class="required" for="email">Your email:</label><br />
<input id="email" class="input" name="email" type="text" value="" size="30" /><br />
<span id="email_validation" class="error_message"></span>
</div>
<div class="row">
<label class="required" for="message">Your message:</label><br />
<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />
<span id="message_validation" class="error_message"></span>
</div>
<input id="submit_button" type="submit" value="Send email" />
</form>
</body>
</html>