Create AJAX multi step form which changes based on user input I am trying to create a form where initially, the user is presented with just one field, which is their email address. When they click submit, I would like it to be an AJAX submit where I then lookup their email in a custom table in the database and then present them with additional form fields that will either be blank if we do not have their email address in the sytem, or will be pre-populated and ready for them to edit, if we already have them in the system. I was thinking a multi step AJAX form might do the trick, but I don't know if it even needs to be "multi step". Can I accomplish this with just a standard AJAX submit? I just can't figure out how to show/populate those additional fields after they submit the form. This is what I have so far, I just can't figure out how to only show the additional fields AFTER the submit and verification process:

/**
 * Implements hook_form().
 */
function _vista_form($form, &amp;$form_state) {

  $form = array();

  $form['email'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Email',
    '#required' =&gt; TRUE,
  );

  $form['wrapper'] = array(
    '#markup' =&gt; '',
    '#prefix' =&gt; '&lt;div id="ajax_wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );


  // all of the fields below this are the ones that I would like to show ONLY after I look them up and then I can prefill them in or not
  $form['id'] = array(
    '#type' =&gt; 'hidden',
    '#value' =&gt; 0,    
  );

  $specialties = db_query("SELECT specialty_code, specialty_name FROM {specialties_vista}")-&gt;fetchAll();
  $default_specialties = explode('^', '');

  $specialty_options = array();
  foreach ($specialties as $specialty) {
    $specialty_options[$specialty-&gt;specialty_code] = $specialty-&gt;specialty_name;
  }

  $form['specialty'] = array(
    '#type' =&gt; 'select',
    '#multiple' =&gt; TRUE,
    '#size' =&gt; 10,
    '#title' =&gt; 'Specialty',
    '#description' =&gt; 'Hold Control or Shift while clicking to select multiple specialties',
    '#options' =&gt; $specialty_options,    
    '#empty_option' =&gt; '-All-',
    '#empty_value' =&gt; 'all',
    '#default_value' =&gt; $default_specialties,
  );

  $type_options = array(
    'VISTA-HealthCare-Partners-Government' =&gt; 'Vista Healthcare Partners',
    'International' =&gt; 'International Locum Tenens',
    'Permanent' =&gt; 'Permanent Physician',
    'US-Locum-Tenens' =&gt; 'US Locum Tenens',
  );   

  $form['job_type'] = array(
    '#type' =&gt; 'checkboxes',
    '#multiple' =&gt; TRUE,
    '#title' =&gt; 'Type of Job',    
    '#options' =&gt; $type_options,    
    '#empty_option' =&gt; 'Choose a placement type',
    '#empty_value' =&gt; 'all',
    //'#default_value' =&gt; $type_selected,
  );  

  $form['active'] = array(
    '#type' =&gt; 'checkbox',    
    '#title' =&gt; 'Subscribe/Unsubscribe',    
    '#default_value' =&gt; 1,
  );

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
    '#attributes' =&gt; array('class' =&gt; array('submit')),
    '#ajax' =&gt; array(
      'callback' =&gt; '_display_form',
      'wrapper' =&gt; 'ajax_wrapper',      
      'effect' =&gt; 'fade',
    ),
  );

  return $form;
}

function _display_form($form, $form_state) {
  //do database lookup here and set some variables? Not sure.
  return $form['wrapper'];
}
You need to keep track of the step you're in. The first time a user hit's the form you would initialize a variable, say $stepand give it the value 1. On submit you augment that value to be in step 2 on the form rebuild. In the form builder itself (_vista_form()) you add form items depending on the current step. The same goes for validation and submit handlers. Usually you would use switch statements.

Have a look at this very complete tutorial: http://www.jaypan.com/tutorial/drupal-7-ajax-driven-multi-step-forms-non-javascript-fallback