Page with multiple forms action

Hello, i am making a page that have multiple forms in it, how do i have an action for each form's submit ?
14 Replies
Shinra
ShinraOP2y ago
i will post what i have tried so far soon
toeknee
toeknee2y ago
If it's a custom page, you would ideally have multiple livewire components each being a form so it' calls it'self
Shinra
ShinraOP2y ago
protected function getForms(): array { return [ 'generalInfoForm' => $this->makeForm() ->schema($this->getGeneralInfoFormSchema()), 'passwordForm' => $this->makeForm() ->schema($this->getPasswordFormSchema())->statePath('passData'), 'configForm' => $this->makeForm() ->schema($this->getConfigFormSchema()), ]; } protected function getPasswordFormSchema(): array { return [ LovaSection::make('Change Password') ->compact() ->collapsible() ->collapsed() ->columns(3) ->schema([ TextInput::make('current_password') ->label('Current Password') ->password() ->rules(['required_with:new_password']) ->currentPassword() ->autocomplete('off'), TextInput::make('new_password') ->label('New Password') ->password() ->rules(['confirmed']) ->autocomplete('new-password'), TextInput::make('new_password_confirmation') ->label('Confirm Password') ->password() ->rules([ 'required_with:new_password', ]) ->autocomplete('new-password'), ]) ->footerSchema([ DropInAction::make('password_action')->disableLabel() ->execute( \Filament\Forms\Components\Actions\Action::make('passwordAction')->action('update_password') ) ]) ]; } hello, thank you for quick response, do you mean to make <livewire:form> on the page file ? instead of inside class
toeknee
toeknee2y ago
No you would build individual livewire components if you want them to have different form actions completely.
Shinra
ShinraOP2y ago
so.. what is the point of getForms() then ? i mean, what is the use case for a page with multiple forms, but still have 1 action ?
toeknee
toeknee2y ago
Ahh my bad, I am not familiar with getForms. Just checked the docs one second
Shinra
ShinraOP2y ago
ah okay, i will complete my question first, the Action in my code would not call the update_password public function, and that confuses me
toeknee
toeknee2y ago
Makes sense now, you would need to customise the view to have an action on the form. So for example: https://filamentphp.com/docs/2.x/forms/getting-started#using-multiple-forms you would have
<form wire:submit.prevent="savePost">
{{ $this->postForm }}

<button type="submit">
Save Post
</button>
</form>
<form wire:submit.prevent="savePost">
{{ $this->postForm }}

<button type="submit">
Save Post
</button>
</form>
I believe, but along those lines
Filament
Getting started - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Shinra
ShinraOP2y ago
i had hoped that it didnt come to that.. hahaha, because i want to use the styling of filament's components so its not possible to make the submit button in the form schema ? i feel like i am so close with my approach to use drop-in-action as the submit button for my forms, any insights as to why the action button in my code is not working ?
Thijmen
Thijmen2y ago
Why not make a function() in the ->action()?
Shinra
ShinraOP2y ago
hello, i have also tried that, like this DropInAction::make('password_action')->disableLabel() ->execute( function (\Closure $get, \Closure $set){ return \Filament\Forms\Components\Actions\Action::make('geolocate') ->icon('heroicon-o-search') ->label('Geocode') ->action(function () use ($get,$set){ Log::info('asdasdasd'); $set('subscriber_code', 'asdasd'); }); } ) but nothing is in the log
Thijmen
Thijmen2y ago
That's weird Did you try dd()? Also i'm not sure if $get and $set are closures
Shinra
ShinraOP2y ago
yes i just tried dd() and the response is still 200, with these { "effects": { "html": null, "dirty": [] }, "serverMemo": { "checksum": "d01bfee9a651579cda0a6b6d919a641ed10be0f0da664f116ca9ddeaf07cfee5" } } nothing happened as if it didnt reach the dd() at all
Thijmen
Thijmen2y ago
Do you have any errors in your code editor? And what is the rest of the code from the form builder
Want results from more Discord servers?
Add your server