Ajax User login failing with "Username field is required", "Password field is required" I am trying to set up an AJAX login box for a site, using the following code:

function THEME_form_user_login_alter (&amp;$form, &amp;$form_state) {
   $form['actions']['submit']['#ajax'] = array(       

        'callback' =&gt; 'user_login_submit',
        'wrapper' =&gt; 'user-login',
        'effect' =&gt; 'fade',
        'speed' =&gt; 'fast',
        'method' =&gt; 'replace',
    );
}


I get an Ajax error on form validation, I am thinking I am using the wrong callback but I can't figure out which one would work, and I couldn't find any example out there.. Any suggestion?

This is the error message:


  An AJAX HTTP error occurred. HTTP Result Code: 200
  Debugging information follows.
  Path: /parce/system/ajax
  StatusText: OK
  ResponseText: [{"command":"settings","settings":{"basePath":"/parce/","pathPrefix":"","ajaxPageState":{"theme":"parce","theme_token":"PFPo8K2w-7tUSndM3muIGW4Gpq-X8TT4-fR4ZmVcxD0","css":[]}},"merge":true}]
  Uncaught exception thrown in session handler.
  PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048
  Column "uid" cannot be null:
  INSERT INTO {sessions} (sid, ssid, uid, cache, hostname, session, timestamp) VALUES
  (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6);
  Array(
   [:db_insert_placeholder_0] => -nLyLCVNED-8LSAd6NoZ8znhzZAoUVMNutGmi7ObAQ8
   [:db_insert_placeholder_1] =>
   [:db_insert_placeholder_2] =>
   [:db_insert_placeholder_3] => 0
   [:db_insert_placeholder_4] => 183.16.201.97
   [:db_insert_placeholder_5] => messages|a:1:{s:5:"error";a:2:{i:0;s:27:"Username field is required.";i:1;s:27:"Password field is required.";}}
   [:db_insert_placeholder_6] => 1308899744
  ) in
   _drupal_session_write() (line 203 of /home/sites/parce/includes/session.inc).
It looks like user_login_submit doesn't work well when called as an AJAX callback. The error you receive is because Drupal tries to create a session for the user that should be logged in, but no values for uid is present, which is required.

I believe that Drupal will call the form submit hooks when the form is submitted by ajax, so you might be able to simply add an empty callback function.

Alternatively you will need to call the form submit functions yourself, which should fix the problem.