问题
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