-2

Let's say that I have the following simple input text box:

<input type="text" name="Details[0]->Name" value="" />

Now the problem is, php translating the input name as array, and then ignore the rest name after the closing square bracket. So in print_r, it become:

Details => Array{
    [0] => "Input"
}

What can I do to workaround this? Is there any unparsed $_REQUESTS?

N.B: If you noticed it, yes I am trying to use automatic input to class mapper as it has been done in Asp.net mvc.

Edit:

The additional solution requirement is that I can read raw array input from either GET, POST or multipart form requests.

Fendy
  • 4,565
  • 1
  • 20
  • 25

2 Answers2

1

For POST:

echo urldecode ( file_get_contents('php://input'));

For GET:

echo urldecode ($_SERVER['QUERY_STRING']);

Both the above give the output Details[0]->Name=testval

As for enctype='multipart/form-data', the unparsed data is not available in php. However, there is a solution of sorts given by this SO question: Get raw post data

Community
  • 1
  • 1
enigma
  • 3,476
  • 2
  • 17
  • 30
  • I replied at your comment. Is file_get_contents works on other requests header other than POST? And I also want it to work on enc-multipart form – Fendy Apr 25 '15 at 11:03
  • thanks for the answer. I am still waiting for some way that do not required to edit the initial config file. – Fendy Apr 25 '15 at 11:59
0

Just replace Input with some another name like Inputcust and make new array

Details => Array{
[0] => "Inputcust"

}

and where ever you want to use again replace from Inputcust => Input

Kruti Aparnathi
  • 175
  • 1
  • 11
  • You are getting me wrong. I am translating the input name to PHP syntax (without eval though). So in short, I am telling PHP to do this code `$result->Details[0]->Name = $inputValue` when getting input with name `Details[0]->Name`. – Fendy Apr 25 '15 at 11:14
  • so you can convert array to object. – Kruti Aparnathi Apr 25 '15 at 11:45