user1187135
user1187135

Reputation:

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

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

Upvotes: 2

Views: 1536

Answers (2)

DaveRandom
DaveRandom

Reputation: 88647

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.

Upvotes: 3

Layton Everson
Layton Everson

Reputation: 1148

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.

Upvotes: 2

Related Questions