I'm using some javascript as a makeshift bookmarklet, and all is well. When a user is logged in and visits another site, they can click their bookmarklet and they get the title and url prepopulated in their add/node/web-site-entry form.
However, if the user is not logged in, visits a site, and clicks their bookmarklet, they get sent to a 403 page, where a login form is. They then enter their details and are directed to the add/node/web-site-entry form, however, the form seems to drop the ?edit[title]=Kidzinfo&edit[field_web_site_link][0][url]=http%3A%2F%2Flocalhost%2Fk%2F, instead directing only to node/add/web-site-entry, thus dropping the prepopulated info and making the bookmarklet somewhat useless unless a user is persistently logged in.
Viewing the source of the login form at my 403 page, I can see that the fragment is in the action, so I'm assuming that in between the user clicking 'login' and the redirection to login form, the url drops its fragment.
Basically, if I can prevent the fragment from being stripped, I believe all should work well. Any advice is appreciated.
Comments
I meant query
Wherever I mentioned fragment, I meant to say query, if that helps.
A fix
I've solved this myself with a small hack (a couple lines) to user.module and to provide valid urls, I used nodeformtemplate to create variables for my cck fields that allow me to substitute long ugly edit[text][text][text] with whatever I want.
I eventually found that in function drupal_get_destination(), there's an if/else with the if not appending the query string in a url, while the else does, so, adding .$path and a couple variables, I was able to achieve what I wanted. See below to compare:
Before my hack:
<?phpfunction drupal_get_destination() {
if (isset($_REQUEST['destination'])) {
return 'destination='. urlencode($_REQUEST['destination']);
}
else {
// Use $_GET here to retrieve the original path in source form.
$path = isset($_GET['q']) ? $_GET['q'] : '';
$query = drupal_query_string_encode($_GET, array('q'));
if ($query != '') {
$path .= '?'. $query;
}
return 'destination='. urlencode($path);
}
}
?>
After:
<?phpfunction drupal_get_destination() {
if (isset($_REQUEST['destination'])) {
$path = isset($_GET['q']) ? $_GET['q'] : '';
$query = drupal_query_string_encode($_GET, array('q'));
if ($query != '') {
$path .= '?'. $query;
}
return 'destination='. urlencode($_REQUEST['destination'].$path);
}
else {
// Use $_GET here to retrieve the original path in source form.
$path = isset($_GET['q']) ? $_GET['q'] : '';
$query = drupal_query_string_encode($_GET, array('q'));
if ($query != '') {
$path .= '?'. $query;
}
return 'destination='. urlencode($path);
}
}
?>
I suppose I could improve this by completely removing the if/else, because the 2 seem to duplicate each other now, the exception being the else doesn't return $_REQUEST['destination']
To summarize, now, a user can add my bookmarklet, log out, surf and click the bookmarklet when they find something to add. Now, before this, being logged out resulted in the values not passing to the form after log in, but this fixes it. Now if the user has to log in, the values still get passed to the form after they log in.
I may not be very clear above and am clearly wrong to edit the core, but this is the best fix I could come up with.
Sounds like a great fix, I
Sounds like a great fix, I ran into this myself today!
Please create an issue and post a patch for core: http://drupal.org/node/add/project-issue -- this is the type of hack to core that can be fixed for the next release of Drupal :-)
not user.module, common.inc
Looking at this, I can't remember why I wrote user.module above, but it sure confused me when I went back to create a patch (http://drupal.org/node/158159) as suggested.
Anyone reading this thread will want to make this change in common.inc, function drupal_get_destination() isn't in user.module
if you are submitting from a
if you are submitting from a form just attach this in your form and everyhing should work, i guess:
$form['#action'] = url($_GET['q'], array('query' => drupal_get_destination()));