PHP Form Error
Moderator: General Moderators
- partiallynothing
- Forum Commoner
- Posts: 61
- Joined: Fri Nov 21, 2003 5:02 pm
- Location: connecticut, usa
PHP Form Error
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!
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.
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
<?php
$previous = $_SERVER["HTTP_REFERER"];
header("Location:{$previous}");
?>Code: Select all
<input type="hidden" name="onError" value="somewhere.php" />- partiallynothing
- Forum Commoner
- Posts: 61
- Joined: Fri Nov 21, 2003 5:02 pm
- Location: connecticut, usa
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
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
- partiallynothing
- Forum Commoner
- Posts: 61
- Joined: Fri Nov 21, 2003 5:02 pm
- Location: connecticut, usa