added contact page

This commit is contained in:
Omer Sabic 2024-08-24 13:24:12 +02:00
parent f3bf7f6551
commit 5211188dbc
6 changed files with 79 additions and 1 deletions

View File

@ -15,10 +15,13 @@
>
<div class="flex flex-row items-center">
<a href="/" class="font-bold text-2xl">{data.blog.site.name}</a>
<div class="flex flex-row ml-8 font-bold">
<div class="flex flex-row ml-8 font-bold gap-4">
{#if data.blog.site.use_about_page}
<a href="/about">About</a>
{/if}
{#if data.blog.site.use_contact_page}
<a href="/contact">Contact</a>
{/if}
</div>
</div>
<div>

View File

@ -0,0 +1,47 @@
import { redirect } from "@sveltejs/kit";
import { get } from 'svelte/store';
import { site_id } from '../store';
import { env } from '$lib';
/** @type {import("@sveltejs/kit").Actions} */
export const actions = {
contact: async (event) => {
const data = await event.request.formData();
const subject = data.get("subject");
const email = data.get("email");
const message = data.get("message");
if (!subject || !email || !message) {
return {
success: false,
message: "missing data"
}
}
if (!email.toString().includes("@")) {
return {
success: false,
message: "invalid email"
}
}
let res = await fetch(env.api_url + "/blog/contact", {
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify({
subject,
email,
content: message,
blog_id: get(site_id)
})
});
console.log(await res.text());
return {
success: true
}
},
}

View File

@ -0,0 +1,28 @@
<div class="mt-44 mb-6 text-center w-full flex justify-center">
<form action="?/contact" method="post" class="flex flex-col gap-4 max-w-[400px] w-full">
<input
name="email"
id="email"
type="text"
placeholder="Email address"
class="py-3 px-5 flex-grow border border-solid border-gray-300 h-[50px] rounded-lg"
/>
<input
name="subject"
id="subject"
type="text"
placeholder="Subject"
class="py-3 px-5 flex-grow border border-solid border-gray-300 h-[50px] rounded-lg"
/>
<textarea
name="message"
id="message"
placeholder="Message"
class="py-3 px-5 flex-grow border border-solid border-gray-300 h-[200px] rounded-lg"
/>
<button
class="px-8 py-3 bg-gray-900 text-white font-semibold rounded-lg h-[50px]"
>Submit</button
>
</form>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB