I'm creating a module that adds my own fields to the registration page using hook_user(). I'm trying to make it so that which fields are created depends on whether a $_SESSION variable is set, so I have the following (simplified down) code called from hook_user() when $op = 'register':
function dm_teams_register_teams($edit, $account, $category) {
if($_SESSION['dm_teams']['tid']) {
$form['team']['tid'] = array(
'#type' => 'hidden',
'#value' => $_SESSION['dm_teams']['tid'],
);
unset($_SESSION['dm_teams']['tid']);
} elseif($_SESSION['dm_teams']['new_team']) {
$form['team']['name'] = array(
'#type' => 'textfield',
'#title' => t('Team Name'),
'#size' => 60,
'#maxlength' => 100,
'#required' => TRUE,
);
unset($_SESSION['dm_teams']['new_team']);
} else {
$form['team']['find'] = array(
'#type' => 'button',
'#value' => 'Find a Team',
'#submit' => FALSE,
);
}
return $form;
}
It shows up very nicely the first time, but then if there are errors, no matter what the else statement shows up (because the $_SESSION vars have been unset). Not only that, but I checked the $edit array in my validate function, hook_user($op = 'validate'), and the information that was in $form['team']['tid'] or $form['team']['name'] does not appear. I do not understand that because the form generated fine.