28 lines
857 B
Plaintext
28 lines
857 B
Plaintext
import { CreateUserSchema } from "../schemas/create-user";
|
|
|
|
page ServerActions {
|
|
seo {
|
|
title = "Typed server actions"
|
|
description = "Schema validation, CSRF, invalidation and progressive enhancement"
|
|
}
|
|
|
|
action createUser using CreateUserSchema {
|
|
invalidate("users")
|
|
return { id: crypto.randomUUID(), name: input.name, email: input.email }
|
|
}
|
|
|
|
view {
|
|
<main>
|
|
<h1>Typed server actions</h1>
|
|
<p>The form works with or without JavaScript.</p>
|
|
<form @submit="createUser">
|
|
<label for="action-name">Name</label>
|
|
<input id="action-name" name="name" autocomplete="name" required />
|
|
<label for="action-email">Email</label>
|
|
<input id="action-email" name="email" type="email" autocomplete="email" required />
|
|
<button type="submit">Create user</button>
|
|
</form>
|
|
</main>
|
|
}
|
|
}
|