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 235
<?php
function book_form_update() {
// Load the form based upon the $_POST data sent via the ajax call.
list($form, $form_state) = ajax_get_form();
$commands = array();
$bid = $_POST['book']['bid'];
// 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($form['values']['form_build_id'], $form, $form_state);
// Build and render the new select element, then return it in JSON format.
$form_state = array();
$form = form_builder($form['form_id']['#value'], $form, $form_state);
$commands[] = ajax_command_replace(NULL, drupal_render($form['book']['plid']));
}
// @todo: We could and should just return $form['book']['plid'] and skip the
// ajax_command_replace() above. But for now, this provides a test case of
// returning an AJAX commands array.
return array('#type' => 'ajax_commands', '#ajax_commands' => $commands);
}
?>Login or register to post comments 