Custom form action help

Hi, Is there a way modify form data when submitting from a custom form action? I've added this into my createPost.php protected function getFormActions(): array { return [ $this->getCreateFormAction(), $this->getCreateAndSetActiveFormAction(), $this->getCancelFormAction(), ]; } protected function getCreateAndSetActiveFormAction(): Action { return Action::make('createandsetactive') ->label('Create and set active') ->submit('createandsetactive'); } This button works correctly in creating a Post record, but I'd like to be modify the 'active' parameter that's in the form data and set it to TRUE before creating the record. Is such a thing possible?
Solution:
You could use ->action ```php Action::make('createandsetactive') ->label('Create and set active') ->action(function(){...
Jump to solution
8 Replies
Solution
LeandroFerreira
LeandroFerreira8mo ago
You could use ->action
Action::make('createandsetactive')
->label('Create and set active')
->action(function(){
$this->data['status'] = 'active';
$this->create();
})
Action::make('createandsetactive')
->label('Create and set active')
->action(function(){
$this->data['status'] = 'active';
$this->create();
})
Gediminas
Gediminas8mo ago
Thanks, worked like a charm!
hashim199
hashim1993mo ago
@Leandro Ferreira Send the data of form to controller function from a custom action, i will be thankful to you for the help Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ]) ->action(function (array $data) {
return route('invoice.create',$data); }) Routes: I have tried both i doest not Route::get('/invoice-genrate/{data}', [BillPanelReports::class, 'createInvoice'])->name('invoice-genrate'); Route::post('/invoice-cerate', [BillPanelReports::class, 'createInvoice'])->name('invoice.create'); controller function public function createInvoice(Request $request) { dd('hello'); $companyName = $request->input('companyname'); $fromDate = $request->input('from'); $toDate = $request->input('to');
}
LeandroFerreira
LeandroFerreira3mo ago
You should redirect to this route passing the params or make a http request
hashim199
hashim1993mo ago
@Leandro Ferreira now its is not going inside function and there is no error 😦 Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ]) ->action( function (array $data) {
$companyName=$data['companyname']; $fromDate=$data['from']; $toDate=$data['to']; return route('invoice-genrate',[$companyName,$fromDate,$toDate]);
} ) Route::get('/invoice-genrate/{companyName}/{fromDate}/{toDate}', [BillPanelReports::class, 'createInvoice'])->name('invoice-genrate'); public function createInvoice(Request $request) { $companyName = $request->input('companyname'); $fromDate = $request->input('from'); $toDate = $request->input('to'); dd($companyName,$fromDate,$toDate); }
hashim199
hashim1993mo ago
akash sagar
akash sagar3mo ago
hello i am new to filament i have created this action which is dispatching an event public function clearAction(): Action { return Action::make('clear') ->size(ActionSize::Large) ->dispatch('clear-form'); } this action is clearing localstorage but i also want to clear form data along with this, for that i want to do this $this->form->fill(); can anyone know where i should use this ?
hashim199
hashim1993mo ago
@Leandro Ferreira solved now how can i open the action in new window, shouldOpenInNewTab will not work here any suggestions ->action( function ($data) { $companyName=$data['companyname']; $fromDate=$data['from']; $toDate=$data['to']; return redirect()->route('invoice-genrate',[$companyName,$fromDate,$toDate]); } ),