Skip to content

Instantly share code, notes, and snippets.

@thelebster
Last active December 13, 2015 17:58
Show Gist options
  • Save thelebster/4951475 to your computer and use it in GitHub Desktop.
Save thelebster/4951475 to your computer and use it in GitHub Desktop.
Disable selected form fields by name. #drupal #form #helper
<?php
/**
* Disable selected form fields by name.
*
* @param array $fields
* Array of fields names that needs to be disabled.
*/
function MYMODULE_form_helper_disable_fields(&$form, $fields = array()) {
if (is_array($fields)) {
foreach ($fields as $field) {
if (isset($form[$field])) $form[$field]['#disabled'] = TRUE;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment