Concept Flow - Form validation patterns
User fills form
User submits form
Run validation checks
Process valid data
The user fills and submits a form, triggering validation. If valid, data is processed; if not, errors show.
export async function action({ request }) { const formData = await request.formData(); const email = formData.get('email'); if (!email || !email.includes('@')) { return { error: 'Invalid email' }; } return { success: true }; }
| Step | Action | Input Value | Validation Check | Result | Next Step |
|---|---|---|---|---|---|
| 1 | Receive form data | { email: 'user@example.com' } | N/A | Data received | Check email validity |
| 2 | Check if email exists | 'user@example.com' | email present? | Yes | Check email format |
| 3 | Check email format | 'user@example.com' | contains '@'? | Yes | Return success |
| 4 | Return response | N/A | N/A | { success: true } | End |
| 5 | Receive form data | { email: 'userexample.com' } | N/A | Data received | Check email validity |
| 6 | Check if email exists | 'userexample.com' | email present? | Yes | Check email format |
| 7 | Check email format | 'userexample.com' | contains '@'? | No | Return error |
| 8 | Return response | N/A | N/A | { error: 'Invalid email' } | End |
| 9 | Receive form data | { email: '' } | N/A | Data received | Check email validity |
| 10 | Check if email exists | '' | email present? | No | Return error |
| 11 | Return response | N/A | N/A | { error: 'Invalid email' } | End |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| formData | undefined | { email: 'user@example.com' } | { email: 'user@example.com' } | { email: 'user@example.com' } | N/A |
| undefined | 'user@example.com' | 'user@example.com' | 'user@example.com' | N/A | |
| validationResult | undefined | undefined | undefined | success | N/A |
Form validation in Remix: - User submits form data - Server action reads formData - Validate fields (e.g., email presence and format) - Return error object if invalid - Return success if valid - Show errors or proceed accordingly