Tell me why?

This commit is contained in:
2022-12-25 14:01:00 +01:00
parent 869debe87e
commit 899edf8234
2 changed files with 5 additions and 2 deletions

View File

@@ -36,6 +36,7 @@
async function handleForm (event: SubmitEvent) { async function handleForm (event: SubmitEvent) {
const data = new FormData(this) const data = new FormData(this)
const email = data.get('email') const email = data.get('email')
console.log('form:', data, email)
if (email) { if (email) {
const req = await fetch(this.action, { const req = await fetch(this.action, {

View File

@@ -3,14 +3,16 @@ import type { RequestHandler } from './$types'
import { error } from '@sveltejs/kit' import { error } from '@sveltejs/kit'
export const POST = (async ({ request }) => { export const POST = (async ({ request }) => {
const { email } = await request.json() const data = await request.json()
const { email } = data
console.log('server:', data, email)
// No email // No email
if (!email) { if (!email) {
throw error(400, { message: 'NO_EMAIL' }) throw error(400, { message: 'NO_EMAIL' })
} }
// Invalid email // Invalid email
else if (!email || !email.match(/^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/)) { if (!email.match(/^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/)) {
throw error(400, { message: 'INVALID_EMAIL' }) throw error(400, { message: 'INVALID_EMAIL' })
} }