-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
66 lines (57 loc) · 3.27 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
<?php
require('src/inc/pdo.php');
require('src/inc/functions.php');
session_start();
$errors = [];
$sent = false;
if (!empty($_POST['submit'])) {
$mail = checkXss($_POST['mail']);
$firstname = checkXss($_POST['firstname']);
$lastname = checkXss($_POST['lastname']);
$subject = checkXss($_POST['subject']);
$message = checkXss($_POST['message']);
$errors = checkEmail($errors, $mail, 'mail');
$errors = checkField($errors, $mail, 'mail', 6, 160);
$errors = checkField($errors, $firstname, 'firstname', 2, 100);
$errors = checkField($errors, $lastname, 'lastname', 2, 100);
$errors = checkField($errors, $subject, 'subject', 10, 250);
$errors = checkField($errors, $message, 'message', 10, 2000);
if (count($errors) == 0) {
insert($pdo, 'bn_contact', ['mail', 'firstname', 'lastname', 'subject', 'message', 'created_at'], [$mail, $firstname, $lastname, $subject, $message, now()]);
$sent = true;
}
}
$title = 'Contact - Bookination';
include('src/template/header.php');
?>
<section id="contact">
<div class="wrap-fluid">
<div class="contact-form">
<form action="" method="POST">
<div class="inputs-container">
<input type="mail" name="mail" placeholder="Votre mail" value="<?php if (!empty($_POST['mail'])) echo $_POST['mail'];
elseif (!empty($_SESSION['user']['mail'])) echo $_SESSION['user']['mail'];
elseif (!empty($_SESSION['visitor']['mail'])) echo $_SESSION['visitor']['mail'];
?>">
<input type="text" name="firstname" placeholder="Votre prénom" value="<?php if (!empty($_POST['firstname'])) echo $_POST['firstname'];
elseif (!empty($_SESSION['user']['firstname'])) echo $_SESSION['user']['firstname']; ?>">
</div>
<div class="inputs-container">
<input type="text" name="lastname" placeholder="Votre nom" value="<?php if (!empty($_POST['lastname'])) echo $_POST['lastname'];
elseif (!empty($_SESSION['user']['lastname'])) echo $_SESSION['user']['lastname']; ?>">
<input type="text" name="subject" placeholder="Votre motif" value="<?= (!empty($_POST['subject'])) ? $_POST['subject'] : '' ?>">
</div>
<textarea name="message" placeholder="Votre message"><?= (!empty($_POST['message'])) ? $_POST['message'] : '' ?></textarea>
<?php if ($sent == false) : ?>
<input type="submit" name="submit" class="btn btn-purple" value="Envoyer">
<?php else : ?>
<input type="submit" class="btn btn-success" value="Bien reçu !" disabled>
<?php endif; ?>
</form>
</div>
<div class="contact-image">
<img src="assets/img/contact_us.svg" alt="Image de contact">
</div>
</div>
</section>
<?php include('src/template/footer.php');