Page 1 of 1
PHP Form Error
Posted: Sun Jan 25, 2004 4:23 pm
by partiallynothing
I have a PHP form validator. When the FormHandler page (which contains the validator) is loaded and an error is present, error text is displayed on the screen. I want to know if I can also make it automatically redirect itself back to the previouse page. Does anyone know how this can be done? Thanks!
Posted: Sun Jan 25, 2004 4:50 pm
by Gen-ik
To get the previous page that PHP was on you could use $_SERVER["HTTP_REFERER"] and then either add the value to a link or use header() to redirect the page.
Code: Select all
<?php
$previous = $_SERVER["HTTP_REFERER"];
header("Location:{$previous}");
?>
You could also set a hidden input in the form which contains a url to the page you want PHP to go to if there's an error in the form.
Code: Select all
<input type="hidden" name="onError" value="somewhere.php" />
Posted: Sun Jan 25, 2004 5:10 pm
by partiallynothing
I get the following error when trying to use the PHP example above.
Notice: Undefined index: HTTP_REFERER in c:\inetpub\wwwroot\partiallynothing\IS\inc\common\FormHandler.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\partiallynothing\IS\inc\common\FormHandler.php:2) in c:\inetpub\wwwroot\partiallynothing\IS\inc\common\FormHandler.php on line 3
Posted: Sun Jan 25, 2004 5:16 pm
by Gen-ik
What does your code look like?
Posted: Sun Jan 25, 2004 6:00 pm
by partiallynothing
I just decided not to do that. They can click the back button themselfves!
