-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_formulaire.php
107 lines (72 loc) · 2.49 KB
/
validation_formulaire.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php require 'header.php';
$Activity = $_POST['activity'];?>
<?php
function verifier($variable){
$variable = htmlspecialchars($variable);
$variable = trim($variable);
return $variable;
}
if(array_key_exists('project_web', $_POST)){
$Projects[] = $_POST['project_web'];
}
if(array_key_exists('project_print', $_POST)){
$Projects[] = $_POST['project_print'];
}
if(array_key_exists('project_digital', $_POST)){
$Projects[] = $_POST['project_digital'];
}
if(array_key_exists('project_video', $_POST)){
$Projects[] = $_POST['project_video'];
}
if(array_key_exists('project_stand', $_POST)){
$Projects[] = $_POST['project_stand'];
}
if(array_key_exists('divers', $_POST)){
$Projects[] = $_POST['divers'];
}
if(empty($Projects)){
header('Location: index-contact.php');
}
if(isset($_POST['full_name']) && $_POST['full_name'] != ''){
$userName = $_POST['full_name'];
$userName = verifier($userName);
}else{
$errors['full_name'] = 'vous devez renseigner un mail valide';
}
if(isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$userMail = $_POST['email'];
$userMail = verifier($userMail);
}else{
$errors['email'] = 'Vous devez renseigner un mail valide';
}
if(isset($_POST['phone']) && preg_match($code_syntaxe, $_POST['phone'])){
$userPhone = $_POST['phone'];
$userPhone = verifier($userPhone);
}else{
$errors['phone'] = 'Vous devez renseigner un numéro valide';
}
if(isset($_POST['message']) && $_POST['message'] != ''){
$userMessage = $_POST['message'];
$userMessage = verifier($userMessage);
}else{
$errors['message'] = 'Vous devez renseigner un message';
}
if(!empty($errors)){
session_start();
$_SESSION['errors'] = $errors;
header('Location: index-contact.php');
}else{
session_start();
$headerMessage = 'Demande de contact site Djack';
$body = "";
$body .= "From: " .$userName. "\r\n";
$body .= "Type d'activité : " .$Activity. "\r\n";
$body .= "Email : " .$userMail. "\r\n";
$body .= "Téléphone : " .$userPhone. "\r\n";
$body .= "Projet.(s) : " .implode('-', $Projects). "\r\n";
$body .= "Message : " .$userMessage. "\r\n";
mail('geoffroy-charley@hotmail.fr',$headerMessage, $body);
$succes = 'Votre demande a bien été enregistré';
$_SESSION['succes'] = $succes;
header('Location:http://index-contact.php');
}