作为表单
的一部分的代码 $form['search'] = array(
'#type' => 'textfield',
'#title' => 'Search',
'#description' => 'Search by',
'#ahah' => array(
'event' => 'keyup',
'path' => 'admin/store/products/group/autocomplete',
'wrapper' => 'products-search-wrapper',
'method' => 'replace',
'effect' => 'none', //also available: fade, slide
'progress' => array(
'type' => 'throbber', //also available: bar
'message' => 'Loading results...',
),
),
);
$form['search_results'] = array(
'#type' => 'markup',
'#value' => '<div id="products-search-wrapper"></div>',
);
回调
function tf_cart_admin_group_autocomplete($search = NULL)
{
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$search = $form_state['post']['search'];
print drupal_json(array('status' => TRUE, 'data' => "TEST AHAH $search" ));
exit;
}