michaellunsford Posted March 25, 2008 Share Posted March 25, 2008 I just built a big form full of select and text fields, submit it and get an empty $_POST array using <?php print_r($_POST); ?>, if I change the method to "get" then <?php print_r($_GET); ?> it displays everything just fine. What's going on? ??? Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/ Share on other sites More sharing options...
dmccabe Posted March 25, 2008 Share Posted March 25, 2008 I think it would help people to help you if you actually post your code Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/#findComment-500420 Share on other sites More sharing options...
michaellunsford Posted March 25, 2008 Author Share Posted March 25, 2008 Sorry, I didn't think it was important. The problem was apparently the enctype="text/plain" (odd), the problem goes away when using enctype="application/x-www-form-urlencoded" <?php print_r($_POST); ?> <form method="post" enctype="text/plain" action=""> <input type="text" name="text_field" id="text_field" value="text value" /> <input type="submit"> </form> Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/#findComment-500438 Share on other sites More sharing options...
BlueSkyIS Posted March 25, 2008 Share Posted March 25, 2008 i'd leave out enctype unless you're uploading something. also, i would set the action on the form, in this case probably to <form method='post' action='<?=$_SERVER['PHP_SELF'];?>'> Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/#findComment-500440 Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 action does not need to be set as it defaults to the submitting page. Remove the enctype. It is invalid if you want PHP to be able to parse the form. If it must be there, set it to 'application/x-www-form-urlencoded' or 'multipart/form-data' in the case of file uploading. Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/#findComment-500445 Share on other sites More sharing options...
BlueSkyIS Posted March 25, 2008 Share Posted March 25, 2008 action does not need to be set as it defaults to the submitting page. yes, but it's good form to set it. Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/#findComment-500452 Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 In that case, using PHP_SELF would not always be the proper variable to use, as it doesn't replicate a query string that may be in the URL. REQUEST_URI would be better, or, just a blank action Read: 4.2. Same-document References A URI reference that does not contain a URI is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document. Traversal of such a reference should not result in an additional retrieval action. However, if the URI reference occurs in a context that is always intended to result in a new request, as in the case of HTML's FORM element, then an empty URI reference represents the base URI of the current document and should be replaced by that URI when transformed into a request. From: http://www.ietf.org/rfc/rfc2396.txt It never hurts to include an action, though. From what I've read older versions of some cellphone-based browsers (mostly nokia) have problems submitting to a blank action. It all depends on how many non-standard browsers you want to support. Personally, I have enough fun as it is just trying to get things to show up the same in IE/FF/Safari. I usually use blank actions when I want a page to submit itself. I've had problems before with PHP returning bad REQUEST_URI and PHP_SELF variables. On the other hand, I've yet to have a complaint or issue using a blank action. To sum it up, I agree with your statement, though chances are a blank action will not break a script. Link to comment https://forums.phpfreaks.com/topic/97811-_post-array-is-empty/#findComment-500460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.