You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/tutorial/02-sveltekit/04-forms/01-the-form-element/README.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
title: The <form> element
3
3
---
4
4
5
-
In the previous chapter, we saw how to get data from the server to the browser. Sometimes you need to send data in the opposite direction, and that's where `<form>`— the web platform's way of submitting data — comes in.
Let's build a todo app. We've already got an in-memory database set up in `src/lib/server/database.js`, and our `load` function in `src/routes/+page.server.js`uses the [`cookies`](https://kit.svelte.dev/docs/load#cookies-and-headers) API so that we can have a per-user todo list, but we need to add a `<form>`to create new todos:
7
+
todo アプリを作ってみましょう。すでに `src/lib/server/database.js` にセットアップ済みのインメモリデータベースがあり、`src/routes/+page.server.js`の `load` 関数で [`cookies`](https://kit.svelte.jp/docs/load#cookies-and-headers) API を使用しているためユーザーごとの todo リストを持つことができるようになっています。ここでは新しい todo を作成するための `<form>`を追加する必要があります。
8
8
9
9
```svelte
10
10
/// file: src/routes/+page.svelte
@@ -20,7 +20,7 @@ Let's build a todo app. We've already got an in-memory database set up in `src/l
20
20
{#each data.todos as todo}
21
21
```
22
22
23
-
If we type something into the `<input>`and hit Enter, the browser makes a POST request (because of the `method="POST"`attribute) to the current page. But that results in an error, because we haven't created a server-side _action_to handle the POST request. Let's do that now:
23
+
追加した `<input>`になにか入力して Enter を押すと、ブラウザは現在のページに対する POST リクエストを作成します (`method="POST"`属性があるため)。リクエストの結果がエラーになっているのは、その POST リクエストを処理するためのサーバーサイドの _action_が作成されていないからです。では、それをやってみましょう。
24
24
25
25
```js
26
26
/// file: src/routes/+page.server.js
@@ -38,6 +38,6 @@ export function load({ cookies }) {
38
38
};+++
39
39
```
40
40
41
-
When we hit Enter, the database is updated and the page reloads with the new data.
41
+
Enter を押すと、データベースが更新され、新しいデータでページがリロードします。
42
42
43
-
Notice that we haven't had to write any `fetch`code or anything like that — data updates automatically. And because we're using a `<form>`element, this app would work even if JavaScript was disabled or unavailable.
0 commit comments