How to call Ajax callback on form submit to display results
Basic working code example for validation or submit form with ajax.

 function afaf_custom_form($form, &amp;$form_state) {
  $form['d_id'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('D id'),
    '#size' =&gt; 60,
    '#maxlength' =&gt; 60,
    '#required' =&gt; TRUE,

  );
  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Search'),
    '#ajax' =&gt; array(
     'callback' =&gt; 'v_custom_ajax_handler',
     'wrapper' =&gt; 'display-dept-ajax',
   ),
  );

  $form['#prefix'] = '&lt;div id="display-dept-ajax"&gt;';
  $form['#suffix'] = '&lt;/div&gt;';
  if (isset($form_state['values'])) {
    $form['output'] = array('#markup' =&gt; 'thankyou message');
  }
  return $form;
}

function afaf_custom_form_submit($form, &amp;$form_state) {
  $form_state['rebuild'] = TRUE;
}

function v_custom_ajax_handler($form, $form_state) {
  $form_errors = form_get_errors();
  if ($form_errors) {
    return $form;
  }
  else {
    $thank_you_html = drupal_render($form['output']);
    $commands[] = ajax_command_insert(NULL, $thank_you_html);
    return array(
      '#type' =&gt; 'ajax',
      '#commands' =&gt; $commands,
    );
  }
}