jamInTheValleys Posted January 18, 2010 Share Posted January 18, 2010 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 https://forums.phpfreaks.com/topic/188954-form-methodpost-doubling-in-_get-and-_post/ Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 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 https://forums.phpfreaks.com/topic/188954-form-methodpost-doubling-in-_get-and-_post/#findComment-997729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.