← Back to excelora.in Free courses by the Excelora team · Learn by doing
Hire Excelora

Lesson 3 of 4 · 12 min read

Secure forms: validation and CSRF

Every form needs three defences:

  1. Validate on the server — check type, length and allowed values (filter_var($email, FILTER_VALIDATE_EMAIL)).
  2. CSRF token — a random secret in a hidden field, checked with hash_equals(), so other sites can’t submit forms as your users.
  3. 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?