docs: Fix incorrect enctype info on Forms page (#2516)

Fixes #2515

This PR updates the Forms page in the docs with accurate information
about a form's `enctype` attribute.
This commit is contained in:
Jordan Tucker
2024-06-16 22:46:24 +00:00
committed by GitHub
parent 7caae01b17
commit 97ac05912c
+11 -9
View File
@@ -10,13 +10,14 @@ support for form submissions with the HTML `<form>` element.
In the browser, a `<form>` submit will send an HTML action (usually `GET` or In the browser, a `<form>` submit will send an HTML action (usually `GET` or
`POST`) to the server, which responds with a new page to render. `POST`) to the server, which responds with a new page to render.
## POST request with `multipart/form-data` ## POST request with `application/x-www-form-urlencoded`
Forms can either submit as a `GET` request with URL search parameter encoding, Forms typically submit as a `GET` request with data encoded in the URL's search
or as a `POST` request with `multipart/form-data`. parameters, or as a `POST` request with either an
`application/x-www-form-urlencoded` or `multipart/form-data` body.
This example demonstrates how to handle `multipart/form-data` `<form>` This example demonstrates how to handle `application/x-www-form-urlencoded`
submissions: `<form>` submissions:
```tsx routes/subscribe.tsx ```tsx routes/subscribe.tsx
import { Handlers } from "$fresh/server.ts"; import { Handlers } from "$fresh/server.ts";
@@ -53,14 +54,15 @@ export default function Subscribe() {
} }
``` ```
When the user submits the form, Deno will access a specific `email` value from a When the user submits the form, Deno will retrieve the `email` value using the
`formData()`, add the email to a list, and redirect the user to a thank you request's `formData()` method, add the email to a list, and redirect the user to
page. a thank you page.
## Handling file uploads ## Handling file uploads
File uploads can be handled in a very similar manner to the example above. Note File uploads can be handled in a very similar manner to the example above. Note
that this time, we have to explicitly declare the form's encoding. that this time, we have to explicitly declare the form's encoding to be
`multipart/form-data`.
```tsx routes/subscribe.tsx ```tsx routes/subscribe.tsx
import { Handlers, type PageProps } from "$fresh/server.ts"; import { Handlers, type PageProps } from "$fresh/server.ts";