prg-pattern
/prg-pattern
ACTIVATE when implementing form handling, POST endpoints, or any controller that modifies data. ACTIVATE for 'form submission', 'POST redirect', 'PRG', 'duplicate submission'. Covers: POST success always redirects, POST error re-renders (no redirect), flash messages after redirect. DO NOT use for: FormType design (see symfony:symfony-form), API endpoints returning JSON.
- Author
- fabiensalles ↗
- Repository
- claude-marketplace ↗
- Licence
- MIT
- Last repository change
- 12.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 12.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
ACTIVATE when implementing form handling, POST endpoints, or any controller that modifies data. ACTIVATE for 'form submission', 'POST redirect', 'PRG', 'duplicate submission'. Covers: POST success always redirects, POST error re-renders (no redirect), flash messages after redirect. DO NOT use for: FormType design (see symfony:symfony-form), API endpoints returning JSON.
Triggers from the description
Original author description
ACTIVATE when implementing form handling, POST endpoints, or any controller that modifies data. ACTIVATE for 'form submission', 'POST redirect', 'PRG', 'duplicate submission'. Covers: POST success always redirects, POST error re-renders (no redirect), flash messages after redirect. DO NOT use for: FormType design (see symfony:symfony-form), API endpoints returning JSON.
How it works
- The Solution
- Implementation Rules
- Complete Example
- Quick Reference
- Anti-Patterns
SKILL.md preview
---
name: prg-pattern
description: "ACTIVATE when implementing form handling, POST endpoints, or any controller that modifies data. ACTIVATE for 'form submission', 'POST redirect', 'PRG', 'duplicate submission'. Covers: POST success always redirects, POST error re-renders (no redirect), flash messages after redirect. DO NOT use for: FormType design (see symfony:symfony-form), API endpoints returning JSON."
---
# Post/Redirect/Get (PRG) Pattern
POST success -> redirect. POST error -> re-render with errors. This prevents duplicate submissions on page refresh.
## The Solution
```
┌─────────────────────────────────────────────────────────────┐
│ PRG FLOW │
├─────────────────────────────────────────────────────────────┤
│ │
│ GET /form ──────────► Display Form │
│ ▲ │ │
│ │ ▼ │
│ │ User fills & submits │
│ │ │ │
│ │ ▼ │
│ ┌────┴────┐ POST /form │
│ │ Refresh │ │ │
│ │ safe! │ ▼ │
│ └────┬────┘ ┌──────────┴──────────┐ │
│ │ │ │ │
│ │ Validation OK? Validation KO │
│ │ │ │ │
│ │ ▼ ▼ │
│ │ 302 REDIRECT Re-render form │
│ │ │ with errors │
│ │ ▼ │
│ └──── GET /success │
│ │
└─────────────────────────────────────────────────────────────┘
```
## Implementation Rules
### 1. POST Success → Always Redirect
```php
if ($request->isMethod('POST')) {
$selection = $request->request->getString('choice');
if ($this->isValid($selection)) {
// ✅ Success: REDIRECT (never return HTML)
return new RedirectResponse(
$this->urlGenerator->generate('next_step')
);
}
// ❌ Error: Re-render form (no redirect)
return $this->render(..., hasError: true);
}
```
### 2. POST Error → Re-render (No Redirect)
When validation fails, **re-render the form** with error messages. This is NOT a violation of PRG because:
- User needs to see their input + errors
- Refreshing will re-submit, but that's intentional (user correcting data)
- Redirecting would lose the submitted data
### 3. Flash Messages for User Feedback
When redirecting after success, use flash messages:
```php
// In controller
$this->session->getFlashBag()->add('success', 'Operation completed');
return new RedirectResponse(...);
// In template
{% for message in app.flashes('success') %}
<div class="alert alert-success">{{ message }}</div>
{% endfor %}
```
## Complete Example
```php
#[Route(path: '/form', name: 'my_form', methods: ['GET', 'POST'])]
public function __invoke(Request $request): Response
{
if ($request->isMethod('POST')) {
$data = $request->request->all();
if (!$this->validate($data)) {
// Error: re-render with data
return $this->render($data, hasError: true);
}
// Success: process and redirect
$this->process($data);
return new RedirectResponse(
$this->urlGenerator->generate('success_page')
);
}
// GET: display empty form
return $this->render();
}
```
## Quick Reference
| Scenario | Response | Why |
|----------|----------|-----|
| GET request | Render form | Display form |
| POST + valid | **RedirectResponse** | PRG: prevent re-submit |
| POST + invalid | Render with errors | Show validation errors |
| POST + exception | Render with error | Show error message |
## Anti-Patterns
```php
// ❌ WRONG: Returning HTML after successful POST
if ($valid) {
$this->save($data);
return new Response('Success!'); // Refresh will re-submit!
}
// ❌ WRONG: Redirecting on error (loses user input)
if (!$valid) {
return new RedirectResponse('/form?error=1');
}
// ✅ CORRECT
if ($valid) {
$this->save($data);
return new RedirectResponse('/success');
}
return $this->renderWithErrors($data);
```
Versions
The database has no other skills named prg-pattern.
Database snapshot: 13.11.2026 · package version 3d5f307af160 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100symfony-form
ACTIVATE when working with Symfony FormTypes, form handling, data_class, DataTransformers, form options, or property_path. ACTIVATE when creating or modifying any FormType class. Covers: data_class as single source of truth (no data in options), DataTransformer placement (not… - 100symfony-test-conventions
ACTIVATE when writing or modifying a test that boots Symfony — WebTestCase, KernelTestCase, TypeTestCase, functional/interface tests, FormType tests, or container service doubles. ACTIVATE for 'crawler', 'assertSelectorTextContains', 'assertResponseRedirects',… - 95react-form-validator
This skill should be used when the user asks to "create a form", "add validation", "handle form submission", "use React Hook Form", or when creating login, signup, or data entry forms. Enforces React Hook Form + Zod pattern. - 100oauth-pkce-sessionstorage-lost-on-redirect
Fix OAuth PKCE "Session not found" or "No code verifier" errors in SPAs after redirect from external auth server. Use when: (1) OAuth callback fails with session/verifier not found despite flow starting correctly, (2) PKCE code_verifier stored in sessionStorage is missing after… - 100redirect-301-generator
301 Redirect Generator. Use when working with source-to-destination mapping and deployment platform. - 100rest-controller-conventions
Use when writing hand-rolled REST controllers in Symfony (without API Platform) — routing attributes, HTTP status codes, request payload mapping, serialization groups, pagination, and versioning. Use when generating controllers, JSON endpoints, or resource routes.