Forum Moderators: coopster

Message Too Old, No Replies

Form error messages

         

th1chsn

4:17 pm on Aug 14, 2005 (gmt 0)

10+ Year Member



Hello, I got this free form submission program from the web and I want to try and put the form error messages on a custom error page. The program allows for a custom error page but I am not sure what code to include on the custom page to show the specific error.

The code in the form specifying the redirect is:
<input type=hidden name="missing_fields_redirect" value="../error.php">

The error function code is:

// our mighty error function..
function print_error($reason,$type = 0) {
build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
// for missing required data
if ($type == "missing") {
if ($missing_field_redirect) {
header("Location: $missing_field_redirect?error=$reason");
exit;
} else {
?>
The form was not submitted for the following reasons:<p>
<ul><?
echo $reason."\n";
?></ul>
Please use your browser's back button to return to the form and try again.<?
}
} else { // every other error
?>
The form was not submitted because of the following reasons:<p>
<?
}
echo "<br><br>\n";
exit;
}

I thought I could just use <? echo $reason?> but that didn't work.

Any help would be appreciated.

[edited by: jatar_k at 7:34 pm (utc) on Aug. 15, 2005]
[edit reason] removed url [/edit]

dreamcatcher

5:36 pm on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi th1chsn,

What you need to use is:

echo $_GET['error'];

dc

th1chsn

5:05 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



dc, I tried the following 3 lines and I couldn't get it to work. What am I missing?

<? echo $_GET['error'];?>

<? echo $_GET['[print_error'];?>

<? echo $_GET['reason'];?>

dreamcatcher

7:31 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Firstly, does your server have short tags enabled? If it doesn`t this will not work:

<? echo $_GET['error'];?>

Try this instead:

<?php echo $_GET['error'];?>

Also make sure that the error variable in the url actually has a value.

dc

th1chsn

8:40 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Hi dc, thanks for your help but I'm still unable to get this thing to work. The closest I got was putting?error=$reason at the end of my redirect url and I got the error page to echo back "$reason".

I'm not a skilled programmer and everything that I try is just getting me more and more frustrated. I'll just leave a generic error message.

Thanks anyway.

-- th1

dreamcatcher

7:29 am on Aug 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try echoing the $reason variable before it populates the URL?

Also, a silly question but your server does support PHP doesn`t it?

dc

th1chsn

2:45 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



hey dc, i checked with the host and they support php as well as have short tags enabled. what i tried to do is put $reason in the hidden tag on the form:

<input type=hidden name="missing_fields_redirect" value="../error.php?error=$reason"> and when I used <? echo $_GET['error'];?> I got $reason displayed on the error.php page.

-- th1