View Full Version : Best way to handle <FORM> result page ?

07-06-2005, 06:41 AM
Hi guys,

I have the general setup:

MyForm.htm // the HTML form
MyForm.php // the PHP result script

Everything works fine. I do however want to handle the case where someone goes to MySite.com/MyForm.php without getting there from the MyForm.htm page.

I tried a hidden field but I get an undefined index error if they don't go from the form page.

What's the best way to handle this situation ? I'm looking for something clean and not too complicated.


07-06-2005, 06:51 AM
on your myform.php file surround all your code in

if ($_POST['Submit'])
// all your code here
echo "error you cannot view this page";

if ($_POST['Submit']) just checks to see if your submit button was pressed.. there are many other ways to do it. im sure more people will post

07-06-2005, 04:43 PM
I get this:

PHP Notice: Undefined index: Submit in ...

Now it doesn't work at all, even if I press Submit.

07-06-2005, 05:05 PM
Try something like so:


if (!isset($_POST['submit']) OR empty($_POST['submit']))
echo 'You cannot view this page.';

/* processing code here */

Just name your submit input 'submit'

07-06-2005, 05:20 PM
rather than just putting an error message, personally I would redirect to MyForm.htm


if (!isset($_POST['submit']) OR empty($_POST['submit']))
header("Location: http://" . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']). "/" . "MyForm.htm");

Just better for a usability point of view IMO, error messages should be avoided if at all possible

07-06-2005, 06:07 PM
Thanks everyone.

I like redirecting also, I just had the 'if' test messed up. It works great now, I'm doing it like Nancy recommended.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum