Page 1 of 1

knowing when a form has been POSTed

Posted: Sat Oct 26, 2002 6:39 pm
by NNParksITGuy
Ok, I'm new to PHP 4.2x, and I read with great interest the post regarding the change from register_globals, which helped a lot.

The problem is that I call $_SERVER['PHP_SELF'] as the post action, and had been using

Code: Select all

If (isset($submit)) {
to determine whether the form has been first opened, or actually has run with some data.

I've been searchning the forums and PHP site all day and can't seem to locate the proper syntax for that under 4.2. I've tried

Code: Select all

If (isset($_POSTї'submit']))
and

Code: Select all

if (isset($_SERVERї'submit']))
but neither seem to be triggered by the form submittal.

This newbie would appreciate a steer in the right direction.

Thanks and happy coding!!!

Posted: Sat Oct 26, 2002 7:57 pm
by sweahe
You can use:

if ($_SERVER["REQUEST_METHOD"] == 'POST') {
// Things to do when posting
}

Posted: Sun Oct 27, 2002 1:44 am
by Takuma
Just a basic question but are you sending data using POST or GET? Have you tried $HTTP_POST_VARS? Have you got the case of the string correct?

Posted: Sun Oct 27, 2002 5:40 am
by twigletmac
For debugging you can use:

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
to see what is in the $_POST array, in order to check that variables and values are getting passed as expected.

Mac

My bad. Question answered

Posted: Sun Oct 27, 2002 7:58 pm
by NNParksITGuy
Hi everyone:

I figured it out. Some days I don't think straight.

I was using

Code: Select all

If (isset($_POSTї'submit']))
to flag that the form was submitted with a submit button, but a number of other variables were not coded properly as $_POST['variable'] as explained in the excellent post on passing variables. Once i corrected that and the session variables, it worked fine - it just took a day or so to figure it all out.

Thanks everyone for the assistance.

Posted: Tue Oct 29, 2002 3:26 am
by d3ad
Personally I use:

Code: Select all

<?php If (isset($_POSTї'submit'])) {
switch($submit){
case"bleh":
break;
default:
}
}  ?>
Rather then a nasty if or 2 :D.