PHP Form Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

PHP Form Error

Post 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!
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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

&lt;input type="hidden" name="onError" value="somewhere.php" /&gt;
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Post 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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

What does your code look like?
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Post by partiallynothing »

I just decided not to do that. They can click the back button themselfves! :)
Post Reply