CTools modal return incorrectly return html instead of ajax commands I am trying to create custom login form using Ctools modal window. There seems to be a problem upon submitting the correct username and password. 

The page callback function is supposed to return a JSON of the ajax commands. Right now it is instead returning an AJAX error, with the response as the HTML text of the user profile page (eg. user/123). The return code is 200. Which seems to suggest that the function got redirected to the user page, which shouldn't happen for AJAX call. I might be wrong on this though.

I have used the same pattern for other forms, such as register form and reset password, which work fine. Anybody has any idea why this is happening? Thank you all.

Here are my codes:

hook_menu:

$items['modal/user_login/%ctools_js'] = array(
    'file'=&gt; 'popup_login.inc',
    'page callback' =&gt; 'my_module_user_login',
    'page arguments' =&gt; array(2),
    'access arguments' =&gt; array('access content'),
    'type' =&gt; MENU_CALLBACK,
);
$items['test_ctool_popup'] = array(
    'title' =&gt; "Test Login Popup Page",
    'page callback' =&gt; 'my_module_test_login_page',
    'access arguments' =&gt; array('access content'),
    'type' =&gt; MENU_NORMAL_ITEM,
);


page callback function: my_module_test_login_page

function my_module_test_login_page () {
    ctools_include('ajax');
    ctools_include('modal');
    ctools_modal_add_js();
    ctools_add_js('ajax-responder');
    if(!user_is_logged_in()){
        $link = ctools_modal_text_button(
            'Log in modal', 
            'modal/user_login/nojs', 
            'Log in');
    } else {
        $link = 'user already logged in';
    }

    return &lt;&lt;&lt; HTML
    &lt;div class="modal-link"&gt;$link&lt;/div&gt;
HTML;
}


modal callback function: my_module_user_login

function my_module_user_login ($js = null) {
if(!$js){
    return drupal_get_form('my_module_user_login_form');
}
ctools_include('ajax');
ctools_include('modal');
$form_state = array(
    'ajax' =&gt; TRUE,
    //'title' =&gt; t('Log In')
);
$output = ctools_modal_form_wrapper('my_module_user_login_form',$form_state);
if (!empty($form_state['ajax_commands'])) {
    ctools_add_js('ajax-responder');
    $output = $form_state['ajax_commands'];
}
print ajax_render($output);
}


form function my_module_user_login_form

function my_module_user_login_form ($form, &amp;$form_state) {
    $login_form = user_login($form, $form_state);
    $login_form['name']['#title'] = t('Email');
    $login_form['name']['#size'] = 25;
    $login_form['pass']['#size'] = 25;
    //$login_form['#validate'][] = '_ewp_property_user_login_form_validate';
    return $login_form;
}


submit function my_module_user_login_form_submit

function my_module_user_login_form_submit ($form, &amp;$form_state) {
    user_login_submit ($form, $form_state);
    unset($form_state['redirect']);
    $commands = array();
    $commands[] = ctools_modal_command_dismiss(t('Log In Successful.'));
    $commands[] = ctools_ajax_command_reload();
    //$commands[] = ctools_ajax_command_redirect('modal/dismiss_modal/nojs');
    $form_state['ajax_commands'] = $commands; 
}
Turns out the offending part is not the logic, but the function name. The my_module_user_login_form function happens to be a invoke hook form, which interferes with the modal.

Changing the function name solved the problems.