hide field conditionally and submit values accordingly.
Hi there!
I wan to achieve something like if user has role admin then show this
otherwise i want to submit default value like this
how to achieve that?
Thanks!
7 Replies
Don't use
Hidden
to submit data.
You can have an if condition to show the Select
and do something similar in the mutateFormDataUsing()
method to add a default value eg
Not sure if ther's another way
You can also use ->hidden()
but that does render some stuff. However, AFAIK, hidden fields are not hydrated automatically so it's probably safe?Hey, Thank you for your help, I achieved it like this.
and used this $field variable inside schema
First thing Chester said was:
Don't use Hidden to submit data.It's a security risk. Why didn't you use his example?!
Alright! where to write ->mutateFormDataUsing?
Check this section for CreatePage: https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving
What chester showed was an example for Actions. Depending on whether you have a modal or a separate page
Oh, I have used this method mutateFormDataBeforeCreate() before.
Its really great alternative for Hidden or to submit default value.
Now my code looks like this.
I've removed if else and added hidden for manager role and adding default value for manager role.
Thank you @Dennis Koch , @ChesterS