knowing when a form has been POSTed

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
NNParksITGuy
Forum Newbie
Posts: 4
Joined: Sat Oct 26, 2002 6:39 pm
Location: Newport News Virginia

knowing when a form has been POSTed

Post 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!!!
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

Post by sweahe »

You can use:

if ($_SERVER["REQUEST_METHOD"] == 'POST') {
// Things to do when posting
}
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
NNParksITGuy
Forum Newbie
Posts: 4
Joined: Sat Oct 26, 2002 6:39 pm
Location: Newport News Virginia

My bad. Question answered

Post 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.
User avatar
d3ad
Forum Newbie
Posts: 1
Joined: Tue Oct 29, 2002 3:26 am
Location: Up to my neck in PHP.

Post 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.
Post Reply