Drupal: $form_state['redirect'] getting URL Encoded

Published on May 5, 2012

Was trying to redirect on a form submission to an anchor tag on the same page using:

<?php
$form_state['redirect'] = 'spinner#spinned';
?>

But it turns out that the result of the $form_state['redirect' actually causes redirection to "spinner%23spinned", with the passed url being URL-Encoded.

Passing an absolute URL to this solved it!

<?php
global $base_url;
$form_state['redirect'] = $base_url . '/spinner#spinned';
?>