Question

I have a form at the bottom of the page. It's a normal form. I've set the action to #adding-show and the form's id is "form". The result is that the form submits to the current page (the browser doesn't send #adding-show to the server).

If the submission is invalid/fails, the form is focused and visible = good.

If the submission is valid, the server redirects the browser to the same page (to get rid of the postback), without hash, but the browser 'remembers' the hash, so the browser redirects to #adding-show at the bottom of the page.

In short: keeping the hash is good when submission is invalid/fails, but the hash shouldn't be used if submission succeeded.

The question: is there a way to do that? Redirect correctly and 'forget' the hash appropriately. Some JS is okay. I can make the server do anything.

If you like code, it's on Github.

Or:

<form id="adding-show" method="post" action="#adding-show">

Was it helpful?

Solution

I've solved it with a piece of 'conditional' JS: https://github.com/rudiedirkx/series/blob/83c74f183d4c10474e2b92d819349120ad0094b6/index.php#L627 It's only printed if the page is in postback, so the form needs to be highlighted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top