Last active
August 29, 2015 14:02
-
-
Save acao/6fbe6d25a504b63b946b to your computer and use it in GitHub Desktop.
A handy example of how to hide non-required fields from a form - in this case, on a profile2_regpath altered user_register_form
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 | |
function MYMODULE_form_alter(&$form, &$form_state, $form_id){ | |
if ($form_id == 'user_register_form') { | |
$fields = array_filter($form['profile_PROFILE_TYPE_NAME'], "_filter_required_fields"); | |
foreach ($fields as $field_name => $field) { | |
$form['profile_PROFILE_TYPE_NAME'][$field_name]['und']['#access'] = false; | |
} | |
} | |
} | |
function _filter_required_fields($field){ | |
if (is_array($field) && isset($field['und'])){ | |
if (!isset($field['und']['#required']) || $field['und']['#required'] == false){ | |
return $field; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment