use ahah to do ajaxy updates on individual feeds in a translation tool.

  1. // The story so far...
  2. function fringslate_menu() {
  3.  /*
  4.   * Lots of irrelevant menu entries
  5.   * ...and then:
  6.   */
  7.  
  8.   $items['strings/js'] = array(
  9.     'type' => MENU_CALLBACK,
  10.    'title' => 'administer fring strings',
  11.     'page callback' => "fr_strings_admin_ajax",
  12.     'access arguments' => array('create strings'),
  13.   );
  14. }
  15.  
  16. function fr_strings_admin_form($form_id, $strings) {
  17.    foreach($strings as $string){
  18.      if(!empty($string['nid'])) {
  19.         $form['str_key'.$string['nid']] = array(
  20.         '#type' => 'textfield',
  21.         '#size' => '20',
  22.         '#default_value' => $string['str_key'],
  23.         '#ahah' => array(
  24.           'event' => 'change',
  25.           'path' => 'strings/js',
  26.          )
  27.        );
  28.       /*
  29.        * some other form fields
  30.        * ...
  31.        */
  32.    }
  33.  
  34.   return $form;
  35. }
  36.  
  37. function fr_strings_admin_ajax(){
  38.  
  39. //just testing this out to learn how it works
  40.  $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form');
  41.  $form = $cache->data;
  42.  $form_state = array('values' => $_POST);
  43.  
  44. // for right now I'm writing to a file so that I can see what's going on back there
  45. $handle = fopen("/home/lisha/ajax.txt", "w");
  46.  
  47.  
  48.   // here's where I want to see what's going on so that I can figure out what to write next
  49.  
  50. $output = drupal_render($form) ; //this gives me a form with NO names or ids... WHY?? Oh, dear.
  51.  fwrite($handle, $output);
  52.  fclose($handle);
  53.   print drupal_to_js(array('status' => TRUE, 'data' => $output));
  54.   exit;
  55.  
  56.  
  57. }