1
|
|
|
<div class="todo_container"> |
2
|
|
|
|
3
|
|
|
<h2>TODO Application</h2> |
4
|
|
|
|
5
|
|
|
<!-- in case of normal post request --> |
6
|
|
|
<form action= "<?= PUBLIC_ROOT . "Todo/create" ?>" method="post"> |
7
|
|
|
<label>Content <span class="text-danger">*</span></label> |
8
|
|
|
<textarea name="content" class="form-control" required placeholder="What are you thinking?"></textarea> |
9
|
|
|
<input type='hidden' name = "csrf_token" value = "<?= Session::generateCsrfToken(); ?>"> |
10
|
|
|
<button type="submit" name="submit" value="submit" class="btn btn-success">Create</button> |
11
|
|
|
</form> |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
<!-- in case of ajax request |
15
|
|
|
<form action= "#" id="form-create-todo" method="post"> |
16
|
|
|
<label>Content <span class="text-danger">*</span></label> |
17
|
|
|
<textarea name="content" class="form-control" required placeholder="What are you thinking?"></textarea> |
18
|
|
|
<button type="submit" name="submit" value="submit" class="btn btn-success">Create</button> |
19
|
|
|
</form> |
20
|
|
|
--> |
21
|
|
|
|
22
|
|
|
<br> |
23
|
|
|
<?php |
24
|
|
|
|
25
|
|
|
// display success or error messages in session |
26
|
|
View Code Duplication |
if(!empty(Session::get('success'))){ |
|
|
|
|
27
|
|
|
echo $this->renderSuccess(Session::getAndDestroy('success')); |
28
|
|
|
}else if(!empty(Session::get('errors'))){ |
29
|
|
|
echo $this->renderErrors(Session::getAndDestroy('errors')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
?> |
33
|
|
|
|
34
|
|
|
<br><hr><br> |
35
|
|
|
|
36
|
|
|
<ul id="todo-list"> |
37
|
|
|
<?php |
38
|
|
|
$todoData = $this->controller->todo->getAll(); |
39
|
|
|
foreach($todoData as $todo){ |
40
|
|
|
?> |
41
|
|
|
<li> |
42
|
|
|
<p> <?= $this->autoLinks($this->encodeHTMLWithBR($todo["content"])); ?></p> |
43
|
|
|
|
44
|
|
|
<!-- in case of normal post request --> |
45
|
|
|
<form action= "<?= PUBLIC_ROOT . "Todo/delete" ?>" method="post"> |
46
|
|
|
<input type='hidden' name= "todo_id" value="<?= "todo-" . Encryption::encryptId($todo["id"]);?>"> |
47
|
|
|
<input type='hidden' name = "csrf_token" value = "<?= Session::generateCsrfToken(); ?>"> |
48
|
|
|
<button type="submit" name="submit" value="submit" class="btn btn-xs btn-danger">Delete</button> |
49
|
|
|
</form> |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
<!-- in case of ajax request |
53
|
|
|
<form class="form-delete-todo" action= "#" method="post"> |
54
|
|
|
<input type='hidden' name= "todo_id" value="<?= "todo-" . Encryption::encryptId($todo["id"]);?>"> |
55
|
|
|
<button type="submit" name="submit" value="submit" class="btn btn-xs btn-danger">Delete</button> |
56
|
|
|
</form> |
57
|
|
|
--> |
58
|
|
|
</li> |
59
|
|
|
<?php } ?> |
60
|
|
|
</ul> |
61
|
|
|
|
62
|
|
|
</div> |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.