Created
April 3, 2010 15:09
-
-
Save evandonovan/354569 to your computer and use it in GitHub Desktop.
example of various uses of hook_form_alter()
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
function um_common_form_alter(&$form, $form_state, $form_id) { | |
// hide split teaser on node forms | |
if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') { | |
$form['body_field']['teaser_include'] = array( | |
'#type' => 'value', | |
'#value' => TRUE, | |
); | |
} | |
// user login block changes | |
elseif(($form_id == 'user_login_block')) { | |
$items = array(); | |
if (variable_get('user_register', 1)) { | |
// change the user register path from "user/register" to "create-account" (node/8542) | |
$items[] = l(t('Create account'), 'create-account', array('attributes' => array('title' => t('Create a free user account.')))); | |
} | |
$items[] = l(t('Forgot password?'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); | |
unset($form['links']); | |
$form['#suffix'] .= theme('item_list', $items); | |
} | |
// prefixing a form with javascript | |
elseif($form_id == 'user_register') { | |
$form['#prefix'] = | |
'<script type="text/javascript"> | |
$(document).ready(function() { | |
$("#editrow-group :checkbox").attr("checked", "checked") | |
}); | |
</script>'; | |
} | |
// hiding some useless form elements | |
elseif($form_id == 'user_profile_form') { | |
$form['blog']['#access'] = FALSE; | |
$form['theme_select']['#access'] = FALSE; | |
$form['block']['#access'] = FALSE; | |
$form['nodewords']['#access'] = FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment