-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_blog_post.php
More file actions
52 lines (45 loc) · 1.45 KB
/
Copy pathcreate_blog_post.php
File metadata and controls
52 lines (45 loc) · 1.45 KB
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
<?php
include 'init.php';
// check to make sure only logged in users can create posts
if (!logged_in()){
header('Location: index.php');
exit;
}
if (isset ($_POST['post_title'], $_POST['post_content'])){
$cat_id = 0;
$post_title = $_POST['post_title'];
$post_content = $_POST['post_content'];
$errors = array();
if (empty ($post_title) || empty ($post_content)){
$errors[] = 'Post title and content required';
} else{
if (strlen($post_title) > 255){
$errors[] = 'Titles can be 255 characters or less';
}
}
if(!empty($errors)){
foreach ($errors as $error){
echo $error, '<br />';
}
} else {
create_blog_post($cat_id, $post_title, $post_content);
header('Location: blog.php?user_id='.$_SESSION['user_id']);
}
}
include 'template/header.php';
?>
<section id="main_section">
<article class="transparent">
<h2>Post A New Blog</h2>
<form action="" method="post">
<p>Title: <br/><textarea id="blog_title" name="post_title" rows="2" cols="75" maxlength="255"/></textarea></p>
<div id="blog_title_feedback" align="right"></div>
<p>Content: <br/><textarea name="post_content" rows="20" cols="75"></textarea></p>
<p><input type="submit" value="Post"/></p>
</form>
</article>
</section>
<?php include 'widgets/blog_options.php' ?>
<?php
include 'template/footer.php';
?>