Locking Form fields (read only)

hello everybody,

I have a form, and when a specific time is passed (today) I’ll lock some of the form fields so the user cannot modify those fields. This part was easy :)

My question is, how can I find out which fields were read-only? (since everything is dynamic in my form)



I am not sure I fully understand what you are trying to do.

All disabled fields do not appear in the posted data, so on the server side you can find out if a field was disabled like this: if(!isset($_POST[‘myobject’][‘myfield’])) { // field was disabled }

Of course a user can still manipulate the POST data and set a field that you disabled.

If you only have a few different cases then you could use scenarios.

In one scenario you include all your fields in safeAttributes() in the other scenario you only include the fields that are not disabled. In your controller you have to set the scenario following the condition for disabling fields. You could also have some logic in the safeAttributes() function.

There is a difference in disabling a field and making it read-only. In the first, the data is not passed.


it is definitely a READ ONLY field, NOT disabled. I kinda ducked that bullet with another solution, passing a hidden value which is set to TRUE if the fields are LOCKED.

I was just curious if there is a thing like:

$this -> getAttribute( 'field_name' ) -> options[ 'readOnly' ]; // which would return TRUE or FALSE