Brought to you by molecularsciences.org.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
This publication may not be redistributed without this notice.

Making a text field uneditable

Every now and then, we need to show the data in a form field, pre-checked checkboxes, or pre-selected selection menus, which should not be editable by the user. Very often, these sort of functions are used in permissions and access control related pages.

In HTML, an uneditable form field can be created as follows:

<input type="text" readonly="readonly" name="cantedit" />

In drupal, an editable form field can be created as follows:

$form['name'] = array( '#type' => 'textfield', '#title' => t('name'), '#attributes' => array('disabled' => 'disabled'), );