0

I'm trying to create a query string, which passes all form elements and the entered data via a GET request to a PHP file.

I'm using encodeURIComponent in JavaScript to encode the input field names as well as the field values.

What I'm encountering is that the field values seem to be passed well as I receive them in $GET correctly, but the field names will have the dot (.) replaced by an underscore ().

Example:

<input type="text" name="form.0.text.0" value="" />

This field.name would arrive at my PHP script as form_0_text_0 instead of form.0.text.0, while the entered text (e.g. this contains a lot of ....) would arrive just fine.

I'm using the following code as part of the query string generation:

+ encodeURIComponent(field.name) + "=" + (field.type == "checkbox" ? (field.checked) : encodeURIComponent(field.value))

Any ideas about what to do?

user1914292
  • 1,586
  • 13
  • 38
  • thanks for the correct redirect - i would delete the question if I thought I just didn't search enough, but since I had no idea that PHP was doing this, maybe someone else will find this question and get pointed to the right answer. Please flag as irrelevant if you don't agree. – user1914292 May 18 '13 at 16:51

1 Answers1

1

This is PHP “protecting you”. If you try to pass GET variables containing dots, they'll be replaced by underscores. See Get PHP to stop replacing '.' characters in $_GET or $_POST arrays?

There is a way around that “protection” if you really must use dots in your name attributes: https://stackoverflow.com/a/1939911/2397004

Community
  • 1
  • 1
Patrice Levesque
  • 2,079
  • 17
  • 16
  • awesome - all i had to do was replace the php://input with $_SERVER['QUERY_STRING'] since I'm using HTTP GET and I'm ready to roll – user1914292 May 18 '13 at 17:46