Skip to content

Instantly share code, notes, and snippets.

@thelebster
Created February 14, 2013 09:29
Show Gist options
  • Save thelebster/4951550 to your computer and use it in GitHub Desktop.
Save thelebster/4951550 to your computer and use it in GitHub Desktop.
Deny (hide) selected form fields by name. #drupal #form #helper
<?php
/**
* Deny (hide) selected form fields by name.
*
* @param array $fields
* Array of fields names that needs to be denied.
*
* Values of these fields will not be passed to $form_state['values'].
*
* @example
* // hide 'status', 'timezone', 'notify' form fields from $form['account']
* $fields = array('status', 'timezone', 'notify');
* MYMODULE_form_helper_deny_fields($form['account'], $fields);
*/
function MYMODULE_form_helper_deny_fields(&$form, $fields = array()) {
if (is_array($fields)) {
foreach ($fields as $field) {
if (isset($form[$field])) $form[$field]['#access'] = FALSE;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment