|
|
@@ -65,7 +65,6 @@ $app->get('/', function (Request $request, Response $response, array $args) { |
|
|
|
|
|
|
|
$app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response $response, array $args) { |
|
|
|
if (isset($_SESSION['username'])) { |
|
|
|
global $db; |
|
|
|
if ($request->getMethod() == 'GET') { |
|
|
|
addNavbar($response); |
|
|
|
$response->getBody()->write('<form action="/blog/create" method="POST">'); |
|
|
@@ -73,10 +72,15 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response |
|
|
|
$response->getBody()->write('<input type="text" name="slug"/><br/>'); |
|
|
|
$response->getBody()->write('<label for="title">Titel:</label>'); |
|
|
|
$response->getBody()->write('<input type="text" name="title"/><br/>'); |
|
|
|
$response->getBody()->write('<label for="content">Content:</label>'); |
|
|
|
$response->getBody()->write('<textarea name="content" rows="4" columns="50"></textarea>'); |
|
|
|
$response->getBody()->write('<input type="submit"/>'); |
|
|
|
addFooter($response); |
|
|
|
} else { |
|
|
|
$data = $request->getParsedBody(); |
|
|
|
global $db; |
|
|
|
$insertQuery = "INSERT INTO blogs (slug, title, content) VALUES ('" . $data['slug'] . "', '" . $data['title'] . "', '" . $data['content'] ."')"; |
|
|
|
$db->exec($insertQuery); |
|
|
|
$_SESSION['blogs'][] = ["slug" => $data['slug'], "title" => $data['title'], "content" => "Lorem ipsum 4"]; |
|
|
|
return $response->withHeader('Location', '/')->withStatus(302); |
|
|
|
} |