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:Jump to solution
You could use ->action
```php
Action::make('createandsetactive')
->label('Create and set active')
->action(function(){...
8 Replies
Solution
You could use ->action
Thanks, worked like a charm!
@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');
}
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');
}
You should redirect to this route passing the params or make a http request
@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); }
$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); }
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 ?
@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]);
}
),