Tripal v1.0 (6.x-1.0)
|
00001 <?php 00031 function tripal_core_ahah_init_form() { 00032 // If form elements have autocomplete elements returned in 00033 // an ahah call they won't work because the following JS file 00034 // doesn't get included. If we include it first before any 00035 // ahah calls it will be there when we need it. 00036 drupal_add_js('misc/autocomplete.js'); 00037 } 00038 00051 function tripal_core_ahah_prepare_form() { 00052 00053 // Retrieve the form from the cache 00054 $form_state = array('storage' => NULL); 00055 $form_build_id = filter_xss($_POST['form_build_id']); 00056 $form = form_get_cache($form_build_id, $form_state); 00057 00058 // Preparing to process the form 00059 $args = $form['#parameters']; 00060 $form_id = array_shift($args); 00061 $form_state['post'] = $form['#post'] = $_POST; 00062 $form['#programmed'] = $form['#redirect'] = FALSE; 00063 00064 // we don't want to submit the form or have required fields validated on 00065 // an ahah callback. 00066 $form_state['submitted'] = TRUE; 00067 $form['#validate'] = NULL; 00068 $form['#submit'] = NULL; 00069 $form_state['submit_handlers'] = NULL; 00070 $form_state['validate_handlers'] = NULL; 00071 tripal_core_ahah_form_element_disable_validation($form); 00072 00073 // Sets the form_state so that the validate and submit handlers can tell 00074 // when the form is submitted via AHAH 00075 $form_state['ahah_submission'] = TRUE; 00076 00077 // Process the form with drupal_process_form. This function calls the submit 00078 // handlers, which put whatever was worthy of keeping into $form_state. 00079 drupal_process_form($form_id, $form, $form_state); 00080 00081 // You call drupal_rebuild_form which destroys $_POST. 00082 // The form generator function is called and creates the form again but since 00083 // it knows to use $form_state, the form will be different. 00084 // The new form gets cached and processed again, but because $_POST is 00085 // destroyed, the submit handlers will not be called again. 00086 $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); 00087 00088 00089 return $form; 00090 } 00091 00104 function tripal_core_ahah_bind_events() { 00105 00106 // Get the JS settings so we can merge them. 00107 $javascript = drupal_add_js(NULL, NULL, 'header'); 00108 $settings = call_user_func_array('array_merge_recursive', $javascript['setting']); 00109 00110 return array('ahah' => $settings['ahah']); 00111 } 00112 00126 function tripal_core_ahah_form_element_disable_validation(&$form) { 00127 // --START code borrowed from ahah_helper module 00128 foreach (element_children($form) as $child) { 00129 $form[$child]['#validated'] = TRUE; 00130 tripal_core_ahah_form_element_disable_validation($form[$child]); 00131 } 00132 // --END code borrowed from ahah_helper module 00133 }