-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact.php
87 lines (73 loc) · 3.11 KB
/
contact.php
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
<?php
$page = "contact.php";
session_start();
if (!isset($_SESSION['loggedIn']) || $_SESSION['loggedIn'] != true) {
header("location: login.php", true);
exit();
}
$uId = $_SESSION['userId'];
require('./partials/header.php');
require "config.php";
?>
<?php
if (isset($_GET['submitted'])) {
?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Message Sent Successfully</strong>
We'll contact you back soon.
<a type="button" href="diary.php" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></a>
</div>
<?php
}
?>
<?php
if (isset($_GET['failed'])) {
?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Please Enter meaningful message.</strong>
<a type="button" href="diary.php" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></a>
</div>
<?php
}
?>
<section id="updateForm" class="my-5">
<div class="container">
<div class="row">
<form class="form-floating mb-3" action="" method="POST">
<div class=" form-floating mb-3">
<input type="email" class="form-control" name="email" id="floatingInput" spellcheck="false" required>
<label for="floatingInput">Email</label>
</div>
<div class=" form-floating mb-3">
<input type="text" class="form-control" name="subject" id="floatingInput" spellcheck="false" required>
<label for="floatingInput">Subject</label>
</div>
<div class="form-floating mb-3">
<textarea class="form-control" spellcheck="false" required name="message" placeholder="Write Your Message here...." id="floatingTextarea2" style="height: 200px"></textarea>
<label for="floatingTextarea2">Message</label>
</div>
<button type="reset" class="btn btn-danger">Reset</button>
<button type="submit" name="contactSubmit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</section>
<?php
if (isset($_POST['contactSubmit'])) {
$email = $_POST['email'];
$subject = mysqli_real_escape_string($conn, (isset($_POST['subject']) ? $_POST['subject'] : ""));
$message = mysqli_real_escape_string($conn, (isset($_POST['message']) ? $_POST['message'] : ""));
$status = "unread";
if(strlen($subject) < 10 && strlen($message) < 10){
echo "<script>window.location.assign('contact.php?failed');</script>";
}
$insertQuery = "INSERT INTO contact_form (`user_id`, `subject`, `email`, `message`, `status`) VALUES ('$uId', '$subject', '$email', '$message', '$status')";
$fireQuery = mysqli_query($conn, $insertQuery);
if ($fireQuery > 0) {
echo "<script>window.location.assign('contact.php?submitted');</script>";
} else {
echo "There is an error : " . mysqli_error($conn);
}
}
include "./partials/footer.php";
?>