I need users to be able to only edit certain fields on a webform, and not others. This may be due to user privileges, for example.
I’m not sure on the best way to handle this.
-
Set the form attribute to disabled. The problem with this is that disabled fields don’t get submitted, so I either need to include hidden form fields, or I need to cater for this in my model (i.e. only update fields that shouldn’t get changed)
-
Set the attribute to readonly. Possibly better than the above because these fields automatically get posted
-
Don’t use a form field at all – just echo out the var in html. Possibly include a hidden form field or only update fields that shouldnt get changed in the model
I’m not sure on the best way to handle this, both from a UX point of view, and from a general application point of view.
You should always handle this in your models, at the server side. I do not know if your application will be used publicly? But it’s fairly easy to change the required or disabled attributes on the client side to be able to use the form elements.