Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Step 3: Adding a form to create a new post
Browse files Browse the repository at this point in the history
  • Loading branch information
colbyfayock committed Jan 15, 2024
1 parent 13c8486 commit cc125d2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/pages/posts/new.astro
@@ -1,6 +1,27 @@
---
import { ID } from 'appwrite';
import { databases } from '@/lib/appwrite';
import Layout from '@/layouts/Layout.astro';
import Container from '@/components/Container.astro';
if (Astro.request.method === "POST") {
const formData = await Astro.request.formData();
const data = {
title: String(formData.get('title')),
slug: String(formData.get('slug')),
content: String(formData.get('content')),
excerpt: String(formData.get('excerpt')),
}
const results = await databases.createDocument(
import.meta.env.PUBLIC_APPWRITE_DATABASE_ID,
import.meta.env.PUBLIC_APPWRITE_COLLECTION_ID,
ID.unique(),
data
);
return Astro.redirect(`/posts/${results.slug}`);
}
---
<Layout title="New Post - My Blog">
<Container>
Expand Down

0 comments on commit cc125d2

Please sign in to comment.