uams-web/statamic-alpine-csp-forms
A Statamic addon that makes Alpine.js forms work under a strict Content Security Policy. Build forms in Antlers that submit without inline handlers or unsafe-eval, using CSP-safe external scripts and nonces so you can keep headers locked down.
This is a Statamic add-on, not a general Laravel package, so the first step is confirming your project is a Statamic site with forms rendered through Antlers or Blade and served under a strict Content Security Policy.
Install the add-on
composer require uams-web/statamic-alpine-csp-forms:0.1.0
Because this is a 0.x pre-release, pin the exact version rather than using a floating constraint. Check Packagist for the exact package name and whether you need an explicit stability flag or @dev/@beta constraint.
Check auto-discovery and published assets Statamic add-ons normally register a service provider automatically. Confirm whether the add-on ships a config file or front-end assets that need publishing:
php artisan vendor:publish --tag=statamic-alpine-csp-forms
Use the tag documented in the add-on README; if no publish tag exists, skip this step.
Load the Alpine CSP build and the driver
The add-on provides the alpine_csp form JavaScript driver. Follow the README for the exact asset tag or Vite entry point. The important part is that the page loads:
First use case
Take one existing Statamic form with conditional fields — for example, a “Company” field that reveals “VAT number” only when a “Business” option is selected. Run it under Content-Security-Policy-Report-Only first, confirm the field conditions evaluate in the browser, then enforce the CSP.
Where to look first:
spatie/laravel-csp or custom middleware) for the nonce and script-src rules.The add-on has two jobs: load a CSP-safe Alpine form driver, and evaluate the field conditions defined in your Statamic blueprints in the browser. The server remains responsible for validation and submission handling; the driver only improves the form UX.
Typical workflow:
if/show_when condition syntax).With Alpine’s CSP build you cannot rely on inline JavaScript expressions in attributes such as x-on:click="doSomething()" or inline object literals in x-data. Register named Alpine components/data objects in external JavaScript instead:
document.addEventListener('alpine:init', () => {
Alpine.data('contactForm', () => ({
submitted: false,
}));
});
Then reference only the registered name in markup. This is the pattern the CSP build expects, and the add-on’s driver should follow the same constraint.
If you use spatie/laravel-csp, make sure the nonce is applied to the add-on’s script tag as well as Alpine itself. A common pattern is to pass the nonce into your layout:
<script nonce="{{ csp_nonce() }}" src="{{ asset('vendor/statamic-alpine-csp-forms/driver.js') }}"></script>
Use the actual asset path or tag from the add-on README. If the nonce is missing from one script, the browser will block it and field conditions will silently stop working.
Field conditions are presentation logic. Do not use them as validation. A field hidden by the evaluator must still be rejected or ignored server-side according to your form’s validation rules. Statamic form submissions should continue to validate all required fields as configured.
For an existing site, deploy with Content-Security-Policy-Report-Only first:
This is especially important when moving from a non-CSP Alpine setup, because previously tolerated inline expressions will now be blocked.
A PHP feature test can assert that the form markup and script tags render, but it cannot verify the browser-side evaluator. Cover the actual behaviour with Dusk, Playwright, or a manual browser check:
0.x means breaking changes can arrive in minor releasesThe release notes explicitly state that a minor release can carry a breaking change and will call it out first. Practical consequences:
composer.json, for example "uams-web/statamic-alpine-csp-forms": "0.1.0".composer update.1.0.0; keep your integration thin so upgrades are cheap.If Composer refuses to install the package due to stability, add an explicit constraint with a stability suffix or set minimum-stability carefully. Prefer a targeted constraint over lowering minimum stability for the whole project.
The most common failure mode is copying Alpine examples from the docs that use inline expressions. Under the CSP build those will not run. Symptoms include:
unsafe-eval.Fix by moving logic into registered Alpine components and binding only method or property names in markup.
Two frequent causes of “it worked yesterday”:
php artisan cache:clear
php artisan statamic:stache:clear
Then hard-refresh the browser.When field conditions do not work:
script-src allows the nonce or the host serving the driver.Content-Security-Policy-Report-Only to see blocked resources without breaking the page.composer why-not uams-web/statamic-alpine-csp-forms <version> when resolving conflicts.The add-on is MIT licensed, which is permissive for project use. It is still a pre-1.0 package, so treat it as an integration dependency that needs version pinning and periodic review rather than a stable platform component.
How can I help you explore Laravel packages today?