/
new_post.php
129 lines (106 loc) · 3.13 KB
/
new_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
include_once('php/config.php');
define("PAGENAME","Create New");
include_once('include/header.php');
$user = new USER($conn);
if(!$user->loggedin())
{
$user->redirect('login');
}
$userID = $_SESSION['user_session'];
$stmt = $conn->prepare("SELECT * FROM user WHERE userID=:userID");
$stmt->execute(array(":userID"=>$userID));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if(isset($_POST['send_post']))
{
$title = trim($_POST['title']);
$subtitle = trim($_POST['subtitle']);
$preview = trim($_POST['preview']);
$main_text = trim($_POST['main_text']);
//improving quality of the code, adding empty method to check for empty variables
if(empty($title)){
$error[] = "Oh no! You need a title for your post!";
}
else if(empty($subtitle)){
$error[] = "Oh no! You need a subtitle for your post!";
}
else if(empty($preview)){
$error[] = "Oh no! What's your extract?";
}
else if(empty($main_text)){
$error[] = "Oh no! C'mon, you need to write your post! This is a blog, afterall!";
}
else {
//$user->notEmtpy($title, $subtitle, $preview, $main_text);
if($user->insertBlog($userID, $title, $subtitle, $preview, $main_text))
{
$user->redirect('my_posts');
}
}
}
?>
<main>
<div class="feat create">
<h1 class="dashboard">Create a new post</h1>
<?php
//loops through the errors
if(isset($error))
{
foreach ($error as $value) { ?>
<div class="alert" >
<?php echo $value; ?>
</div>
<?php
}
}
?>
<div class="dashboard">
<h2>This will be posted to Bloggie. So, just follow our structure and you'll be awesome!</h2>
<h3>There are four sections to this. Title, subtitle, preview and main text. We employ a simple WYSIWYG editor.</h3>
</div>
</div>
<form method="POST" id="new_post" class="auto inputs create">
<div class="margins create">
<div class="explain">
<label for="heading">Title:</label>
</div>
<div>
<small>Your title should contain the essence of your topic</small>
<input type="text" id="heading" maxlength="50" name="title">
</div>
</div>
<div class="margins create">
<div class="explain">
<label for="subtitle">Subitle:</label>
</div>
<div>
<small>This is a the question you're answering in your post</small>
<input type="text" id="subtitle" name="subtitle">
</div>
</div>
<div class="margins create">
<div class="explain">
<label for="preview">Summary:</label>
</div>
<div>
<small>Make sure that most important information is on top of the page, it's valuable and consice</small>
<textarea name="preview" id="preview"></textarea>
</div>
</div>
<div class="margins create">
<div class="explain">
<label for="main_text">Main Text:</label>
</div>
<div>
<small>Make sure that most important information is on top of the page, it's valuable and consice</small>
<!-- .simple-editor calls for Trumbowyg to do it's magic -->
<textarea name="main_text" id="main_text" class="simple-editor"></textarea>
</div>
</div>
<input type="submit" name="send_post" class="feat create">
</form>
</main>
<?php
include_once('include/extra.php');
include_once('include/footer.php');
?>