Drupal 6

When node_load won't load, and the anonymous user has vanished

Use these two SQL commands to repair your Drupal 6 site to restore the anonymous user database record:

INSERT INTO users (name, mail) VALUES ('', '');
UPDATE users SET uid=0 WHERE name='';

The symptoms you'll see that tip you off that this is needed:

  1. node_load() is not loading nodes that you can prove are in the node table.
  2. node_delete() is not deleting nodes that you can prove are in the node table.
  3. The query SELECT * FROM users WHERE uid=0; returns zero rows.

Redirect to "destination" after submitting a multi-step Drupal form

For the HelpInject module I needed a multi-step form. This is pretty easy in Drupal 6. The problem I encountered was that the “destination” parameter was no longer being honored, and the form was submitting to itself after the last step. It was supposed to be redirecting to “destination”. Here’s the code that made it work. The tip is to unset $form_state['storage'] after you’re done with it because for some reason that’s FAPI’s litmus test for whether or not to redirect.

<?php
// The form is built like this
function foobar_form(&$form_state, $type) {
  if (empty(
$form_state['storage']['foo'])) { } else {  }
}        

// The submit handler follows a similar pattern.
function foobar_form_submit($form, &$form_state) {
  if (empty(
$form_state['storage']['foo'])) {
   
$form_state['storage']['foo'] = $form_state['values']['foo'];
   
$form_state['rebuild'] = TRUE;
  } else {
    ... do
CRUD ...
   
// if you want your form to respect destination,
    // unset the storage.
   
unset($form_state['storage']);
  }
}
?>

Syndicate content