Web Hosting Talk







View Full Version : Help with form post


saghir69
02-23-2008, 03:58 AM
I have a form on my site that uses post to send the data to a page called process.php

everything is working fine when the data is submitted from the form page. but if I directly type www.mysite.com/process.php I get blank values, obviusly because the form was not submitted.

How can i check on the process.php to check if the form was submitted and if not I display a message for the visitor to go back to form page..

I think is something like

is $_post == true

can someone help thanks.

dollar
02-23-2008, 08:21 AM
First add a hidden field to you form. Something like:

<input type="hidden" name="action" value="doProcess" />

Then in process.php
<?php if($_POST['action'] == "doProcess") {
// Do stuff Here
} else {
echo("Please return to other page.");
} ?>

Codebird
02-23-2008, 09:18 AM
I think a bit better way than dollar said is to:


if($_POST["action"]==""){
//Redirect to another page
header("Location: something.php");
}
else {
//Do stuff here
}

wdr1
02-23-2008, 04:32 PM
Why not check if one of the variables you set is defined?

Codebird
02-23-2008, 04:43 PM
it is the same thing

Tim Greer
02-23-2008, 05:20 PM
Just check if it's a POST or GET, etc. submission, and only accept POST, as CodeBird had said. If it's not a POST request, then display the error.

saghir69
02-23-2008, 07:33 PM
Thanks guys for your response. I think I'll check if one of my important variable is set and if not i'll just redirect to form page.

Do you think I should silently redirect people to form page or actually show a error page. Which is better?

Codebird
02-23-2008, 07:39 PM
same thing in both cases the user will know that he's not allowed to access this page directly. don't know an error he'll be sure that the page exists but redirecting he may think that a 404 error happened but u handled it