book_form_update

Versions
6 – 7
book_form_update()

AJAX callback to replace the book parent select options.

This function is called when the selected book is changed. It updates the cached form (either the node form or the book outline form) and returns rendered output to be used to replace the select containing the possible parent pages in the newly selected book.

Parameters

$build_id The form's build_id.

$bid A bid from from among those in the form's book select.

Return value

Prints the replacement HTML in JSON format.

Code

modules/book/book.pages.inc, line 232

<?php
function book_form_update() {
  $bid = $_POST['book']['bid'];
  if ($form = form_get_cache($_POST['form_build_id'], $form_state)) {

    // Validate the bid.
    if (isset($form['book']['bid']['#options'][$bid])) {
      $book_link = $form['#node']->book;
      $book_link['bid'] = $bid;
      // Get the new options and update the cache.
      $form['book']['plid'] = _book_parent_select($book_link);
      form_set_cache($_POST['form_build_id'], $form, $form_state);

      // Build and render the new select element, then return it in JSON format.
      $form_state = array();
      $form['#post'] = array();
      $form = form_builder($form['form_id']['#value'] , $form, $form_state);
      $output = drupal_render($form['book']['plid']);
      drupal_json(array('status' => TRUE, 'data' => $output));
    }
    else {
      drupal_json(array('status' => FALSE, 'data' => ''));
    }
  }
  else {
    drupal_json(array('status' => FALSE, 'data' => ''));
  }
  exit();
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.