Clearing cash so that a form re-freshes as if for the first time

  1. function string_fields_form($form, $pid) {
  2.  
  3.     // somewhere about here I ought to force this form to actually destroy any previous ideas it had of itself and start over
  4.     $result = db_query("select slid, name, max_chars, platform FROM {fr_scrn_locations} JOIN {fr_platform} using (pid) where pid = %d", $pid);
  5.  
  6.     $j = '0';
  7.  
  8.     while($scrn_locs = db_fetch_array($result)) {
  9.          $form['loc'.$j] = array(
  10.         '#type' => 'textfield',
  11.         '#size' => '15',
  12.         '#value' => $scrn_locs['name'],
  13.         '#prefix' => '<tr><td class="location-field">',
  14.  
  15.        );
  16.       $form['slid'.$j] = array (
  17.         '#type' => 'hidden',
  18.         '#value' => $scrn_locs['slid'],
  19.         '#suffix' => '</td>',
  20.       );
  21.        $form['max_chars'.$j] = array(
  22.         '#type' => 'textfield',
  23.         '#size' => '4',
  24.         '#value' => $scrn_locs['max_chars'],
  25.          '#ahah' => array(
  26.            'event' => 'blur',
  27.            'path' => 'ahah/strings/platform/'.$j,
  28.            'wrapper' => 'form-wrapper',
  29.          ),
  30.         '#prefix' => '<td class="maxchars-field">',
  31.         '#suffix' => '</td></tr>',
  32.        );
  33.        if ($j == 0 ) {
  34.          $platform = $scrn_locs['platform'];
  35.        }
  36.        $j++;
  37.      }
  38. $form['loc0']['#prefix'] = '<table><tr> <th>field name</th><th>max chars</th></tr><tr><td class="location-field">';
  39.  
  40.          $form['newloc'] = array(
  41.         '#type' => 'textfield',
  42.         '#size' => '15',
  43.         '#prefix' => '<tr><td class="location-field">',
  44.         '#suffix' => '</td>',
  45.       );
  46.        $form['newmax_chars'] = array(
  47.         '#type' => 'textfield',
  48.         '#size' => '4',
  49.         '#value' => $scrn_locs['max_chars'],
  50.          '#ahah' => array(
  51.            'event' => 'blur',
  52.            'path' => 'ahah/strings/newplatform/'.$pid,
  53.            'wrapper' => 'form-wrapper',
  54.          ),
  55.         '#prefix' => '<td class="maxchars-field">',
  56.         '#suffix' => '</td></tr>',
  57.        );
  58.     $form['#prefix'] = '<h2>'.$platform.' Fields</h2>';
  59.     $form['#suffix'] = '</table>';
  60.   return $form;
  61.  
  62. }
  63.  
  64. /*
  65.  * insert the new form field into the db and then give me the form again
  66.  */
  67. function fr_newplatform_ahah($pid) {
  68.  
  69.  $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form');
  70.  $form_state = array('values' => $_POST);
  71.  
  72.    // put newloc and newmax_chars into the db
  73.    $sql = "INSERT INTO {fr_scrn_locations} SET name = '%s', max_chars = %d, pid= %d";
  74.    db_query($sql, $form_state['values']['newloc'], $form_state['values']['newmax_chars'], $pid);
  75.  
  76.   // give me the form again -- but fresh.
  77.   // This should replace everything inside form-wrapper.
  78.   // what's happening though is that I'm not getting the new info, so clearly I'm not really re-doing the form. :(
  79.    $output .= drupal_get_form('string_fields_form', $pid);
  80.  
  81.  
  82.      print drupal_to_js(array('status' => TRUE, 'data' => $output));
  83.   exit;
  84. }