2

I have an HTML form:

<html>
    <body>
        <form method="post" action="test.php">
            <input type="text" name="     TEST   " value="   TEST     "/>
            <input type="submit" />
        </form>
    </body>
</html>

It submits to the following PHP page:

<?php
var_dump($_POST);

When I submit the form without modifying any values, the resulting page displays:

array(1) { ["TEST___"]=> string(12) " TEST " }

Where did the left spaces/underscores go in the key name? How can I get the left spaces/underscores back?

ITS Alaska
  • 691
  • 1
  • 6
  • 18
  • 3
    Possible duplicate with : http://stackoverflow.com/questions/17092398/post-spaces-converted-in-underscores ? – Kalzem Jun 17 '13 at 22:31
  • 1
    No. I already looked at that. It explains why the spaces are being converted to underscores, but not where the left spaces/underscores went. @BabyAzerty – ITS Alaska Jun 17 '13 at 22:33

4 Answers4

3

They were dropped, you can't. According to HTML 4 spec: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

The working draft for HTML 5 is even more permissive, saying only that an id must contain at least one character and may not contain any space characters. See: What are valid values for the id attribute in HTML?

Community
  • 1
  • 1
Joe T
  • 2,291
  • 1
  • 16
  • 28
0

don't use spaces for the name attribute to be on the safe side.

jancha
  • 4,873
  • 1
  • 21
  • 35
0

Why would you want your input name to contain all those spaces? Might there be a better solution to what you're trying to achieve, perhaps?

ekreutz
  • 26
  • 1
  • I have a form for updating survey results. The point is to normalize the data, and I'm doing mass replaces of one field value with another where the $_POST key is the original value, and the $_POST value is the new value. Sure I could use a multi-dimensional array, but that adds a new level of complexity to this simple problem that can be solved using the keys and values of a single array. – ITS Alaska Jun 17 '13 at 22:40
0

&nbsp worked for me

<html>
<body>
    <form method="post" action="test.php">
        <input type="text" name="&nbsp&nbspTEST&nbsp&nbsp" value="   TEST     "/>
        <input type="submit" />
    </form>
</body>

&nbsp - Single space, for more spaces use more

Nitish Raj
  • 21
  • 3