Lesson 3 of 4 · 12 min read
Secure forms: validation and CSRF
Every form needs three defences:
- Validate on the server — check type, length and allowed values (
filter_var($email, FILTER_VALIDATE_EMAIL)). - CSRF token — a random secret in a hidden field, checked with
hash_equals(), so other sites can’t submit forms as your users. - Rate limiting + honeypot — a hidden field bots fill and humans don’t, plus a cap on submissions per IP.
Browser-side validation is only for convenience — attackers skip the browser entirely.
⚡ Quick check
Is JavaScript validation enough to secure a form?
Attackers can send requests directly to your server, bypassing the browser.