Jump to content

Create id point in url from form input


amelio

Recommended Posts

Hi, I have a page with a long list of names (c1000) each with an id.

 

On that page I would like to have a form into which i put the id number, when the form is submitted it will take me to the anchor point for that id. The question I have is, how, when i press submit and reload the page, how can I then have that form input as a anchor in the url that will then take me to the place I want to go on the list when the page loads.

 

I can do it manually no problem by adding the hash tag and id to the url myselft it takes me there but It's a pain to do this every time. I would like to use a form.

 

Is this possible? any help appreciated.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/261117-create-id-point-in-url-from-form-input/
Share on other sites

Building upon what requinix posted, put this at the top of the page that lists the records

 

if(isset($_POST['id']))
{
    header("Location: /path/to/thispage.php#{$_POST['id']}");
    exit;
}

 

If you load the page without the post value it will display without moving to an anchor. However, if you do post a value for the ID, then the page immediately reloads the page with the appropriate anchor tag in the URL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.