Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wuggycakes's avatar

Showing modal after validate form

I am using an action to create a model resource (I'm replacing the getCreateFormAction method in my CreateQuestion file). I want the action to validate first, then display a modal, and only when the user clicks "Submit" inside the modal, create the resource.

What's the problem then?

When I tried to do something like this:

use App\Filament\Resources\QuestionResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\CreateRecord;

class CreateQuestion extends CreateRecord
{
   protected static string $resource = QuestionResource::class;

   protected function getCreateFormAction(): Action
   {
       return Action::make('create')
           ->label('Create')
           ->modalContent(function () {
               $this->validate();
               return view('hello-world');
           })
           ->keyBindings(['mod+s']);
   }
}

It just threw the validation exception but Filament didn't handle it (no red text fields or error messages appeared, it just threw the screen with the Laravel Ignition trace).

I also tried doing something like this but it shows the modal and then when I click the action inside the modal it validates the data.

//...

protected function getCreateFormAction(): Action
    {
        return Action::make('create')
            ->label('Create')
            ->action(fn () => $this->validate())
            ->modalContent(fn() => view('hello-world'))
            ->keyBindings(['mod+s']);
    }

Other solution that just didn't work and the result was the same that before:

    protected function getCreateFormAction(): Action
    {
        return Action::make('create')
            ->label('Create')
            ->after(fn () => $this->validate()) // Instead "action", i tried with after
            ->modalContent(fn() => view('hello-world'))
            ->keyBindings(['mod+s']);
    }

What I'm doing wrong? I'm new using Filament.

0 likes
7 replies
wuggycakes's avatar

@Merklin Not work, apparently Filament "thinks" I'm trying to validate a form inside the Action, but that's not the case.

wuggycakes's avatar

@jaseofspades88 I'm not validating anything before the form, I want to validate the form after click the action, and only then, show a modal.

Mega_Aleksandar's avatar

I would actually make a second request - one for the first validation, get the response back, create the modal with the needed data and after the submit make the actual "store" method call. Basically, having a method called "validate" on the first trip to the backend and then the "store" method after submission.

Just an idea, haven't played around in fillament, so I don't know the exact terminology.

Hope this helps.

wuggycakes's avatar

@Mega_Aleksandar Can you please improvise an example of your idea? What I need is:

  • Validate the form
  • If validation doesn't fail, show the modal

But I find your solution a little bit complicated, at least that is what I perceive.

Mega_Aleksandar's avatar

@wuggycakes Hi, I am not a Fillament user (haven't had the chance to utilize it yet). But, from the frontend, the first form would submit to a route 'path/to/form/validation' return to the same view with the parameter of valid = true || false. If false, then on the frontend I would popup the modal and inside the modal (from the Submit button), the second call to the route 'path/to/form/submission/'.

Did I explain it correctly?

Please or to participate in this conversation.