How do you use $_GET and # anchor link at the same time?

[亡魂溺海] 提交于 2020-01-04 09:27:04

问题


I have a form that redirects to the original form page with $_GET to display any errors. But the form itself is place lower down the page. What is the correct way to use both?

I tried www.abc.com/index.php?error=missing_input&#review


回答1:


Yep, it's definitely working for me:

<?php

if (!isset($_GET['submitted'])) {
    echo "<form action='#fragment'><input type='text' name='text'><input type='submit' name='submitted' value='Do it'></form>";
} else {
    echo "<div style='height: 800px'>Vertical Padding<br>Your text was: {$_GET['text']}</div><div id='fragment'>This is the fragment</div>";
}

If it's not working for you, I suspect that either don't have an element with the reference ID on the page you are producing, or you generally have the wrong idea about how URL fragment anchors work.

Have a play with that simple code, and come back to me if you have any more problems.




回答2:


See this link: http://www.ietf.org/rfc/rfc3986.txt for the rfc3986 specification.

     foo://example.com:8042/over/there?name=ferret#nose
     \_/   \______________/\_________/ \_________/ \__/
      |           |            |            |        |
   scheme     authority       path        query   fragment
      |   _____________________|__
     / \ /                        \
     urn:example:animal:ferret:nose

Try removing the "&" after "missing_input" and see if that works.



来源:https://stackoverflow.com/questions/11617022/how-do-you-use-get-and-anchor-link-at-the-same-time

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