Drupal 6, how to publish node from code -


how publish node php code? tried simple query db_query("update {node} set status = 1 nid = %d", $nid); doesn't work. scenario: default nodes unpublished. i'm altering edit-node form add textfield. if user enters right code node become published. adding submit function in form_alter , in function checking code , if it's right trying update node status published.

<?php // load node object $node = node_load($nid); // set status property 1 $node->status = 1; // re-save node node_save($node); ?> 

also, saw comment of using $form['nid']['#value']. sure variable holds node id value? executing code on submit handler of form, means using like: $form_state['values']['nid'] value of $form['nid'] element.

example:

<?php function mymodule_myform() {   $form = array();   $form['nid'] = array(     '#type' => 'textfield',     '#title' => 'node id publish'   );   $form['submit'] = array('#type' => 'submit', '#value' => 'submit'); }  function mymodule_myform_submit($form, &$form_state) {   $node = node_load($form_state['values']['nid']);    if ($node) {     $node->status = 1;     node_save($node);   } } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -