How to make a field readonly using hook_form_alter I am trying to make some of the Drupal profile form fields as read-only in edit mode. I am using the following code 
in hook_alter 

$form[field_organisation_company_name][und][0]['#after_build'][]='_build_element_readonly';

function _build_element_readonly($element, &amp;$form_state) {  
    $element['value']['#attributes']['readonly'] = 'readonly';
    return $element;
}


In the UI filed is showing as read-only, but still, I can change the value using firebug and save. Is there any way to prevent this behavior?
It sounds like you could accomplish what you need to with Field Permissions. On a field-by-field basis you can set permissions to:


  
  Create own value for the field
  Edit own value for the field
  Edit anyone's value for the field
  View own value for the field
  View anyone's value for the field
  


So you would easily be able to allow your users to create the value for the field initially, but as soon as they have it only becomes editable by an admin.