Set initial value for hidden field
I'm new to Filament but experienced with PHP and Laravel.
I saw in the FormBuilder documentation creating a hidden field (Hidden::make('token')) but I can't find any info on setting its value to a default. I tried ->fill but got an error about accessing the Component before it's initialized.
What am I missing?
Thank you!
8 Replies
Solution
I just found ->default(). Any reason not to use that?
I recommend not using a hidden field for anything that has to do with tokens or ids. They can be manipulated from the front end. It would be better to handle that during the create or save process.
Is there a specific reason the form needs it?
I do understand the vulnerability from the front-end. This particular form is on the admin side of our product and the user would be able to change it regardless, just in a different place. I just haven't learned enough Filament yet to know how to set it in the backend but when I do, I'll probably move it back there anyways.
Ok. Then ->default() should work. But it only works on create.
I think that's the only place I'll need it in this instance. That particular field isn't displayed on the edit form b/c it won't need to be changed on this screen. Thanks for chiming in!
Glad you figured it out. Cheers.
I will say the documentation is pretty fantastic and then having this Discord that's also searchable is also a huge bonus. They've both been very helpful for me so far.
Definitely.
Also, when your thread has an answer, please mark it "Solved": right-click on the "best answer" post, choose "Apps" and choose "Mark Solved".