FormData
When building web applications, it’s common to accept data from users through the use of forms. Accessing this data can be done via the FormData API. To see this in action, let’s look at a basic form that allows users to post a comment to our application. In this example, we’ll create two files, +page.svelte
and +page.server.js
, under the new comment route. As before, the +page.svelte
file contains HTML to scaffold our form and minimal styles. In order to get access to the data sent from our server, we must include the line reading export let form;
in our client-side <script>
code. This lets us view the status of the object returned from +page.server.js
and report the status back to the user by using the templating system provided by Svelte:
src/routes/comment/+page.svelte
<script> export let form; </script> <div class='wrap'> {#if form && form.status === true} &...