Setting field attribute as read only in hook_form_alter? I'm trying to create a simple custom module to stop the Title of a specific node being edited.

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'nodetitle_node_form') {
    unset($form['title']);
  }
}


Currently it just removes any reference to the Title from the edit pages. Does anyone know how I can set the Title field attribute read only?
You can use the #disabled attribute:

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'nodetitle_node_form' &amp;&amp; $form['nid']['#value']) {
    $form['title']['#disabled'] = TRUE;
  }
}


I made the assumption that you want this when editing nodes only (not when they are being added) which is what the &amp;&amp; $form['nid']['#value'] part is for.