summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjesse <jesse@jesterpm.net>2011-05-19 17:14:05 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-05-19 17:14:05 -0700
commita1bbd6bfb8dd3812c70acdeff793cd9d78bdc219 (patch)
tree158bb2393a0be3459bb850530a1275f4ebc8fefc
parent2d74c1bc6394b68edfed3c75cca157b5ef938f54 (diff)
Got some processing started for the new post page.
-rw-r--r--htdocs/new-post.php91
1 files changed, 78 insertions, 13 deletions
diff --git a/htdocs/new-post.php b/htdocs/new-post.php
index e6f4035..7312e5f 100644
--- a/htdocs/new-post.php
+++ b/htdocs/new-post.php
@@ -14,24 +14,89 @@ require_once "src/header.inc.php";
echo "<h2>Submit Post</h2>";
-echo "<form action=\"submit-post.php\" method=\"post\">";
-echo "<p><label>Category: <select name=\"category\">";
-foreach (Category::getCategories() as $short => $name) {
- echo "<option name=\"$short\">$name</option>";
-}
-echo "</select></label</p>";
+// Process submission
+if (isset($_POST['category'])) {
+ $required = array(
+ 'title' => 'Title',
+ 'description' => 'Description',
+ 'category' => 'Category',
+ 'email' => 'Email Address',
+ 'email2' => 'Confirm Email Address',
+ );
+
+ $error = '';
+ $values = array();
+ foreach ($required as $field => $desc) {
+ if (!isset($_POST[$field]) or trim($_POST[$field]) == '') {
+ $error .= "<p>$desc is a required field.</p>";
+
+ } else {
+ $values[$field] = addslashes($_POST[$field]);
+ }
+ }
+
+ if ($values['email'] != $values['email2']) {
+ $error .= "<p>Email addresses must match.</p>";
+ }
+
+ if ($error == '') {
+ $post = new Post();
+
+ $post->setEmail($values['email']);
+ $post->setCategory($values['category']);
+ $post->setTitle($values['title']);
+ $post->setDescription($values['description']);
-echo "<p><label>Title: <input type=\"text\" name=\"title\" /></label></p>";
+ if ($post->save()) {
+ $post->sendValidation();
-echo "<p><label for=\"desc\">Description:</label></p>";
-echo "<p><textarea name=\"description\" id=\"desc\" rows=\"10\""
- . " cols=\"80\"></textarea></p>";
+ // TODO: Revise wording.
+ echo "<p>Your posting is awaiting email verification</p>";
-// TODO: Link to terms of service.
-echo "<p><label><input type=\"checkbox\" name=\"tos\" value=\"1\" /> I agree to the terms of service.</label></p>";
+ } else {
+ $error .= "An internal error has occured.";
+ }
-echo "<p><input type=\"submit\" value=\"Submit\" /></p></form>";
+ } else {
+ render_form($error);
+ }
+
+} else {
+ render_form();
+}
require_once "src/footer.inc.php";
+
+function render_form($error="") {
+ if ($error != '') {
+ echo "<div class=\"error\">$error</div>";
+ }
+
+ echo "<form action=\"new-post.php\" method=\"post\">";
+ echo "<p><label>Category: <select name=\"category\">";
+ foreach (Category::getCategories() as $short => $name) {
+ echo "<option name=\"$short\">$name</option>";
+ }
+ echo "</select></label</p>";
+
+ echo "<p><label>Title: <input type=\"text\" name=\"title\" /></label></p>";
+
+ echo "<p><label for=\"desc\">Description:</label></p>";
+ echo "<p><textarea name=\"description\" id=\"desc\" rows=\"10\""
+ . " cols=\"80\"></textarea></p>";
+
+ echo "<p><label>Email Address: <input type=\"text\" name=\"email\" />"
+ . "</label></p>";
+ echo "<p><label>Confirm Email: <input type=\"text\" name=\"email2\" />"
+ . "</label></p>";
+
+ // TODO: Link to terms of service.
+ echo "<p><label><input type=\"checkbox\" name=\"tos\" value=\"1\" />"
+ ." I agree to the terms of service.</label></p>";
+
+ echo "<p><input type=\"submit\" value=\"Submit\" /></p></form>";
+}
+
+
?>