Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Steps component to build-forms.mdx #8124

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/content/docs/en/recipes/build-forms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ description: Learn how to build HTML forms and handle submissions in your frontm
i18nReady: true
type: recipe
---
import { Steps } from '@astrojs/starlight/components';

In SSR mode, Astro pages can both display and handle forms. In this recipe, you'll use a standard HTML form to submit data to the server. Your frontmatter script will handle the data on the server, sending no JavaScript to the client.


## Prerequisites
- A project with [SSR](/en/guides/server-side-rendering/) (`output: 'server'`) enabled

## Recipe

<Steps>
1. Create or identify a `.astro` page which will contain your form and your handling code. For example, you could add a registration page:

```astro title="src/pages/register.astro"
Expand Down Expand Up @@ -139,7 +140,7 @@ In SSR mode, Astro pages can both display and handle forms. In this recipe, you'
</form>
```

5. Validate the form data on the server. This should include the same validation done on the client to prevent malicious submissions to your endpoint and to support the rare legacy browser that doesn't have form validation.
6. Validate the form data on the server. This should include the same validation done on the client to prevent malicious submissions to your endpoint and to support the rare legacy browser that doesn't have form validation.

It can also include validation that can't be done on the client. For example, this example checks if the email is already in the database.

Expand Down Expand Up @@ -201,5 +202,4 @@ In SSR mode, Astro pages can both display and handle forms. In this recipe, you'
</form>
```


</Steps>
Loading