Skip to content

fix: add Cloudflare Turnstile spam protection to contact form#201

Merged
ManukMinasyan merged 2 commits intomainfrom
fix/contact-form-spam
Mar 31, 2026
Merged

fix: add Cloudflare Turnstile spam protection to contact form#201
ManukMinasyan merged 2 commits intomainfrom
fix/contact-form-spam

Conversation

@ManukMinasyan
Copy link
Copy Markdown
Contributor

Summary

  • Integrate Cloudflare Turnstile (ryangjchandler/laravel-cloudflare-turnstile) to block bot spam on the contact form
  • Add Turnstile widget to the contact form and validation rule to ContactRequest
  • Add Turnstile script tag to guest layout and config to config/services.php
  • Keep existing honeypot as a first defense layer; Turnstile serves as the primary gate

Setup

After merging, create a Turnstile widget in the Cloudflare dashboard (Managed mode recommended) and add the keys to production .env:

TURNSTILE_SITE_KEY=...
TURNSTILE_SECRET_KEY=...

Test plan

  • 4 feature tests covering form display, successful submission, failed Turnstile, and missing token
  • PHPStan passes with no new errors
  • Pint code style passes

Copilot AI review requested due to automatic review settings March 30, 2026 10:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates Cloudflare Turnstile into the contact form flow to reduce bot spam while keeping the existing honeypot layer.

Changes:

  • Added Turnstile widget rendering to the contact form and validation to ContactRequest
  • Included Turnstile scripts in the guest layout and added related service/env configuration
  • Added feature tests covering success and failure cases for Turnstile validation

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Feature/ContactFormTest.php Adds feature tests for Turnstile-protected contact submissions
resources/views/layouts/guest.blade.php Loads Turnstile scripts via Blade component
resources/views/contact.blade.php Renders the Turnstile widget and shows validation errors
config/services.php Adds Turnstile keys to app configuration
composer.json Adds the Turnstile Laravel package dependency
app/Http/Requests/ContactRequest.php Enforces Turnstile validation on contact submissions
.env.example Documents required env vars for Turnstile configuration

@ManukMinasyan ManukMinasyan merged commit c42812b into main Mar 31, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants