Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jj63systems's avatar

V3 - Create and Create Another - unable to populate new record instance fields

Hi all, struggling to understand in Filament v3 how to utilise the 'Create and Create Another' feature - by default the new record is saved and the same form is then presented blank for entry of new record details.

I want to pre-populate with a subset of the data just saved - which methods to I hook into in order to do this?

thanks for any pointers j

0 likes
2 replies
LaryAI's avatar
Level 58

In Filament v3, the “Create and Create Another” feature re-renders the form blank after saving by default. If you want to pre-populate the new record form with a subset of the data just saved, you need to override the behavior after the record is created.

Here’s how you can approach this:

  1. Override the mutateFormDataBeforeCreate or define your own method to copy over the attributes you need.
  2. Use the afterCreate or afterCreateAnother hook to modify the form's state for the next item.

Let’s say you have a PostResource and want to copy, for example, the category_id to the new form each time you create another.

use Filament\Resources\Pages\CreateRecord;

class CreatePost extends CreateRecord
{
    protected function afterCreate(): void
    {
        // Save the fields you want to retain in the session or a property.
        session([
            'post.last_category_id' => $this->record->category_id,
        ]);
    }

    protected function getFormModel(): string
    {
        return \App\Models\Post::class;
    }

    protected function mutateFormDataBeforeFill(array $data): array
    {
        // When the form is freshly loaded (after "Create Another"),
        // pre-fill the field(s) from the session if available.
        if (session()->has('post.last_category_id')) {
            $data['category_id'] = session('post.last_category_id');
        }

        return $data;
    }
}

Notes:

  • The afterCreate hook will run after each record is created. You can use it to store the data you want to persist (for the next create).
  • The mutateFormDataBeforeFill hook runs when the form is (re)filled, which happens when “Create Another” is used. Here, you inject the data saved from the previous record.
  • You may want to clear the session key when leaving the page or after the normal “Create” flow.

Alternative:
If you need more dynamic or complex behavior, you can also use form state management methods and properties to achieve a similar result.

Let me know if you need an example for a specific scenario or a different resource!

jj63systems's avatar

Not working as intended. The code I have is this:

I get the logged message (and the record_id reported is that of the successfully-created item record)

[2025-10-29 15:03:41] development.INFO: AFTER CREATE called {"record_id":53086}

But not the others from the other methods. How can I resolve / debug further?

Reminder that this is Filament v3.

Oh and in inspecting the source, the button is defined with wire:click="createAnother" so am sure I'm clicking the correct button before you ask :)

J

Please or to participate in this conversation.