Not able to get textfield value to generate a ajax dependent dropdown option I am not able to get the textfield value to generate an ajax dependent dropdown option.That is when i am trying to enter a textfield value in the form and clicking a button to call the ajax function. The form value for the textfield i am getting is blank.Here's the code snippet:

/*
* function to add the images to the gallery
* @param: none
* @return: none
*/
function image_gallery_add($form, &amp;$form_state) {
$form['#tree'] = TRUE;
$form['add_image'] = array(
    '#title' =&gt; t('Add images to gallery'),
    '#type' =&gt; 'fieldset',
);
$form['add_image']['gallery_name'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Please enter the gallery name'),
);

$form['add_to_dropdown'] = array(
    '#type' =&gt; 'button',
    '#value' =&gt; 'Add To Dropdown',      
    '#ajax' =&gt; array(      
        'event' =&gt; 'click',
        'callback' =&gt; 'image_gallery_select_options_callback',
        'wrapper' =&gt; 'dropdown_gallery_replace',
    ),
);  

$form_field_val = isset( $form['values']['add_image']['gallery_name'] ) ?  $form['values']['add_image']['gallery_name'] : '';
$form['add_image']['select_gallery'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; 'Select Gallery',
    // The entire enclosing div created here gets replaced when textfield gallery_name changes
    // is changed.
    '#prefix' =&gt; '&lt;div id="dropdown_gallery_replace"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    // when the form is rebuilt during ajax processing, the $selected variable
    // will now have the new value and so the models will change
    '#options' =&gt; automobile_get_model_dropdown_options($form_field_val),
    '#default_value' =&gt; '',
);

$form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit')
);
return $form;

}
/**
* Handle post-validation form submission.
*/
 function image_gallery_submit($form, &amp;$form_state) {
    $name = $form_state['values']['add_image']['gallery_name'];
     print( $name );exit();
  }

 function automobile_get_model_dropdown_options($key = '') {
     //dpm($key);
   $options = array(
            t($key) =&gt; drupal_map_assoc(array(t($key))),    
        );
     if (isset($options[$key])) {
          return $options[$key];
      }
      else {
           return array();
      }
  }

 function image_gallery_select_options_callback($form, $form_state) {
   return $form['add_image']['select_gallery'];
 }


Can anyone suggests what i am doing wrong? I am attaching a screenshot of the situation too...
Not sure, but from the looks of it (I think) you need to set 

$form['#tree'] = TRUE;


When building your form.