Populate form from query string

I want to populate a Wizard partially from a query string. The use case would be, you want someone to register for your site, and you have a wizard they need to fill out. An administrator can give you a link that has some things already filled out, so when you get to that URL, you are on a certain step and all the previous required values are already populated.
No description
3 Replies
ChesterS
ChesterS2w ago
Here is a way you can achieve something like that. Add this to the CreateRecord page
public function mount(): void
{
parent::mount();

$this->form->fill([
'name' => request()->get('name'),
]);
}

public function form(Form $form): Form
{
return $form->schema([
Wizard::make([
Wizard\Step::make('Step1')
->schema([
TextInput::make('name')
]),
Wizard\Step::make('Step2')
])
->startOnStep(function(Request $request) {
return $request->get('step', 1);
})
]);
}
public function mount(): void
{
parent::mount();

$this->form->fill([
'name' => request()->get('name'),
]);
}

public function form(Form $form): Form
{
return $form->schema([
Wizard::make([
Wizard\Step::make('Step1')
->schema([
TextInput::make('name')
]),
Wizard\Step::make('Step2')
])
->startOnStep(function(Request $request) {
return $request->get('step', 1);
})
]);
}
I can't stress this enough - this is just a sample to get you started! Up to you to make sure this is secure or what you want Anyway, hope it helps
toeknee
toeknee2w ago
I would say to store the data on the invitation, have a unique url with a unique code which pre-fills the form with the form filler from the database where the code matches. Then on submission, invalidate the code.
swilla
swillaOP2w ago
Thank you

Did you find this page helpful?