Skip to content

Commit 3dcfa74

Browse files
thejmitchenerdependabot[bot]
authored andcommitted
Add Cloudflare Turnstile CAPTCHA support for spam protection with configuration, validation, and UI integration; enhance form inputs to retain old values; include middleware to handle fbclid query parameter; update dependencies and documentation accordingly. #major (#41)
* Add Cloudflare Turnstile CAPTCHA support for spam protection with configuration, validation, and UI integration; enhance form inputs to retain old values; include middleware to handle fbclid query parameter; update dependencies and documentation accordingly. * Move 'spam_redirects' configuration to a higher position in the forms config for better organization. * #major * Update environment variable defaults in README and expand package version compatibility in composer.json to support multiple versions of laravel-cloudflare-turnstile. * Bump actions/checkout from 4 to 5 (#37) Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Joshua Mitchener <[email protected]> * Add support for fbclid parameter in form data handling and validation to track Facebook click identifiers. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 84372f1 commit 3dcfa74

File tree

16 files changed

+165
-9
lines changed

16 files changed

+165
-9
lines changed

.github/workflows/auto-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
application_id: ${{ vars.FUELVIEWS_BOT_APP_ID }}
2626
application_private_key: ${{ secrets.FUELVIEWS_BOT_APP_PRIVATE_KEY }}
2727

28-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@v5
2929
with:
3030
ref: 'main'
3131
fetch-depth: '0'

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
token: ${{ secrets.GITHUB_TOKEN }}
2626

2727
- name: Checkout the code
28-
uses: actions/checkout@v4
28+
uses: actions/checkout@v5
2929

3030
- name: Dependabot metadata
3131
id: metadata

.github/workflows/php-cs-fixer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
steps:
1717
- name: Checkout code
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v5
1919
with:
2020
ref: ${{ github.head_ref }}
2121

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
steps:
3636
- name: Checkout code
37-
uses: actions/checkout@v4
37+
uses: actions/checkout@v5
3838

3939
- name: Setup PHP
4040
uses: shivammathur/setup-php@v2

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to `laravel-forms` will be documented in this file.
44

5+
## v1.0.0 - 2025-09-27
6+
7+
### What's Changed
8+
9+
* Add Cloudflare Turnstile CAPTCHA support for spam protection with configuration, validation, and UI integration; enhance form inputs to retain old values; include middleware to handle fbclid query parameter; update dependencies and documentation accordingly. #major by @thejmitchener in https://github.com/fuelviews/laravel-forms/pull/41
10+
11+
**Full Changelog**: https://github.com/fuelviews/laravel-forms/compare/v0.0.25...v1.0.0
12+
513
## v0.0.25 - 2025-09-27
614

715
### What's Changed

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Laravel forms package
22

3-
Laravel forms package
3+
Laravel forms package with built-in spam protection and optional Cloudflare Turnstile support.
44

55
## Installation
66

@@ -28,6 +28,38 @@ You can publish the view files with:
2828
php artisan vendor:publish --tag="forms-views"
2929
```
3030

31+
## Cloudflare Turnstile Setup (Optional)
32+
33+
This package includes built-in support for Cloudflare Turnstile CAPTCHA to protect your forms from spam.
34+
35+
### 1. Get Your Turnstile Keys
36+
37+
1. Sign up for a free [Cloudflare account](https://dash.cloudflare.com/sign-up) if you don't have one
38+
2. Go to the [Turnstile dashboard](https://dash.cloudflare.com/?to=/:account/turnstile)
39+
3. Create a new site and get your Site Key and Secret Key
40+
41+
### 2. Configure Your Environment
42+
43+
Add these to your `.env` file:
44+
45+
```env
46+
FORMS_TURNSTILE_ENABLED=true
47+
TURNSTILE_SITE_KEY=your_site_key_here
48+
TURNSTILE_SECRET_KEY=your_secret_key_here
49+
```
50+
51+
### Configuration Options
52+
53+
The package configuration in `config/forms.php` supports flexible environment variables:
54+
55+
```php
56+
'turnstile' => [
57+
'enabled' => env('FORMS_TURNSTILE_ENABLED', false),
58+
'site_key' => env('TURNSTILE_SITE_KEY','1x00000000000000000000AA'),
59+
'secret_key' => env('TURNSTILE_SECRET_KEY','1x0000000000000000000000000000000AA'),
60+
],
61+
```
62+
3163
## Form Usage (basic)
3264

3365
Include form method type, form method route, spam strap in the start and end of the form, form key, fake submit button, and a real submit button.
@@ -63,6 +95,7 @@ Include form method type, form method route, spam strap in the start and end of
6395
name="firstName"
6496
id="firstName"
6597
wire:model="firstName"
98+
value="{{ old('firstName') }}"
6699
autocomplete="given-name"
67100
class="block w-full rounded-md border-0 px-3.5 py-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
68101
pattern="[A-Za-z]{2,}"
@@ -82,6 +115,7 @@ Include form method type, form method route, spam strap in the start and end of
82115
name="first-name"
83116
id="lastName"
84117
wire:model="lastName"
118+
value="{{ old('lastName') }}"
85119
autocomplete="family-name"
86120
class="block w-full rounded-md border-0 px-3.5 py-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
87121
pattern=".{2,}"
@@ -101,6 +135,7 @@ Include form method type, form method route, spam strap in the start and end of
101135
name="email"
102136
type="email"
103137
wire:model="email"
138+
value="{{ old('email') }}"
104139
autocomplete="email"
105140
class="block w-full rounded-md border-0 px-3.5 py-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" />
106141
@error('email')
@@ -118,6 +153,7 @@ Include form method type, form method route, spam strap in the start and end of
118153
name="phone"
119154
id="phone"
120155
wire:model="phone"
156+
value="{{ old('phone') }}"
121157
autocomplete="tel"
122158
aria-describedby="phone-description"
123159
class="block w-full rounded-md border-0 px-3.5 py-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
@@ -141,6 +177,7 @@ Include form method type, form method route, spam strap in the start and end of
141177
id="message"
142178
name="message"
143179
wire:model="message"
180+
value="{{ old('messsage') }}"
144181
rows="4"
145182
aria-describedby="message-description"
146183
class="block w-full rounded-md border-0 px-3.5 py-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"></textarea>
@@ -178,7 +215,7 @@ Add laravel-forms to your tailwind.config.js file.
178215

179216
```javascript
180217
content: [
181-
'./vendor/fuelviews/laravel-forms/resources/**/*.php'
218+
'./vendor/fuelviews/laravel-forms/resources/**/*.blade.php',
182219
]
183220
```
184221

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"require": {
1919
"php": "^8.3",
2020
"spatie/laravel-package-tools": "^1.16",
21-
"illuminate/contracts": "^10.0||^11.0||^12.0"
21+
"illuminate/contracts": "^10.0||^11.0||^12.0",
22+
"ryangjchandler/laravel-cloudflare-turnstile": "^2.0||^1.1"
2223
},
2324
"require-dev": {
2425
"fuelviews/laravel-sabhero-wrapper": ">=0.0",
@@ -30,7 +31,7 @@
3031
"pestphp/pest-plugin-arch": "^3.0||^2.7",
3132
"pestphp/pest-plugin-laravel": "^3.2||^2.3",
3233
"rector/rector": "^2.0",
33-
"driftingly/rector-laravel": "^2.0"
34+
"driftingly/rector-laravel": "^2.0||^1.0"
3435
},
3536
"autoload": {
3637
"psr-4": {

config/forms.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,10 @@
9292
'yelp' => 'https://yelp.com',
9393
'bbb' => 'https://bbb.org',
9494
],
95+
96+
'turnstile' => [
97+
'enabled' => env('FORMS_TURNSTILE_ENABLED', false),
98+
'site_key' => env('TURNSTILE_SITE_KEY','1x00000000000000000000AA'),
99+
'secret_key' => env('TURNSTILE_SECRET_KEY','1x0000000000000000000000000000000AA'),
100+
],
95101
];

resources/views/components/steps/step-one.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<input type="text" name="gotcha" style="display:none" />
77

88
<div class="col-span-2">
9-
<div class="flex space-x-2 pt-4">
9+
<div class="flex flex-wrap gap-x-2 gap-y-6 pt-4">
1010
@foreach (config('forms.modal.steps.1.locations') as $location)
1111
<div>
1212
<x-forms::buttons.location-button :location="$location" />

resources/views/components/steps/step-two.blade.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@
6969
<div class="sm:col-span-2">
7070
<x-forms::error :errorKey="'form.submit.limit'" />
7171
</div>
72+
73+
@if(config('forms.turnstile.enabled') && config('forms.turnstile.site_key'))
74+
<div class="sm:col-span-2">
75+
<div
76+
x-data="{
77+
initTurnstile() {
78+
if (typeof turnstile !== 'undefined' && this.$el.querySelector('.cf-turnstile')) {
79+
const container = this.$el.querySelector('.cf-turnstile');
80+
if (!container.hasChildNodes() || container.children.length === 0) {
81+
turnstile.render(container, {
82+
sitekey: '{{ config('forms.turnstile.site_key') }}',
83+
callback: function(token) {
84+
@this.set('turnstileToken', token);
85+
}
86+
});
87+
}
88+
}
89+
}
90+
}"
91+
x-init="$nextTick(() => { setTimeout(() => initTurnstile(), 500); })"
92+
wire:ignore
93+
>
94+
<div class="cf-turnstile" data-sitekey="{{ config('forms.turnstile.site_key') }}"></div>
95+
</div>
96+
</div>
97+
@endif
7298
</div>
7399

74100
<input type="text" name="gotcha" class="hidden" />

0 commit comments

Comments
 (0)