Multiple forms in custom page

I have two forms. But when pressing submit both forms get's triggered.
class EditProfile extends Page implements HasForms
{
public ?array $profileData = [];
public ?array $passwordData = [];

protected function getForms(): array
{
return [
'editProfileForm',
'editPasswordForm',
];
}

public function editProfileForm(Form $form): Form
{
profile form
}

public function editPasswordForm(Form $form): Form
{
password form
}

public function updateProfile(): void
{
update profile login
}

public function updatePassword(): void
{
update password logic
}

protected function getUpdateProfileFormActions(): array
{
return [
Action::make('updateProfileAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updateProfile'),
];
}

protected function getUpdatePasswordFormActions(): array
{
return [
Action::make('updatePasswordAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updatePassword'),
];
}
}
class EditProfile extends Page implements HasForms
{
public ?array $profileData = [];
public ?array $passwordData = [];

protected function getForms(): array
{
return [
'editProfileForm',
'editPasswordForm',
];
}

public function editProfileForm(Form $form): Form
{
profile form
}

public function editPasswordForm(Form $form): Form
{
password form
}

public function updateProfile(): void
{
update profile login
}

public function updatePassword(): void
{
update password logic
}

protected function getUpdateProfileFormActions(): array
{
return [
Action::make('updateProfileAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updateProfile'),
];
}

protected function getUpdatePasswordFormActions(): array
{
return [
Action::make('updatePasswordAction')
->label(__('filament-panels::pages/auth/edit-profile.form.actions.save.label'))
->submit('updatePassword'),
];
}
}
Solution:
remove catch (Exception $e) if you want to keep try catch
Jump to solution
32 Replies
krekas
krekasOP2y ago
The blade file
<x-filament-panels::page>
<x-filament-panels::form wire:submit="updateProfile">
{{ $this->editProfileForm }}

<x-filament-panels::form.actions
:actions="$this->getUpdateProfileFormActions()"
/>
</x-filament-panels::form>

<x-filament-panels::form wire:submit="updatePassword">
{{ $this->editPasswordForm }}

<x-filament-panels::form.actions
:actions="$this->getUpdatePasswordFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament-panels::form wire:submit="updateProfile">
{{ $this->editProfileForm }}

<x-filament-panels::form.actions
:actions="$this->getUpdateProfileFormActions()"
/>
</x-filament-panels::form>

<x-filament-panels::form wire:submit="updatePassword">
{{ $this->editPasswordForm }}

<x-filament-panels::form.actions
:actions="$this->getUpdatePasswordFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
Anyone?
Dennis Koch
Dennis Koch2y ago
You should use a <button type="submit"> instead of the actions.
krekas
krekasOP2y ago
tried that. same result
Dennis Koch
Dennis Koch2y ago
So you removed the actions? Can you try to use a <form> instead of <x-filament-panels::form>? Also check your HTML source code for nested forms.
krekas
krekasOP2y ago
form the form seeing them seperate
krekas
krekasOP2y ago
making blade like so doesn't change anything
<x-filament-panels::page>
<form wire:submit="updateProfile">
{{ $this->editProfileForm }}

<button type="submit">Submit</button>
</form>

<form wire:submit="updatePassword">
{{ $this->editPasswordForm }}

<button type="submit">Submit</button>
</form>
</x-filament-panels::page>
<x-filament-panels::page>
<form wire:submit="updateProfile">
{{ $this->editProfileForm }}

<button type="submit">Submit</button>
</form>

<form wire:submit="updatePassword">
{{ $this->editPasswordForm }}

<button type="submit">Submit</button>
</form>
</x-filament-panels::page>
of course using button like this doesn't have styling
Dennis Koch
Dennis Koch2y ago
Is wire:submit.prevent default now in LW v3? Because it's still present at the bottom but not in your code.
krekas
krekasOP2y ago
yes it is
Dennis Koch
Dennis Koch2y ago
Okay. I have no idea then, sorry.
krekas
krekasOP2y ago
I guess then I need to make an issue with the demo repo
Dennis Koch
Dennis Koch2y ago
Yes. Best to use a fresh install and a minimal form setup to compare whether it's really an issue,
LeandroFerreira
weird. The html should have <form wire:submit="updateProfile">...
krekas
krekasOP2y ago
it has at the end
LeandroFerreira
nope.. if you have <form wire:submit="updateProfile"> it should render exactly this
krekas
krekasOP2y ago
if you mean without alpine directives then it is just like if I don't use blade component for the form
krekas
krekasOP2y ago
LeandroFerreira
yes, because you did
<x-filament-panels::page>
<form wire:submit="updateProfile">
{{ $this->editProfileForm }}

<button type="submit">Submit</button>
</form>

<form wire:submit="updatePassword">
{{ $this->editPasswordForm }}

<button type="submit">Submit</button>
</form>
</x-filament-panels::page>
<x-filament-panels::page>
<form wire:submit="updateProfile">
{{ $this->editProfileForm }}

<button type="submit">Submit</button>
</form>

<form wire:submit="updatePassword">
{{ $this->editPasswordForm }}

<button type="submit">Submit</button>
</form>
</x-filament-panels::page>
right? what is the result when you submit?
krekas
krekasOP2y ago
the same as with using components
LeandroFerreira
ok but you have two methods. What is the result if you do this?
public function updateProfile(): void
{
dump('profile form');
}

public function updatePassword(): void
{
dump('password form');
}
public function updateProfile(): void
{
dump('profile form');
}

public function updatePassword(): void
{
dump('password form');
}
krekas
krekasOP2y ago
dumps as expected
LeandroFerreira
both forms get's triggered in the same time? I didn't understand when you said: But when pressing submit both forms get's triggered.
krekas
krekasOP2y ago
for password form i have validation like current password, same for password confirmation it i enter anything in password inputs and press submit for this form it should show validation errors but instead it submits the first form also i can see that both submit buttons are triggered of changing colors if you want here's demo repo https://github.com/krekas/filament-multiple-forms-test
LeandroFerreira
remove try catch
public function updateProfile(): void
{
$data = $this->editProfileForm->getState();
...
}

public function updatePassword(): void
{
$data = $this->editPasswordForm->getState();
...
}
public function updateProfile(): void
{
$data = $this->editProfileForm->getState();
...
}

public function updatePassword(): void
{
$data = $this->editPasswordForm->getState();
...
}
krekas
krekasOP2y ago
OK will try
LeandroFerreira
TextInput::make('current_password') instead of TextInput::make('Current password')...
krekas
krekasOP2y ago
I would assume that with try it should work because in filament it's how it's done
Solution
LeandroFerreira
remove catch (Exception $e) if you want to keep try catch
krekas
krekasOP2y ago
Will try when I get back home. Thanks for now
LeandroFerreira
let me know because there is an issue opened..
krekas
krekasOP2y ago
Will close it if it will work
LeandroFerreira
yes but it generates work to Dan and Team
krekas
krekasOP2y ago
Will try it today

Did you find this page helpful?