Jump to content

$_POST array is empty?


michaellunsford

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.