Skip to content

Aurora 1.5 is out!

What's new →
Docs menu

Using the admin

Forms

Forms with conditional fields, and what to do with the answers.

Building a form

  • Field types: short text, email, phone, long text, dropdown, single choice, multiple choice, date, file upload (with allowed types and a size limit) and a consent checkbox. Each field has a label, key, placeholder, help text, required and width.
  • Conditional fields: Show only when another field has a given answer. Hidden fields aren't required, checked or stored.
  • Translations: every field's text in each language, with one-click AI translation.
  • Settings: whether the form accepts answers, the button label, a thank-you message or a page to go to afterwards, and email addresses to notify.
The form builder: fields with labels and widths, and the form's settings
The form builder: fields, their widths, and the form's settings.

Submissions

  • Statuses New, Read, Archived and Spam; reply by email; bulk status changes; export to CSV.
  • Uploaded files are served through signed links.
  • The sidebar badge counts new submissions, and everyone who handles forms is notified.
A form's submissions with their status, ready to read, reply to or export
Submissions, ready to read, reply to, archive or export.

Spam protection

A honeypot field, a minimum fill time and a rate limit. Spam is kept, marked as spam, and sends no notifications.

On the website

Place a form with the Form block. Submissions work without JavaScript: they're a plain POST to /forms/{form} with server-side validation, and messages and old input come back to the page. Conditional fields are shown and hidden in the browser and checked again on the server. Deleting a form warns which live pages use it.

To send submissions anywhere else, listen for Aurora\Events\FormSubmitted or add a webhook.

Field types of your own

A website or a package can add field types to the form builder v1.3.11: a captcha, an address picker, a booking slot. A field type is a class extending Aurora\Forms\FieldType, registered in a service provider's boot(). Editors then add it to forms like any other field, and every form keeps working if the type is removed later: its fields become short text.

  • In the form builder: its name, icon and settings of its own (settings()), stored with the field.
  • Checked first: its rules() run before anything is kept, so a failed captcha sends the visitor back to the form with the error.
  • Kept, or not: stores() says whether its answer is kept, and value() how; a captcha's answer isn't.
  • On the website: render() draws its control, and scripts() lists scripts loaded once per page. A website's form view hands any type that isn't Aurora's own to <x-aurora::form-field>, which does both.
  • Kept private: only the settings in publicData() reach the website and the APIs, so a secret never does. Keep keys in a settings tab or in config/services.php.

Example: Cloudflare Turnstile

A captcha that checks the visitor's token with Cloudflare before the submission is kept. The site key and secret come from Cloudflare's dashboard.

app/Forms/Turnstile.php PHP
namespace App\Forms;

use Aurora\Forms\FieldType;
use Closure;
use Illuminate\Support\Facades\Http;

class Turnstile extends FieldType
{
    public static function type(): string
    {
        return 'turnstile';
    }

    public static function label(): string
    {
        return __('Captcha (Turnstile)');
    }

    public static function icon(): string
    {
        return 'phosphor-shield-check';
    }

    public static function requiredByDefault(): bool
    {
        return true;
    }

    // Checked with Cloudflare before anything is kept.
    public static function rules(array $field): array
    {
        return ['required', function (string $attribute, mixed $token, Closure $fail): void {
            $result = Http::asForm()->post('https://challenges.cloudflare.com/turnstile/v0/siteverify', [
                'secret' => config('services.turnstile.secret'),
                'response' => $token,
                'remoteip' => request()->ip(),
            ]);

            if (! $result->json('success')) {
                $fail(__('Please confirm you are human.'));
            }
        }];
    }

    // A captcha's answer is a token, not something to keep.
    public static function stores(): bool
    {
        return false;
    }

    public static function translatable(): array
    {
        return [];
    }

    public static function labelled(): bool
    {
        return false;
    }

    // Turnstile sends its token as the field's own input (data-response-field-name).
    public static function render(array $field, string $id, string $attributes): string
    {
        return sprintf(
            '<div id="%s" class="cf-turnstile" data-sitekey="%s" data-response-field-name="%s"></div>',
            e($id),
            e(config('services.turnstile.key')),
            e($field['name']),
        );
    }

    public static function scripts(): array
    {
        return ['https://challenges.cloudflare.com/turnstile/v0/api.js'];
    }
}
app/Providers/AppServiceProvider.php PHP
use App\Forms\Turnstile;
use Aurora\Support\FormFields;

public function boot(): void
{
    FormFields::register([Turnstile::class]);
}

// config/services.php
'turnstile' => [
    'key' => env('TURNSTILE_SITE_KEY'),
    'secret' => env('TURNSTILE_SECRET_KEY'),
],

Example: an address picker

A text field that suggests addresses from Google Places as the visitor types, and keeps the address as text. Its setting limits the suggestions to a country, and the website may see it.

app/Forms/AddressPicker.php PHP
namespace App\Forms;

use Aurora\Forms\Fields\Text;
use Filament\Forms\Components\TextInput;
use Illuminate\Support\Facades\Vite;

// A short text field with suggestions: placeholder, rules and storing come from Text.
class AddressPicker extends Text
{
    public static function type(): string
    {
        return 'address';
    }

    public static function label(): string
    {
        return __('Address');
    }

    public static function icon(): string
    {
        return 'phosphor-map-pin';
    }

    public static function settings(): array
    {
        return [
            ...parent::settings(),
            TextInput::make('country')->label(__('Country'))->placeholder('no')->maxLength(2),
        ];
    }

    public static function publicData(): array
    {
        return [...parent::publicData(), 'country'];
    }

    public static function render(array $field, string $id, string $attributes): string
    {
        return sprintf(
            '<input type="text" %s data-address-picker data-country="%s" placeholder="%s" autocomplete="off" class="block w-full rounded-xl px-4 py-3 ring-1 ring-zinc-300">',
            $attributes,
            e($field['data']['country'] ?? ''),
            e($field['data']['placeholder'] ?? ''),
        );
    }

    // Loads Google's script with the key and turns every [data-address-picker] into an autocomplete.
    public static function scripts(): array
    {
        return [Vite::asset('resources/js/address-picker.js')];
    }
}