I am trying to use drupal ajax to test if an email address from the form it is in my database. For that i have altered the form and added the following line to the element:

   $form['field_radio']['#ajax'] = array
       'callback' => '_get_member',
       'progress' => array('type' => 'throbber', 'message' => '')

and the callback function:

function _get_member($form, $form_state){

     $sid = $form_state['values']['details']['sid'];
    $commands[] = ajax_command_alert("Hello World");    

    return array(
    'type' => 'ajax',
    'commands' => $commands

As you can see from the callback i just want to return an alert message but it does not work. The callback is called because i have tested using watchdog but the alert popup never fires. Why ?


'wrapper' is a required key for #ajax on form elements, you're probably just missing that. From the docs

This property is required for using AJAX requests in on a form element

If you add the wrapper it should work:

$form['field_radio']['#ajax'] = array (
   'callback' => '_get_member',
   'progress' => array('type' => 'throbber', 'message' => ''),
   'wrapper' => 'some-element-id'
  • i have added the wrapper key but still the alert is not fired! Is there a way to grab variables from the result with javascript ? – Vlasin Jan 9 '13 at 11:07
  • In the ajax response i found the text : "command":"alert", "text":"Based on your email, you are not a Member yet!" – Vlasin Jan 9 '13 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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