Created
February 14, 2013 09:29
-
-
Save thelebster/4951550 to your computer and use it in GitHub Desktop.
Deny (hide) selected form fields by name. #drupal #form #helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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