Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Sveltekit - Form action - fail doesn't work

$
0
0

I try to implement a form action, but I have some trouble with error handling/validation (nameMissing and emailMissing values would be used for validation)

import { fail } from '@sveltejs/kit'export const actions = {  default: async ({ request }) => {    const form = await request.formData();    const name = form.get('name');    const email = form.get('email');    console.log(name);    console.log(email);    if(!name) {      return fail(400, {nameMissing: true })    }    if(!email) {      return fail(400, {emailMissing: true })    }    return { success: true }  },};

It seems to me, the fail import is not successful, because if I use a console.log in my if, it works.Thanks


Viewing all articles
Browse latest Browse all 1541

Trending Articles