Disclaimer - I've only just started using drupal and am also new to PHP. So there may well be a better solution to my original problem. But anyway...
I'm integrating another application (a content source) with drupal by adding a button that triggers a browser pop with a URL like http://drupalhost/?q=node/add/story&edit[title]=The%20Story%20Title
which opens a node creation pane with the title or body, or other fields already filled in. (Actually I've extended flexinode a little so I can default file uploads and such, but that's a different question.)
When you've already got a session running, this works fine. But if the button triggers a new session, it correctly redirects to the login page first, then drupal_goto()s the add page once you've done so. But in the final redirection, it only preserves the 'q' parameter, none of the others, so you don't get any defaults.
I made a little change (below) to user.module::user_block() which preserves the rest of the parameters - this seems to be working fine but as I say I may well be breaking something else.
Any thoughts on whether this is the right approach and/or the right fix?
if (empty($edit)) {
//PDS original loses trailing parameters,
//PDS let's try to save them
$edit["destination"] = $_GET["q"];
foreach ($_GET as $param => $value) {
if ($param != "q") {
if (is_array($value)) { // e.g. edit[]...
foreach ($value as $key => $val) {
$edit["destination"] .= "&{$param}[{$key}]={$val}";
}
} else {
$edit["destination"] .= "&{$param}={$value}";
}
}
}
}