-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
142 lines (129 loc) · 3.86 KB
/
contact.php
File metadata and controls
142 lines (129 loc) · 3.86 KB
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
<?php
require_once(dirname(__FILE__) . "/lib/functions_template.php");
require_once(dirname(__FILE__) . "/lib/functions_blog_format.php");
require_once(dirname(__FILE__) . "/lib/functions_sql.php");
// Store the current page
session_start();
$_SESSION['current-page'] = 'contact';
?>
<!DOCTYPE html>
<html>
<head>
<title>Raymond Shi's Blog</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
</head>
<body>
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<?php
$name='';
$email='';
$category='';
$comment='';
$ok=true;
$insert_failure = false;
if(isset($_POST['submit']))
{
if(!isset($_POST['name']) || $_POST['name'] === '')
$ok = false;
else
$name = $_POST['name'];
if(!isset($_POST['email']) || $_POST['email'] === '')
$ok = false;
else
$email = $_POST['email'];
if(!isset($_POST['category']) || $_POST['category'] === '')
$ok = false;
else
$category = $_POST['category'];
if(!isset($_POST['comment']) || $_POST['comment'] === '')
$ok = false;
else
$comment = $_POST['comment'];
if($ok)
{
$db = sql_connection('blog');
$result = insert_advice($db, $name, $email, $category, $comment);
if(!$result)
$insert_failure = true;
mysqli_close($db);
}
}
?>
<div class="container">
<?php
navbar_template();
?>
<h1>Contact Me</h1>
<p style="font-size:15px; color:#666">Tell me anything that intrigues you! We can talk about fascinating ideas, stories, places, etc. together! </p>
<!-- error message -->
<div class="col-lg-8 col-md-8 well <?php
// When the form is submitted and everything is ok or the form is unsubmitted
if((isset($_POST['submit']) && $ok) || !isset($_POST['submit']) || $insert_failure === true)
echo 'hidden';
?>">
<p>Oooooops...You don't wanna message me T^T?</p>
</div>
<!-- success message -->
<div class="col-lg-8 col-md-8 well <?php
// When the form is submitted and everything is ok or the form is unsubmitted
if(!(isset($_POST['submit']) && $ok))
echo 'hidden';
?>">
<p>Thanks for your comments! I'll reply to you ASAP. ^v^ </p>
</div>
<br/>
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
<form action="" method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control"
placeholder="e.g. Raymond Shi" <?php
printf("value=%s", $name);
?> >
</div>
<div class="form-group">
<label for="email">Eamil</label>
<input type="email" name="email" class="form-control"
placeholder="e.g. example@example.com" <?php
printf("value=%s", $email);
?> >
</div>
<div class="form-group">
<label for="category">Category</label>
<select class="form-control" name="category">
<option value="idea" <?php
if($category === 'idea')
echo 'selected';
?>>Idea</option>
<option value="food" <?php
if($category === 'food')
echo 'selected';
?>>Food</option>
<option value="place" <?php
if($category === 'place')
echo 'selected';
?>>Place & Landscape</option>
<option value="sport" <?php
if($category === 'sport')
echo 'selected';
?>>Sports</option>
<option value="other" <?php
if($category === 'other')
echo 'selected';
?>>Other</option>
</select>
</div>
<div class="form-group">
<label for="comment">Comments</label>
<!-- Store user's entered text value -->
<textarea name="comment" rows="5" class="form-control" draggable="false" placeholder="e.g. I love u~"><?php
echo htmlspecialchars($comment);
?></textarea>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="Sumbit" />
</form>
</div>
</div>
</body>
</html>