You should check out http://drupal.stackexchange.com/a/54387/4387https://drupal.stackexchange.com/a/54387/4387
function MYMODULE_some_form($form, &$form_state) {
// If the form has been submitted, output something related to the submission
if (!empty($form_state['values']['some_field'])) {
// Get data from database and show second step fields.
$form['user_name'] = array(
'#type' => 'textfield',
// ...
);
}
else {
// Otherwise build the normal form (first step).
$form['user_id'] = array(
'#type' => 'textfield',
// ...
);
}
return $form;
}
function MYMODULE_some_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}