Tell me why?
This commit is contained in:
@@ -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, {
|
||||||
|
|||||||
@@ -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' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user