This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_post.php
105 lines (72 loc) · 2.39 KB
/
create_post.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
102
103
104
105
<?php
require_once dirname(__FILE__) . './database/dboperation.php';
require_once dirname(__FILE__) . './database/dbconnect.php';
require dirname(__FILE__) . './header.php';
require_once dirname(__FILE__) . './inc/utils.php';
$db = new dboperation();
$blogTable = "user_post";
$result = $db->getAll($blogTable);
$posts = json_decode($result, true);
$totalPost = sizeof($posts);
// utils::toastClientSide();
if ($totalPost == 0) {
utils::alertMessage("No Any Posts...", "warning");
}
// utils::checkUserLogin();
// $_SESSION['message'] = 'hello';
utils::toastMessage();
// utils::message();
?>
<div class="container mt-4">
<div class="row">
<div class="col-md-10">
<form class="form " action="./database/add_blog_post.php" method="POST">
<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id'] ?>"/>
<div class="form-group">
<textarea rows="5" class="form-control" style="resize:none;" name="post" placeholder="write post here..." required></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg ">Post</button>
</div>
</form>
</div>
</div>
<?php
foreach($posts as $post) {
echo '<div class="row blog-post col">';
echo "<a href='#'>";
$user = $db->getSingleData('user', $post['user_id']);
$user = json_decode($user, true);
// echo '<h5>'. $user['firstName'] . ' ' . $user['lastName'] . '</h5>';
echo '<h5>'. $user['username']. '</h5>';
echo "<p>" .$post['post'] . "</p>";
echo "<span id='date'><small>" . $post['datetime'] . "</small></span>";
echo "</a>";
echo '</div>';
}
?>
</div>
<style>
</style>
<script>
//for form validation
(function () {
'use strict';
window.addEventListener('load', function () {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
//validate all forms
// var forms = document.getElementsByTagName('form');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>