2013-07-14 2 views
0

J'ai créé un fichier .module qui inclut un formulaire et un rappel ajax. Voici un code simple du fichier .module:Drupal 7 ajax et session

function form_registration_form($form, &$form_state) { 
     $form['registration']['email'] = array(
     '#type'  => 'textfield', 
     '#required' => TRUE, 
     '#size'  => 44, 
     '#maxlength' => '80', 
     '#attributes'=> array('placeholder' => 'Email','data-email'=>'','data-min-chars'=>'5'), 
    ); 
     $form['registration']['password'] = array(
     '#type'  => 'password', 
     '#required' => TRUE, 
     '#size'  => 44, 
     '#maxlength' => '80', 
     '#attributes'=> array('placeholder' => 'Password'), 
    ); 
     $form['registration']['submit'] = array(
     '#value'  => 'SIGN IN', 
     '#type'  => 'submit', 
     '#submit' => array('form_registration_handler'), 
     ); 
     return $form; 
} 
and in the function form_registration_handler I create a session (name it test). 
Here is the ajax menu call back function: 

function mymodule_menu() { 

    $items['ajax/innerAction'] = array(
     'title' => 'Browser Inner Action', 
     'page callback' => 'innerActionCallBack', 
     'access arguments' => array('access content'), 
     'type' => MENU_CALLBACK, 
    ); 

    return $items; 
} 

function innerActionCallBack() { 
    header('Access-Control-Allow-Origin: *'); 
    drupal_session_start(); 
    print session_id(); 
} 

Cette fonction est utilisée sur mon fichier page.tpl.php pour créer un ajax au serveur. Le problème ici est quand j'appelle l'ajax, l'id de session est différent quand j'actualise le navigateur et je ne peux pas récupérer le test de session que j'ai créé plus tôt. Savez-vous ce qui se passe ici. Toute aide est vraiment appréciée.

Répondre

0

Ok, donc j'ai trouvé la réponse. Je dois d'abord connecter l'utilisateur à Drupal pour que Drupal puisse récupérer le bon ID de session.