You are here

function rules_admin_form_js in Rules 6

A generic AHAH JS callback. Gets the cached form and passes it to the given callback to alter it. The callback returns the a reference on the to be rendered form, which is rendered and returned to the JS.

1 string reference to 'rules_admin_form_js'
rules_admin_menu in rules_admin/rules_admin.module
Implementation of hook_menu().

File

rules_admin/rules_admin.sets.inc, line 322

Code

function rules_admin_form_js($callback) {
  $form_state = array(
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];

  // Add the new element to the stored form. Without adding the element to the
  // form, Drupal is not aware of this new elements existence and will not
  // process it. We retreive the cached form, add the element, and resave.
  $form = form_get_cache($form_build_id, $form_state);
  $render =& $callback($form);
  form_set_cache($form_build_id, $form, $form_state);
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
  );

  // Rebuild the form.
  $form = form_builder($_POST['form_id'], $form, $form_state);

  // Render the new output.
  print drupal_to_js(array(
    'data' => drupal_render($render),
    'status' => TRUE,
  ));
  exit;
}