Jump to content

form method="post" doubling in $_GET and $_POST


jamInTheValleys

Recommended Posts

Hello everyone,

 

I have a form on a page set to method="post".

 

If I set the action parameter to the same file as the one the form is on it puts the request in both $_POST and $_GET. This is wrong isn't it?

 

Even weirder:

If I loop through $_POST and $_GET and echo the result:

 

echo '<h1>Post</h1>';
foreach ($_POST as $key => $value) {
echo '<p>'.$key.':'.$value.'</p>';
}
echo '<h1>Get</h1>';
foreach ($_GET as $key => $value) {
echo '<p>'.$key.':'.$value.'</p>';
}

 

It displays:

 

Post
input_name:input_value
Get
input_name:input_value

 

But if I also loop through $_REQUEST:

 

echo '<h1>Post</h1>';
foreach ($_POST as $key => $value) {
echo '<p>'.$key.':'.$value.'</p>';
}
echo '<h1>Get</h1>';
foreach ($_GET as $key => $value) {
echo '<p>'.$key.':'.$value.'</p>';
}
echo '<h1>Request</h1>';
foreach ($_REQUEST as $key => $value) {
echo '<p>'.$key.':'.$value.'</p>';
}

 

It displays:

 

Post
input_name:input_value
Get
Request
input_name:input_value
input_name:input_value

 

This behaviour seems odd to me. Can anyone explain what's going on?

 

It behaves as expected when the action is set to a different page.

 

Thanks

Link to comment
Share on other sites

Post your form code, and the results of:

echo '<pre>'; // Formatting
echo print_r($_POST) . "<br/>\n";
echo print_r($_GET) . "<br/>\n";
echo print_r($_REQUEST) . "<br/>\n";

 

Should give you a better idea of what's going on.

 

<html>
<body>
<form action="form.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
<?php
//ini_set('display_errors',1);
//error_reporting(E_ALL);
echo '<pre>';
echo print_r($_POST, 1) . "<br/>\n";
echo print_r($_GET, 1) . "<br/>\n";
echo print_r($_REQUEST, 1) . "<br/>\n";
?>

 

Returns:

Array

(

    [fname] => d

    [age] => d

)

Array

(

)

Array

(

    [fname] => d

    [age] => d

)

 

As expected.

 

This is wrong isn't it?

 

Again, purely depends on your form code, browser and PHP.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.