I am using the ahah helper as I couldn't seem to get my dropdown lists to depend on each other anyother way in Drupal 6. Below is my code, I can hard code the changes so that the second dropdown populates with the correct values. However when I select a value from dropdown one An error occurred. /drupal1/?q=ahah_helper/dependent_select (no information available).

There is no error in my httpd log. All i have changed is, added a DB connection, two queries to populate $grouplist and $sitelist with the latter referencing the selected value from list one for the WHERE clause in the query. I am still passing a ID number which refers to a value. See directly below for the previous code that worked in the example. I have taken the $select1_selected and used that within the query that populates dropdown2.

Dropdown one options = '#options' => array( 1=> 'USA', 2 => 'German'),

Dropdown two options =

 if ( $select1_selected == 1 ) {
    $select2_options['11'] = 'GM';
    $select2_options['12'] = 'Ford';
} else if ( $select1_selected == 2 ) {
    $select2_options['21'] = 'VW';
    $select2_options['22'] = 'Audi';

My Code:

    function ahahdrop_menu(){
        $items = array();
        $items['ahahdrop'] = array(
        'title' => 'Ahah Drop menu',
        'type' => MENU_NORMAL_ITEM,
        'access arguments' => array('access ahahdrop'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array ('ahahdrop_form'),
return $items;

    function ahahdrop_form( $form_state ) {
        $form = array();
    // this is standard method for register ahah helper for current form   
        ahah_helper_register($form, $form_state);

    // we are building fieldset 
        $form['dependent_select'] =
         '#type'   => 'fieldset',
         '#title'  => t('Dependent Select '),
         '#prefix' => '<div id="dependent-select-wrapper">',  // specify wrapper element id
         '#suffix' => '</div>',
         '#tree'   => TRUE,  // this should be TRUE

    // provide default option for select one
        $select1_selected = 11;

    // $form_state['storage'], contains ahah submitted values
        if ( isset($form_state['storage']['dependent_select']['select1']) ) {
    // get 'select1' selected option
        $select1_selected =  $form_state['storage']['dependent_select']['select1'] ;

 try {  $conn = new PDO("pgsql:host=localhost port=5432 dbname=riverflies_gis", "opengeo", "opengeo");
        echo "Connected";
            echo "<br>";
        catch(PDOException $e) {
            echo $e->getMessage();

        $stmt2 = $conn->prepare("SELECT group_id, rmigroupname FROM rmi_group_tbl ");
            if ($stmt2->execute()) {
                    $grouplist = array();
                        foreach ($stmt2 as $row) {
                        $grouplist[$row->group_id] = $row->rmigroupname;

        $stmt3 = $conn->prepare("SELECT site_id, sitename, group_id FROM sites_tbl WHERE group_id = $select1_selected ");
            if ($stmt3->execute()) {
                    $siteslist = array();
                        foreach ($stmt3 as $row) {
                        $siteslist[$row->site_id] = $row->sitename;

    $form['dependent_select']['select1'] =
         '#type'    => 'select',
         '#title'   => t('Select 1'),
         '#options' => $grouplist,
         '#default_value' => array( $select1_selected ),
         // specify ahah event
         '#ahah' => array(
                        'event'   => 'change',  //  this is onchange event of select
                        'path'    => ahah_helper_path(array('dependent_select')),
                        // provide temporary path
                        // no need to register it through hook_menu
                        'wrapper' => 'dependent-select-wrapper',
                        // provide the wrapper of element
                        // here we have given the id of fieldset

    $form['dependent_select']['select2'] =
         '#type'    => 'select',
         '#title'   => t('Select 2'),
         '#options' =>  $siteslist // set dynamic options        

    $form['submit'] =
        array( '#type'  => 'submit',
           '#value' => t('Save')

    return $form;

1 Answer 1


See the ahah drop down examples in drupal examples module

  • This doesn't really help, as i have taken the code from the examples, the examples are for hard coded lists, which i can get working. It is the SQL populated lists where I am having issues.
    – Tom
    Aug 7, 2013 at 9:40
  • check your code that you are providing the correct options to the lists.May be the error was not due to these Aug 7, 2013 at 9:50
  • I know the options are correct, because if i hard code the selection of option1, option two only displays the relating values from the DB. Im having a look at the ahah example again to see if i missed anything.
    – Tom
    Aug 7, 2013 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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