By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,303 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,303 IT Pros & Developers. It's quick & easy.

spaces in $_REQUEST (or $_GET, $_POST)

P: n/a
I have a legacy database table that has spaces in the field names.

So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">

on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

That doesn't work, I never see the form element. How do I get around this?

Note that I have many tables like this and I'm generating the edits
programaticaly.

Jeff
Sep 18 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Jeff wrote:
I have a legacy database table that has spaces in the field names.

So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">

on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

That doesn't work, I never see the form element. How do I get around this?
What does enumerating the $_POST array say (the keys, that is)? I know
periods are replaced with underscores. So spaces may be replaced with
underscores as well.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Sep 18 '08 #2

P: n/a
..oO(Jeff)
I have a legacy database table that has spaces in the field names.

So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">
Such names are invalid:

| 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 (".").
>on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

That doesn't work, I never see the form element. How do I get around this?
Fix the names.

Micha
Sep 18 '08 #3

P: n/a
On Sep 18, 10:24*am, Jeff <jeff@spam_me_not.comwrote:
* I have a legacy database table that has spaces in the field names.

* *So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">

on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

That doesn't work, I never see the form element. How do I get around this?

Note that I have many tables like this and I'm generating the edits
programaticaly.

* *Jeff
Can you not just put in a translator? IE for outgoing html forms,
replace the " " in the field with an underscore, then when reading the
form and putting information in the database, replace the "_" in the
field name with an underscore.

Bill H
Sep 18 '08 #4

P: n/a
On Sep 18, 8:02*pm, Bill H <b...@ts1000.uswrote:
On Sep 18, 10:24*am, Jeff <jeff@spam_me_not.comwrote:
* I have a legacy database table that has spaces in the field names.
* *So I have a form that looks like this:
<input type="text" name="name with space" value="some_value">
on the server I have:
$field_name = 'name with space';
$my_form_value = $_POST[$field_name];
That doesn't work, I never see the form element. How do I get around this?
Note that I have many tables like this and I'm generating the edits
programaticaly.
* *Jeff

Can you not just put in a translator? IE for outgoing html forms,
replace the " " in the field with an underscore, then when reading the
form and putting information in the database, replace the "_" in the
field name with an underscore.

Bill H
Wouldn't you want to replace the "_" with a space?
Sep 18 '08 #5

P: n/a
Bill H wrote:
On Sep 18, 10:24 am, Jeff <jeff@spam_me_not.comwrote:
> I have a legacy database table that has spaces in the field names.

So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">

on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

That doesn't work, I never see the form element. How do I get around this?

Note that I have many tables like this and I'm generating the edits
programaticaly.

Jeff

Can you not just put in a translator? IE for outgoing html forms,
replace the " " in the field with an underscore,
I used a "+" to replace the spaces in the forms and when building the
key for $_POST. I usually use underscores to replace spaces but I didn't
want to use it here as I wanted some symbol that I wouldn't see
otherwise, yet had some meaning.

I don't know what naming conventions Access users use, but these
tables have been driving me crazy. Field and table names are
uppercase and have spaces in them. Primary keys may or may not be there
and if they are they aren't autoincrement. Unfortunately, it's all
mission critical stuff.

Jeff

then when reading the
form and putting information in the database, replace the "_" in the
field name with an underscore.

Bill H
Sep 18 '08 #6

P: n/a
Jeff wrote:
Bill H wrote:
>On Sep 18, 10:24 am, Jeff <jeff@spam_me_not.comwrote:
>> I have a legacy database table that has spaces in the field names.

So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">

on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

That doesn't work, I never see the form element. How do I get around
this?

Note that I have many tables like this and I'm generating the edits
programaticaly.

Jeff

Can you not just put in a translator? IE for outgoing html forms,
replace the " " in the field with an underscore,

I used a "+" to replace the spaces in the forms and when building the
key for $_POST. I usually use underscores to replace spaces but I didn't
want to use it here as I wanted some symbol that I wouldn't see
otherwise, yet had some meaning.
After further thought, it didn't seem like + was legal in a form
field name, so I went with the underscore.

Jeff
>
I don't know what naming conventions Access users use, but these
tables have been driving me crazy. Field and table names are
uppercase and have spaces in them. Primary keys may or may not be there
and if they are they aren't autoincrement. Unfortunately, it's all
mission critical stuff.

Jeff

then when reading the
>form and putting information in the database, replace the "_" in the
field name with an underscore.

Bill H
Sep 18 '08 #7

P: n/a
*** Jeff escribió/wrote (Thu, 18 Sep 2008 10:24:56 -0400):
I have a legacy database table that has spaces in the field names.

So I have a form that looks like this:

<input type="text" name="name with space" value="some_value">

on the server I have:

$field_name = 'name with space';

$my_form_value = $_POST[$field_name];

If you print the contents of $_POST:

print_r($_POST);

You'll see the actual name:

Array
(
[name_with_space] =some_value
)

The reason is that PHP used to create a local variable for each form value
(now it's optional an deprecated) and you can't have a variable with spaces
on its name.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
Sep 18 '08 #8

P: n/a
Michael Fesser:
.oO(Jeff)
<input type="text" name="name with space" value="some_value">

Such names are invalid:

| 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 (".").
No, the value of the name attribute of the form element is declared as
CDATA, not as a NAME token, so pretty much anything goes, including
spaces.

But, as the FAQ says, PHP would convert these spaces to underscores.

http://www.php.net/manual/en/faq.html.php

--
Jock
Sep 18 '08 #9

P: n/a
..oO(John Dunlop)
>Michael Fesser:
>.oO(Jeff)
><input type="text" name="name with space" value="some_value">

Such names are invalid:

| 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 (".").

No, the value of the name attribute of the form element is declared as
CDATA, not as a NAME token, so pretty much anything goes, including
spaces.
Indeed, had forgotten that. Thanks for the correction.

I would still avoid them.

Micha
Sep 19 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.