Skip to content

Commit 5c8e25d

Browse files
committedAug 6, 2015
init commit
1 parent 2b66e06 commit 5c8e25d

11 files changed

+3584
-0
lines changed
 

‎bootstrap-form.html

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Contact form using Bootstrap 3.3.4</title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
6+
<meta charset="utf-8">
7+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
8+
<link rel="stylesheet" href="css/bootstrap.min.css">
9+
<link rel="stylesheet" href="css/animate.css">
10+
</head>
11+
<body style="background-color: #7e7e7e">
12+
<div class="row">
13+
<div class="col-sm-6 col-sm-offset-3">
14+
<div class="well" style="margin-top: 10%;">
15+
<h3>Send me a message</h3>
16+
<form role="form" id="contactForm" data-toggle="validator" class="shake">
17+
<div class="row">
18+
<div class="form-group col-sm-6">
19+
<label for="name" class="h4">Name</label>
20+
<input type="text" class="form-control" id="name" placeholder="Enter name" required data-error="NEW ERROR MESSAGE">
21+
<div class="help-block with-errors"></div>
22+
</div>
23+
<div class="form-group col-sm-6">
24+
<label for="email" class="h4">Email</label>
25+
<input type="email" class="form-control" id="email" placeholder="Enter email" required>
26+
<div class="help-block with-errors"></div>
27+
</div>
28+
</div>
29+
<div class="form-group">
30+
<label for="message" class="h4 ">Message</label>
31+
<textarea id="message" class="form-control" rows="5" placeholder="Enter your message" required></textarea>
32+
<div class="help-block with-errors"></div>
33+
</div>
34+
<button type="submit" id="form-submit" class="btn btn-success btn-lg pull-right ">Submit</button>
35+
<div id="msgSubmit" class="h3 text-center hidden"></div>
36+
<div class="clearfix"></div>
37+
</form>
38+
</div>
39+
</div>
40+
</div>
41+
</body>
42+
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
43+
<script type="text/javascript" src="js/validator.min.js"></script>
44+
<script type="text/javascript" src="js/form-scripts.js"></script>
45+
</html>

‎css/animate.css

+3,181
Large diffs are not rendered by default.

‎css/bootstrap.min.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
19.9 KB
Binary file not shown.

‎fonts/glyphicons-halflings-regular.svg

+229
Loading
40.3 KB
Binary file not shown.
22.8 KB
Binary file not shown.

‎js/form-scripts.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
$("#contactForm").validator().on("submit", function (event) {
2+
if (event.isDefaultPrevented()) {
3+
// handle the invalid form...
4+
formError();
5+
submitMSG(false, "Did you fill in the form properly?");
6+
} else {
7+
// everything looks good!
8+
event.preventDefault();
9+
submitForm();
10+
}
11+
});
12+
13+
14+
function submitForm(){
15+
// Initiate Variables With Form Content
16+
var name = $("#name").val();
17+
var email = $("#email").val();
18+
var message = $("#message").val();
19+
20+
$.ajax({
21+
type: "POST",
22+
url: "php/form-process.php",
23+
data: "name=" + name + "&email=" + email + "&message=" + message,
24+
success : function(text){
25+
if (text == "success"){
26+
formSuccess();
27+
} else {
28+
formError();
29+
submitMSG(false,text);
30+
}
31+
}
32+
});
33+
}
34+
35+
function formSuccess(){
36+
$("#contactForm")[0].reset();
37+
submitMSG(true, "Message Submitted!")
38+
}
39+
40+
function formError(){
41+
$("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
42+
$(this).removeClass();
43+
});
44+
}
45+
46+
function submitMSG(valid, msg){
47+
if(valid){
48+
var msgClasses = "h3 text-center tada animated text-success";
49+
} else {
50+
var msgClasses = "h3 text-center text-danger";
51+
}
52+
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
53+
}

‎js/jquery-1.11.2.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/validator.min.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎php/form-process.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
$errorMSG = "";
4+
5+
// NAME
6+
if (empty($_POST["name"])) {
7+
$errorMSG = "Name is required ";
8+
} else {
9+
$name = $_POST["name"];
10+
}
11+
12+
// EMAIL
13+
if (empty($_POST["email"])) {
14+
$errorMSG .= "Email is required ";
15+
} else {
16+
$email = $_POST["email"];
17+
}
18+
19+
// MESSAGE
20+
if (empty($_POST["message"])) {
21+
$errorMSG .= "Message is required ";
22+
} else {
23+
$message = $_POST["message"];
24+
}
25+
26+
27+
$EmailTo = "emailaddress@test.com";
28+
$Subject = "New Message Received";
29+
30+
// prepare email body text
31+
$Body = "";
32+
$Body .= "Name: ";
33+
$Body .= $name;
34+
$Body .= "\n";
35+
$Body .= "Email: ";
36+
$Body .= $email;
37+
$Body .= "\n";
38+
$Body .= "Message: ";
39+
$Body .= $message;
40+
$Body .= "\n";
41+
42+
// send email
43+
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
44+
45+
// redirect to success page
46+
if ($success && $errorMSG == ""){
47+
echo "success";
48+
}else{
49+
if($errorMSG == ""){
50+
echo "Something went wrong :(";
51+
} else {
52+
echo $errorMSG;
53+
}
54+
}
55+
56+
?>

0 commit comments

Comments
 (0)
Please sign in to comment.