Reputation: 55
A little while ago, I asked a question about using the same input name/hidden name multiple times in a page, and got an answer that did not work as it suggested the I had to use to put brackets after the field name, like partno[]
.
I cannot use this in my form, as the cart it is being sent to only recognizes certain field names like: partno, item, price, qty, etc. (I cannot use partno[], item[]
, etc.) So I really need to be able to get all the values for each identical field name used multiple times. When I use the method GET
, it will display all the values for each field name used in the address bar. You can try this and submit the form. Look at the url in the address bar.
My new question is: Is there a way in PHP to capture all the information passed using the POST
method? (like what shows up in the address bar in the example above but using POST
, not GET
). I can parse it if I can figure out a way to capture it.
Thanks, Kelly
Upvotes: 5
Views: 553
Reputation: 23001
If you want to see what all $_POST is sending, either var_dump($_POST) or echo print_r($_POST). This will show you all of the field names and data, even if the field names contain arrays, like your partno[].
Upvotes: 0
Reputation: 102735
You can get the untainted data directly from the input stream:
file_get_contents('php://input');
So if you have something like this:
<input name="type" value="val1">
<input name="type" value="val2">
<input name="type" value="val3">
You will get a string like this:
type=val1&type=val2&type=val3
You can then parse this string into an array and create your own "raw post data".
http://php.net/manual/en/wrappers.php.php
php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".
Upvotes: 2
Reputation: 1300
No way to POST 2 inputs with same name as string. You should modify the cart to convent array to string.
If you are using GET you can check out parse_url() function.
Upvotes: -1
Reputation: 24661
Since POST in PHP is nothing more than an array, just iterate over it.
foreach($_POST as $k => $v) {
echo($k . ': '. $v . '<br>');
}
Upvotes: 1
Reputation: 5004
You just use $_POST
instead of $_GET
.
So if you were using get in the following way:
?something=somevalue
And were catching it with $_GET['something']
, you would now use $_POST['something']
.
Upvotes: 2