0

basically what i want is, when i submit my form, the action="" is set to my PHP Script which executes the form and does what it needs to do, if its not successful it redirects to the same page displaying the error that occurred, but when it redirects it goes to the top of the page, how can i make it automatically go to the form where the error is displayed on that page, so like auto scroll, kind of like a ^TOP link, when you click top it goes to where ever you have set the id.

I just want it to know where the error is on the page and scroll to that error, so guests are wondering what happened because the error is near the form and they are at the top of the page.

putvande
  • 15,068
  • 3
  • 34
  • 50
thechrishaddad
  • 6,523
  • 7
  • 27
  • 33

1 Answers1

0

Use anchors for that.

<!DOCTYPE html>
<html>
    <head>
        <title>My Page</title>
    </head>
    <body>
        [... stuff on top of the page]
        <div id="errors">My Errors</div>
        <?php var_dump($_GET); ?>
    </body>
</html>

PHP Part

<?php

    header('location: mypage.php?var1=test&var2=test#errors');

?>
thpl
  • 5,810
  • 3
  • 29
  • 43
  • can i still pass my $_get errors in my header with id anchor tags? – thechrishaddad Aug 07 '13 at 08:07
  • sure. I'll edit my answer. Altough I wouldn't recommend to pass errors via get parameters. Use flashdata (session data that is available for one request) for that. – thpl Aug 07 '13 at 08:08
  • Any reason why you would not recommend this? and got any resources on flashdata? thanks – thechrishaddad Aug 07 '13 at 08:35
  • Yes. The user will be able to manipulate the get variables. I'll just send a link to a potential victim with: http://mypage.com/mypage.php?errors=Visit%20my%20malicious%20website%20at%20http%3A%2F%2Fmalicious.com#errors The user who receives the link will get to your page with the error message: Visit my malicious website at http://malicious.com Flashdata is "just a buzzword". Here you can find a simple implementation. The intention should be clear from there :) http://stackoverflow.com/questions/12153140/codeigniter-like-flashdata-in-core-php – thpl Aug 07 '13 at 08:42
  • i thought wrapping your $_get in htmlspecialchars() will protect a hacker from injecting html in to the get variables – thechrishaddad Aug 07 '13 at 08:47
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34972/discussion-between-thomas-david-plat-and-user1265535) – thpl Aug 07 '13 at 08:48