I am trying to set up an AJAX login box for a site, using the following code:

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

        'callback' => 'user_login_submit',
        'wrapper' => 'user-login',
        'effect' => 'fade',
        'speed' => 'fast',
        'method' => '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);
[:db_insert_placeholder_0] => -nLyLCVNED-8LSAd6NoZ8znhzZAoUVMNutGmi7ObAQ8
[:db_insert_placeholder_1] =>
[:db_insert_placeholder_2] =>
[:db_insert_placeholder_3] => 0
[:db_insert_placeholder_4] =>
[: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 would help if you could post the actual error. Have you tried posting the same code in a module?
    – googletorp
    Commented Jun 24, 2011 at 6:09
  • @googetrop I updated my question with the error i receive
    – silkAdmin
    Commented Jun 24, 2011 at 7:16

2 Answers 2


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.


As googletorp mentioned, submit functions are not ajax callbacks.

An ajax callback is a function that returns the part of the form that should be displayed withing the given specified wrapper or executes so called ajax commands (http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax_commands/7)

See also http://api.drupal.org/api/examples/ajax_example--ajax_example.module/7

  • Yes thank you guys, it turns out that i just need to use this call back ajax_process_form, it s now working.
    – silkAdmin
    Commented Jun 24, 2011 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.