Эх сурвалжийг харах

[Refs #2] style on post page

isundil 9 жил өмнө
parent
commit
b177274e4a

+ 4 - 2
src/Poster.php

@@ -11,6 +11,9 @@ class Poster
 
     public function work()
     {
+        if (strlen($_POST["title"]) == 0 ||
+            strlen($_POST["descr"]) == 0)
+            return "Missing field";
         $this->data = Flammenkuchen::fromForm($_POST["title"], $_POST["descr"]);
         foreach ($_FILES as $f)
         {
@@ -21,8 +24,7 @@ class Poster
                 return $errorStr;
             //TODO check unicity using cache
             file_put_contents("../data/" .$this->getNextAvailableDay() .".json", $this->data->toJson());
-            die("done");
-            break;
+            return true;
         }
         return "Missing field";
     }

+ 24 - 4
src/templates/post.php

@@ -1,8 +1,28 @@
 <?php require ("header.php"); ?><title>Share a flamm</title><script src="/js/scripts_post.js"></script></head><body>
+<?php $disabled = "";
+if ($msg !== null)
+{
+    $disabled = $msg === true ? " disabled" : "";
+?><div class="alert"><?php echo $msg === true ? "Okay !" : $msg; ?></div><?php } ?>
 <form method="POST" action="/post" enctype="multipart/form-data">
-    <input type="text" name="title"/>
-    <input type="text" name="descr"/>
-    <input type="file" name="img" />
-    <input type="submit">
+    <div class="input-group">
+        <label>
+            <span>Titre</span>
+            <input type="text" name="title" <?php echo $disabled; ?>/>
+        </label>
+    </div>
+    <div class="input-group">
+        <label>
+            <span>Description</span>
+            <input type="text" name="descr" <?php echo $disabled; ?>/>
+        </label>
+    </div>
+    <div class="input-group">
+        <label>
+            <span>Fichier</span>
+            <input type="file" name="img" <?php echo $disabled; ?>/>
+        </label>
+    </div>
+    <input type="submit" <?php echo $disabled; ?>>
 </form>
 </body></html>

+ 3 - 0
www/css/style.css

@@ -22,6 +22,9 @@ img { max-width: 100%; }
 .section-content { margin: 0 20px 0 0; }
 .article-footer { text-align: center; }
 
+.alert { background: #EDD6CB; border: 1px solid #D3B3A5; margin: 0 0 30px 0; padding: 10px 25px; border-radius: 5px; }
+.input-group span { display: inline-block; width: 250px; }
+
 @media screen and (max-width: 1024px) {
     body { margin: 0 10px 50px 10px; text-align: center; }
     .section { display: block; width: 100%; margin: 15px 0; float: none; }

+ 5 - 6
www/index.php

@@ -7,18 +7,17 @@ $router = new Router();
 
 if ($router->isPostUri())
 {
-    if ($router->isGetRequest())
-        include ("../src/templates/post.php");
-    else
+    $msg = null;
+    if (!$router->isGetRequest())
     {
         $post = new Poster();
-        $error = $post->work();
-        if ($error === true)
+        $msg = $post->work();
+        if ($msg === true)
             header("http/1.0 201 Created");
         else
             header("http/1.0 500 error");
-        die ($error);
     }
+    include ("../src/templates/post.php");
 }
 else if ($router->isLost())
     include("../src/templates/lost.php");