PHP Header Location - redirect to URL with HTML anchor

女生的网名这么多〃 提交于 2020-01-25 05:24:05

问题


I have a website, where after submission of a form user is redirected throught Header Location to the same page but with anchor to fill in another form.

Header('Location: http://www.topdodavatel.cz/tuzby/tuzby.php#nechaj');

However, when the first form is submitted, the user is not landed on the anchored DIV, but on the bottom of page.

As you can try on development version http://www.topdodavatel.cz/tuzby/tuzby.php

What could cause that the anchor does not work? If I choose some div that is written in the code above, it works well.

Kindly thank you for your inputs!


回答1:


This is a common problem it seems, see here or here for a similar problem.

It seems that something along the way, PHP, Apache or your browser strips out the anchor element on redirection.

To make this work I would suggest moving the anchor content nechaj into a query variable tuzby.php?anchor=nechaj. Then in PHP check for this variable and if it exists use JavaScript to move the user to the correct point. Like this:

window.location.hash='<?php echo $_GET["anchor"] ?>';

You'll need to add some kind of input verification check for the anchor variable of course.




回答2:


Name is important

Give submit button like this

<input type="submit" name="submits" value="Done" />

in the submit box name is required need to submit the form

Provide name in your submit in your site check out it will work




回答3:


Thank everyone for your initiative. It showed up that major issue was with DIV that obtained content generated from database and did not have set fixed height, which caused temporary overflow of that DIV.

So I fixed it by setting a height to the element and overflow:hidden (before the style loads properly).



来源:https://stackoverflow.com/questions/30754126/php-header-location-redirect-to-url-with-html-anchor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!