-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex copy.php
91 lines (66 loc) · 1.94 KB
/
index copy.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
<?php
require_once "class/Message.php";
require_once "class/GestBook.php";
$errors =null;
$success =false;
if (isset($_POST['username'] , $_POST['message']) ){
$message= new Message($_POST['username'], $_POST['message']);
$gestbook= new GestBook(__DIR__.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'message');
if ($message->isValid()){
$gestbook->addMessage($message);
$success = true;
$_POST =[];
}else{
$errors = $message->geterrors();
}
$messages = $gestbook->getMessage();
}
$title="Home";
require "elements/header.php";
?>
<div class="container">
<h2>Gest Book </h2>
<?php if (!empty($errors)):?>
<div class="alert alert-danger">
Formulaire invalid
</div>
<?php endif?>
<?php if ($success):?>
<div class="alert alert-success">
Merci pour votre message
</div>
<?php endif?>
<form action="" method="POST">
<div class="form-group">
<label for=" username">Pseudo:</label><br>
<input type="text" id="username" name="username" value="<?= htmlentities( $_POST['username']??'')?>" class="form-control <?= isset($errors['username'])? 'is-invalid':''?>" />
<?php if(isset($errors['username'])):?>
<div class="invalid-feedback">
<?= $errors['username']?>
</div>
<?php endif ?>
</div>
<div class="form-group">
<label for="message">Message:</label><br>
<textarea rows="4 id="message" name="message" class="form-control <?= isset($errors['message'])? 'is-invalid':''?>"><?= htmlentities($_POST['message']??'')?></textarea>
<?php if(isset($errors['message'])):?>
<div class="invalid-feedback">
<?= $errors['message']?>
</div>
<?php endif ?>
</div>
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
<h2>Messages abdou </h2>
<hr>
<?php
if(isset($message)){
foreach($messages as $message):
echo($message->toHtml());
endforeach;
}
?>
</div>
<?php
require "elements/footer.php";
?>