ITS Alaska
ITS Alaska

Reputation: 739

PHP - Missing spaces/underscores in POST key

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?

Upvotes: 2

Views: 1731

Answers (4)

Nitish Raj
Nitish Raj

Reputation: 19

&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

Upvotes: 0

ekreutz
ekreutz

Reputation: 26

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?

Upvotes: 0

jancha
jancha

Reputation: 4967

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

Upvotes: 0

Joe T
Joe T

Reputation: 2350

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?

Upvotes: 3

Related Questions