title: Passing argument in ajax_callback: Return array is not getting populated
body: <p>I am trying to populate the second select box with the all date fields of the first selected content type name in select box. I am using ajax_callback to fetch the selected value by $form_state. I am getting error, which I can't determine why. Can anybody help?</p>
  
  <p>This is the my custom module code.</p>
  
  <pre><code>function mymodule_settings($form, &amp;$form_state){
    $content_type_options = array();
    $result = db_query("SELECT * FROM {node_type}");  
    foreach($result as $record){
      $content_type_options[$record-&gt;type]  =  $record-&gt;name;  
    }
    $form = array();
    $form['content_type'] = array(
      '#title'  =&gt; t('Content Types'),
      '#description'  =&gt; t('Select a content type.'),
      '#type' =&gt; 'select',
      '#options'  =&gt; $content_type_options,
      '#ajax' =&gt; array(
        'event' =&gt; 'change',
        'wrapper' =&gt; 'reg-start-date',
        'callback' =&gt; 'mymodule_datefields_ajax_callback',
        'method' =&gt; 'replace',
      ),
    );
    $form['checkboxes_fieldset'] = array(
      '#title' =&gt; t("Start Date"),
      '#prefix' =&gt; '&lt;div id="reg-start-date"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
      '#type' =&gt; 'select',
      '#description' =&gt; t('Select the date field'),
    );
    $form['submit'] = array(
      '#type' =&gt; 'submit',
      '#value'  =&gt; t('Save'),
    );
    return $form;
  }
  
  function mymodule_datefields_ajax_callback($form, $form_state) {
    $fieldname = $form_state['triggering_element']['#value'];
  
    $field_query = db_query("SELECT fc.field_name FROM {field_config} fc, {field_config_instance} fci
                            WHERE fc.field_name = fci.field_name
                            AND fc.type = 'datetime'
                            AND fci.bundle = '".$fieldname."'");
    $datefield_options = array();
    foreach($field_query as $record){
      $datefield_options = $record;
    }
    return $datefield_options;
    //dpm($form_state, 'AJAX $form_state');
  }
  </code></pre>
  
  <p>Here is the error, which I am getting in popup -</p>
  
  <blockquote>
    <p>An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging
    information follows. Path: /module_dev/?q=system/ajax StatusText: OK
    ResponseText: Fatal error: Cannot use object of type stdClass as array
    in /var/www/module_dev/includes/common.inc on line 5786</p>
  </blockquote>
  
  <p>I went through the /var/www/module_dev/includes/common.inc on line 5786, and this is the code I find there.</p>
  
  <pre><code>function drupal_render(&amp;$elements) {
    // Early-return nothing if user does not have access.
    if (empty($elements) || (isset($elements['#access']) &amp;&amp; !$elements['#access'])) {
      return;
    }
  
    // Do not print elements twice.
    if (!empty($elements['#printed'])) {
      return;
    }
  
    // Try to fetch the element's markup from cache and return.
    if (isset($elements['#cache'])) {
      $cached_output = drupal_render_cache_get($elements);
      if ($cached_output !== FALSE) {
        return $cached_output;
      }
    }
  
    // If #markup is set, ensure #type is set. This allows to specify just #markup
    // on an element without setting #type.
    if (isset($elements['#markup']) &amp;&amp; !isset($elements['#type'])) {
      $elements['#type'] = 'markup';
    }
  
    // If the default values for this element have not been loaded yet, populate
    // them.
    if (isset($elements['#type']) &amp;&amp; empty($elements['#defaults_loaded'])) {
      $elements += element_info($elements['#type']);
    }
  
    // Make any final changes to the element before it is rendered. This means
    // that the $element or the children can be altered or corrected before the
    // element is rendered into the final text.
    if (isset($elements['#pre_render'])) {
      foreach ($elements['#pre_render'] as $function) {
        if (function_exists($function)) {
          $elements = $function($elements);
        }
      }
    }
  
    // Allow #pre_render to abort rendering.
    if (!empty($elements['#printed'])) {
      return;
    }
  
    // Get the children of the element, sorted by weight.
    $children = element_children($elements, TRUE);
  
    // Initialize this element's #children, unless a #pre_render callback already
    // preset #children.
    if (!isset($elements['#children'])) {
      $elements['#children'] = '';
    }
    // Call the element's #theme function if it is set. Then any children of the
    // element have to be rendered there.
    if (isset($elements['#theme'])) {
      $elements['#children'] = theme($elements['#theme'], $elements);
    }
    // If #theme was not set and the element has children, render them now.
    // This is the same process as drupal_render_children() but is inlined
    // for speed.
    if ($elements['#children'] == '') {
      foreach ($children as $key) {
        $elements['#children'] .= drupal_render($elements[$key]);
      }
    }
  
    // Let the theme functions in #theme_wrappers add markup around the rendered
    // children.
    if (isset($elements['#theme_wrappers'])) {
      foreach ($elements['#theme_wrappers'] as $theme_wrapper) {
        $elements['#children'] = theme($theme_wrapper, $elements);
      }
    }
  
    // Filter the outputted content and make any last changes before the
    // content is sent to the browser. The changes are made on $content
    // which allows the output'ed text to be filtered.
    if (isset($elements['#post_render'])) {
      foreach ($elements['#post_render'] as $function) {
        if (function_exists($function)) {
          $elements['#children'] = $function($elements['#children'], $elements);
        }
      }
    }
  
    // Add any JavaScript state information associated with the element.
    if (!empty($elements['#states'])) {
      drupal_process_states($elements);
    }
  
    // Add additional libraries, CSS, JavaScript an other custom
    // attached data associated with this element.
    if (!empty($elements['#attached'])) {
      drupal_process_attached($elements);
    }
  
    $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
    $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
    $output = $prefix . $elements['#children'] . $suffix;
  
    // Cache the processed element if #cache is set.
    if (isset($elements['#cache'])) {
      drupal_render_cache_set($output, $elements);
    }
  
    $elements['#printed'] = TRUE;
    return $output;
  }
  </code></pre>