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

SvelteKit Form Action not returning success / remains null

$
0
0

I have the following setup in my +page.server.js:

export const actions = {    createScore: async ({ request }) => {        const values = await request.formData();        try {            const instagram = values.get('username');            const score = Number(values.get('score'));            await prisma.score.create({                data: {                    score,                    instagram                }            });            return { success: true };        } catch (err) {            console.error(err);            return fail(500, { message: 'Could not create the score.' });        }    }};

This runs fine, I see the entry in the database. However, no matter how hard I try, I cannot access 'form' to check for the return of sucess in my front end.

I do the following in page.svelte

<script>    export let form;    console.log(form);</script>

The console log consistently returns null when the form is run.

Further, the following never renders (telling me I am not missing a state change):

{#if form?.success}<p>It Worked</p>{/if}

Finally, form as follows:

<form action="?/createScore" method="POST"><input type="text" id="score" name="score" /><input type="text" id="username" name="username" /><button type="submit">Submit</button></form>

Am I missing something?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>