Page 1 of 2
Blank in name attribute converted to underscore
Posted: Fri Aug 18, 2006 9:40 pm
by anjanesh
Hi
Whitespaces in
input's name attribute are getting converted to underscores.
Code: Select all
<input type="text" name="Full Name"/>
Output
Code: Select all
Array ( [Full_Name] => Some Name................)
How long has this been like this ?
Thanks
[FireFox 1.5.0.4, PHP 5.1.4, Apache 2.0.58]
Posted: Fri Aug 18, 2006 11:26 pm
by RobertGonzalez
Why are there spaces in your field names?
To be back on topic, I had no idea that form fields with spaced names were modified during post.
Posted: Fri Aug 18, 2006 11:32 pm
by anjanesh
Everah wrote:Why are there spaces in your field names?
I want them to match exactly as my MySQL fieldnames.
Posted: Fri Aug 18, 2006 11:35 pm
by RobertGonzalez
MySQL field names shouldn't have spaces either.
Posted: Fri Aug 18, 2006 11:36 pm
by Weirdan
I want them to match exactly as my MySQL fieldnames.
And why are there spaces in your db field names?

Posted: Fri Aug 18, 2006 11:44 pm
by anjanesh
Because MySQL handles it well allowing us to define fieldnames as proper names. I've always used whitespaces in MySQL fieldnames from the start.
Posted: Fri Aug 18, 2006 11:46 pm
by RobertGonzalez
I would recommend not using spaces in our DB field names. And I would recommend not using spaces in your form field names.
Posted: Fri Aug 18, 2006 11:48 pm
by feyd
...there's always
str_replace().
I would hazard to guess it's Firefox that's adding the underscore.. or it may be your own code somewhere. Darn near impossible to say right now.
Posted: Fri Aug 18, 2006 11:49 pm
by Weirdan
recent versions of MySQL allows unicode in field names. Yet I don't store my metadata in Russian... guess why.
Posted: Sat Aug 19, 2006 12:57 pm
by anjanesh
feyd wrote:I would hazard to guess it's Firefox that's adding the underscore.. or it may be your own code somewhere. Darn near impossible to say right now.
post-test.php
Code: Select all
<?php
print_r($_POST);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr">
<head>
<title>POST Test</title>
</head>
<body>
<form action="" method="post">
Full Name : <input type="text" name="Full Name"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
On both my localhost and server using FF 1.5.0.4 and IE 7 beta 2, the whitespace gets converted to underscore.
If converted to
GET, it becomes
post-test.php?Full+Name=someone but print_r($_GET) still prints
Array ( [Full_Name] => someone )
Changing the PHP code to ASP .NET and running it on IIS 5.1 (post-test.aspx)
Code: Select all
<%
Response.Write(Request.Form())
%>
I get
Full+Name=someone as output.
So Im guessing this is Apache's doing ? Im yet to try this on PHP+IIS.
Posted: Sat Aug 19, 2006 2:08 pm
by Weirdan
So Im guessing this is Apache's doing ?
As a quick check, do var_dump($_SERVER["QUERY_STRING"]);
If there are underscores, then that's apache thing, otherwise it's php's behaviour
Posted: Sat Aug 19, 2006 2:20 pm
by feyd
Might need to check
$HTTP_RAW_POST_DATA too.
Posted: Sat Aug 19, 2006 11:38 pm
by RobertGonzalez
I'm still thinking it may be easier (and better) to axe the spaces in your db field names and form field names.
Posted: Sat Aug 19, 2006 11:41 pm
by feyd
Everah wrote:I'm still thinking it may be easier (and better) to axe the spaces in your db field names and form field names.
I would agree, but so far, anjanesh has disliked that solution.
Posted: Sat Aug 19, 2006 11:55 pm
by RobertGonzalez
feyd wrote:Everah wrote:I'm still thinking it may be easier (and better) to axe the spaces in your db field names and form field names.
I would agree, but so far, anjanesh has disliked that solution.
Yeah, I know. And I suppose repeating that solution makes me look like a persistent @$$, so, with that, I believe I will be vacating my position in this thread.