Submitted by zizo-ch on
salut ,
je suis beginner en drupal, j'ai crée un module de recherche.
Dans ce module , j'ai un formulaire simple ayant un seul textfield, où l'user peut taper un certain code pour chercher un client (son nom,prénom, tél ..) et le résultat s'affiche après avoir clicker sur un bouton "search" en même page en utilisant ajax.
Je sais pas quelle command ajax à utiliser et comment implémenter le tout , là dessous une tentative de ce que j'ai codé
Dans Hook_menu :
$items['search-champs-cin/ajax'] = array(
'title' => t('CIN by AJAX'),
'page callback' => 'recherche_ajax',
'access callback' => TRUE,
'file' => 'inc/search-by-cin.inc'
);
Fonction recherche_ajax :
function recherche_ajax(){
return drupal_get_form ('recherche_ajax_form');
}
function recherche_ajax_form ($form,$form_state){
$form = array();
$form['client'] = array(
'#type' => 'textfield',
'#title' => 'client\'s CIN',
'#size' => 25,
);
$form['output'] = array(
'#prefix' => '<div id="output">',
'#suffix' => '</div>',
'#markup' => '',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('search'),
'#ajax' => array(
'callback' => 'search_form_ajax_callback',
),
);
return $form;
}
function search_form_ajax_callback($form, $form_state) {
$cin = check_plain($form_state['values']['client']);
$commands = array();
$commands[] = array(
'command' => 'callclientcin', // voila quoi mettre là dessus
'elementId' => 'output',
'cin' => $cin,
);
// Send the command to the page.
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
return $page;
}