Hello again,
I've come across a roadblock attempting to modify the user forms using hook_form_alter in Drupal 7.
$form_id is empty.
I don't know why either version fails. Any pointers would be great.
function cg_volunteer_form_alter(&$form_id, &$form) {
$cg_stuff = array();
if ($form_id == 'user_profile_form') {
$cg_stuff['user']['cg_first_name'] = array (
'form' => array(
'#type' => 'textfield',
'#title' => t('demo'),
'#size' => 10,
),
);
};
if ($form_id == 'user_register_form') {
$cg_stuff['user']['cg_first_name']= array (
'#type' => 'textfield',
'#title' => t('demo'),
'#description' => t('Great effort!'),
'#size' => 20,
);
}
watchdog('cg_volunteer', 'cg form_alter has run %formly', array('%formly' => $form_id), WATCHDOG_NOTICE, $link = NULL);
return $cg_stuff;
};
Comments
Have a look at the docs &
Have a look at the docs & examples: http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
You're not supposed to be returning anything, but rather modifying
$form.---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
Thanks! One more
Once you gave me the clue about modifying form, it works! Thanks.
Now, I've got the new form element, but it always appears towards the bottom of the form. How do I put it on top of all of the other elements on a user page? '#weight' has no effect.
Do I need to use array_unshift to get the form on top?
The #weight property is used
The
#weightproperty is used to adjust order.... will put the element at the top of the form.
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com