How to override the submission of a form in a custom created page class.
I create a custom page class to reset the password.
“
class ResetPassword extends Page implements HasForms
{
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.reset-password';
protected static bool $shouldRegisterNavigation = false;
protected function getFormSchema(): array
{
return [
Card::make()->schema([
Forms\Components\TextInput::make('email')
->email()
->required()
->name('email')
->label('Current Email'),
Forms\Components\TextInput::make('password')
->password()
->required()
->minLength(6)
->name('password')
->label('Current Password'),
Forms\Components\TextInput::make('newpassword')
->password()
->required()
->minLength(6)
->name('newpassword')
->label('New Password'),
])
];
}
}“
And my custom view page is:
“
<x-filament::page>
<form>
@csrf
{{ $this->form }}
<div class="filament-page-actions flex flex-wrap ">
<button type="submit" class="text-white font-bold">
Submit
</button>
</div>
</form>
</x-filament::page> “
Now I need to customize the submission of this form in ResetPassword class. How can I do that.6 Replies
Now I need to customize the submission of this form in ResetPassword class. How can I do that.What are you trying to customize?
I see you're missing a
wire:submit
handler on your form... make sure to give this a quick read:
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-componentI'm trying to customize the submit function.
I created a submit function inside the "ResetPassword" .
"
public function submit()
{
$data = $this->form->getState();
// Processing the password resetting
// Redirect back to the form page
return redirect()->route('filament.pages.reset-password');
}
"
When I click the submit button on the form, need to get all the field values [username, password, newpassword] inside the sumit method in the "ResetPassword" page class. But as per my current code, I only the token value inside the submit function.
Below given is my view page.
" <x-filament::page>
<div class="container mx-auto py-2">
<div class="flex">
<div class="w-full">
<form action="{{ route('filament.pages.reset-password.submit') }}" method="POST">
@csrf
{{ $this->form }}
<div class="filament-page-actions filament-form-actions">
<button type="submit" class="text-white">
Submit
</button>
</div>
</form>
</div>
</div>
</div>
</x-filament::page>
"You're trying to use a Filament form with a regular POST form action. It's not designed to work this way.
Then how can I achieve this functionality. Need to create page with a form having three fields and to submit that after validating the fields. No need of list , view, edit pages.
It's described in this section of the documentation:
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component