0

I have a page with a form at the bottom. I use a fragment identifier in the form action, because the form re-displays on post when there are errors, and I don't want the user to have to scroll down to it to make corrections.

When the form is successfully processed, I perform a redirect to the same page and display a confirmation message. The problem I am having is that the browser preserves the fragment identifier upon 302 redirects. Is there a trick to force the browser to clear/remove the fragment identifier?


Let's say I'm looking at a user profile page, and there's an address form on the page. The form action would be /user/profile#AddressForm. If the form is submitted with errors, the page automatically is scrolled to the address form so the user can correct the errors. If there are no errors, I want to redirect to /user/profile, which doesn't have the fragment identifier. The problem I am running into is that the browser retains the fragment identifier and the page scrolls back down to the form, instead of staying at the top.

Community
  • 1
  • 1
Sonny
  • 8,204
  • 7
  • 63
  • 134

1 Answers1

1

Update

Now that I see what is the actual problem I would suggest a redirect to non-existing anchor

header ('Location: /user/profile#top');

There is.

$form->setAction ($this->getRequest ()->getRequestUri ());
akond
  • 15,865
  • 4
  • 35
  • 55
  • I don't think you understand the issue. I do not have a problem setting the form "action". I have a problem doing a redirect afterward, because the browser is retaining the fragment identifier, and I want it to go away. – Sonny Nov 19 '12 at 15:06
  • I think I do. Browser retains fragment identifier only when action attribute is not set. When action is explicitly set, it does not. – akond Nov 19 '12 at 15:18
  • I always set the action. Either way, I am doing a redirect after post, so the form action is no longer a factor. – Sonny Nov 19 '12 at 19:28
  • I thought that may be the only solution, but I wanted to confirm. – Sonny Nov 21 '12 at 17:03