amelio Posted April 17, 2012 Share Posted April 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261117-create-id-point-in-url-from-form-input/ Share on other sites More sharing options...
requinix Posted April 17, 2012 Share Posted April 17, 2012 Use a redirect. header("Location: /path/to/wherever#c1000"); exit; I prefer that to the JavaScript equivalent (which I'm not even sure how you do). Quote Link to comment https://forums.phpfreaks.com/topic/261117-create-id-point-in-url-from-form-input/#findComment-1338161 Share on other sites More sharing options...
Psycho Posted April 17, 2012 Share Posted April 17, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261117-create-id-point-in-url-from-form-input/#findComment-1338167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.