Fix for Fix for AHAH callback in Drupal 5

  1. <?php
  2. /**
  3.  * Menu callback; format=text/json; generates and outputs the appropriate HTML.
  4.  */
  5. function hierarchical_select_json() {
  6.   // We are returning Javascript, so tell the browser. Ripped from Drupal 6's
  7.   // drupal_json() function.
  8.   drupal_set_header('Content-Type: text/javascript; charset=utf-8');
  9.  
  10.   $form_id = $_POST['form_id'];
  11.   $hs_form_build_id = $_POST['hs_form_build_id'];
  12.  
  13.   // Collect all necessary variables.
  14.   $cached = cache_get($hs_form_build_id, 'cache');
  15.   $storage = unserialize($cached->data);
  16.  
  17.   // Retrieve and process the form.
  18.   $form = call_user_func_array('drupal_retrieve_form', $storage['parameters']);
  19.   drupal_prepare_form($form_id, $form);
  20.  
  21.   // Render only the relevant part of the form (i.e. the hierarchical_select
  22.   // element).
  23.   $part_of_form = hierarchical_select_get_form_element($form, $storage['parents']);
  24.   $output = drupal_render($part_of_form);
  25.  
  26.   // TODO: http://drupal.org/node/235932. This is why we're continuing to
  27.   // use JSON as the response format and not HTML.
  28.  
  29.   print drupal_to_js(array(
  30.     'output' => $output,
  31.   ));
  32.   exit;
  33. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.