How can I assign a URL with a fragment (#) as an array value? In my form:

$form_state['redirect'] = 'mypage/' . $nid . '#comment-form';


redirects to:

/mypage/1%23comment-form


...so it doesn't jump to the comment form. I tried:

$form_state['redirect'] = l('', "mypage/$nid", array('fragment' =&gt; 'comment-form');


...that retuned a bigger mess. I need to link to:

/mypage/1#comment-form


Basically, I'm trying to jump to the bottom of the page the user is redirected to.

Thanks
You can use an array for $form_state['redirect'], the elements of which mirror the arguments passed to the url() function.

So you can use...

$form_state['redirect'] = array(
  "mypage/$nid",
  array('fragment' =&gt; 'comment-form'),
);


The method it used quite sparingly in core (just 5 occurrences as far as I can tell); node_form_delete_submit() contains an example.