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?
form
that triggers the action. – Slipsheet$: console.log(form);
– Slipsheet+page.svelte
, correct? Also, would recommend using theenhance
action to not fully reload the page on submit. – Slipsheetenhance
) and report that in the respective repository. Forms should still work as intended when no JS is running on the client. – Slipsheetn-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles. The "/[lang]" and "/[lang]/(app)" routes conflict with each other
and along other problemts. – Ululate