By sykic on
I am creating a new book node/page as below
it works but I can not make it a new book
tried AAAAA and BBBBB below
where do I look in documentation to solve this
better still does anyone know drupal 6.x
// Create a new node
$form_state = array();
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => 'book');
//$node['bid'] = 'new'; // AAAAAA
$form_state['values']['title'] = 'My node robo';
$form_state['values']['body'] = 'This is the body text!';
$form_state['values']['name'] = 'x';
//$form_state['values']['bid']] = 'new'; // BBBBBBB
$form_state['values']['op'] = t('Save');
drupal_execute('book_node_form', $form_state, (object)$node);
Thanks in advance
Sykic
Comments
Add these statements to create book node
What made the difference for me was adding these statements:
$form_state['values']['status'] = 1;
$form_state['values']['type'] = 'book';
$form_state['values']['book']['bid']['value'] = 'new';
$form_state['values']['book']['module']['value'] = 'book';
In my case I was wanting to create a top-level book page that was unpublished because I didn't want its content showing up in site searches, but it turns out that for an unpublished node, the "Add Child Page" link doesn't show up. It would be nice if the online documentation gave a quick official example of how to programmatically create a book node.
John Stith