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
Action::make('createandsetactive')
    ->label('Create and set active')
    ->action(function(){
        $this->data['status'] = 'active';
        $this->create();
    })
Was this page helpful?