"Contact form with jquery validation"
Bootstrap 3.3.0 Snippet by bipon68

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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="container">
<h2 class="text-center">Contact Us</h2>
<div class="errors">
</div>
<form action="<?=$_SERVER['PHP_SELF']?>" class="contact-form" method="POST">
<div class="form-group">
<input type="text" name="username" id="username" class="username form-control" placeholder="Your Username" value="">
<i class="fa fa-user"></i>
<span class="asterix">*</span>
<span class="cross">x</span>
<span class="verify"><i class="fa fa-check" aria-hidden="true"></i></span>
<div class="alert alert-danger custom-alert">
user must be more than 3 letter
</div>
</div>
<div class="form-group">
<input type="text" name="email" class=" email form-control" placeholder="Your Email" value="">
<i class="fa fa-envelope"></i>
<span class="asterix">*</span>
<span class="cross">x</span>
<span class="verify"><i class="fa fa-check" aria-hidden="true"></i></span>
<div class="alert alert-danger custom-alert">
Email can not be empty
</div>
</div>
<div class="form-group">
<input type="text" name="subject" class="subject form-control" placeholder="Your subject" value="">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
/*start .contact-form*/
@import url('https://fonts.googleapis.com/css?family=Raleway');
body{
font-family: 'Raleway', sans-serif;
background: url(../img/body_bg.jpg);
background-repeat: no-repeat;
background-size: cover;
}
h2{
font-weight: bold;
font-size: 40px;
}
.contact-form{
max-width: 500px;
margin: 50px auto;
}
.contact-form .form-group{
margin-bottom: 0;
position: relative;
}
.contact-form input,
.contact-form textarea{
margin-bottom: 20px;
background: #ececec;
}
.contact-form input:focus{
border: 1px solid #999;
outline: none !important;
}
.contact-form input{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
$(function () {
'use strict';
// error variables
var UserError = true,
EmailError = true,
SubError = true,
MsgError = true;
$(".username").blur(function() {
if($(this).val().length < 4){
$(this).css('border','1px solid #F00');
$(this).parent().find('.custom-alert').fadeIn(300).end().find('.asterix').fadeOut(300).end().find('span.cross').fadeIn(300).end().find('span.verify').fadeOut(300);
UserError = true;
}else{
$(this).css('border','1px solid #080');
$(this).parent().find('.custom-alert').fadeOut(300).end().find('.asterix').fadeOut(300).end().find('span.verify').fadeIn(300).end().find('span.cross').fadeOut(300);
UserError = false;
}
});
$(".email").blur(function() {
if($(this).val() === ''){
$(this).css('border','1px solid #F00');
$(this).parent().find('.custom-alert').fadeIn(300).end().find('.asterix').fadeOut(300).end().find('span.cross').fadeIn(300).end().find('span.verify').fadeOut(300);
EmailError = true;
}else{
$(this).css('border','1px solid #080');
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: