When setting the redirect path in hook_user_login(), if I set $form_state['redirect'] as an array with query params
$form_state['redirect'] = array(
'node/123',
array(
'query' => array(
'foo' => 'foo',
'bar' => 'bar',
),
),
);
the array gets run through url twice. First in _ajax_register_execute_form() and the second in ctools_ajax_command_redirect(). When the query parameters are included directly in the path, the full url gets run through drupal_encode_path() which breaks the query path.
http://example.com/node/123%3Ffoo%3Dfoo%26bar%3Dbar
vs
http://example.com/node/123?foo=foo&bar=bar
I believe the attached patch fixes the problem.
Issue fork ajax_register-2541456
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
akkina CreditAttribution: akkina as a volunteer commentedIt returned a URL (
/ode/123?foo=foo&bar=bar
) which was removed a first charactern
when I applied this patch.I'm wondering why a first character (leading slash) needs to be removed from a URL.
By the way, I've got another solution, so I'll attach it here.
Comment #2
akkina CreditAttribution: akkina as a volunteer commentedIt seems like removing leading slash from a URL is no longer necessary.
Therefore, I'll attach the updated patch.
Comment #5
dmytro-aragornIn my case login page has a destination URL param with additional query params. And after the login form submission user was redirected to the non-existing page because query params from destination URL weren't encoded.
It's happen because the destination param is set to the
ctools_ajax_command_redirect()
function which additionally callurl()
with where URL and query params are set as a single string.To fix that need to split the redirect URL and possible URL params abs sent them as individual arguments into
ctools_ajax_command_redirect()
.