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!
Solution:
I just found ->default(). Any reason not to use that?
Jump to solution
8 Replies
Solution
gmgarrison
gmgarrison13mo ago
I just found ->default(). Any reason not to use that?
awcodes
awcodes13mo ago
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?
gmgarrison
gmgarrisonOP13mo ago
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.
awcodes
awcodes13mo ago
Ok. Then ->default() should work. But it only works on create.
gmgarrison
gmgarrisonOP13mo ago
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!
awcodes
awcodes13mo ago
Glad you figured it out. Cheers.
gmgarrison
gmgarrisonOP13mo ago
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.
DrByte
DrByte13mo ago
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".
Want results from more Discord servers?
Add your server