How to disable, hide or lock a form field in Drupal

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

Primary tabs

First Create a function hook_form_alter.Then inside hook_form_alter depending upon your choice :
a) If you want to disable field (it will be visible, but user can't change it) :

$form['field_myfield']['#disabled'] = TRUE;

b) If you want it to be hidden, but to keep value it has before editing the way to do that is:

$form['field_myfield']['#access'] = FALSE;

c) if you want to hide it: