Spaces becoming underlines

Spaces becoming underlines

am 21.04.2008 06:11:31 von Alan M Dunsmuir

I have two example strings, a name - 'SMITHJ' - and a short phrase -
'Town and Country' - which together uniquely identify a record on my
database. I concatenate them with a separating '&' to create a single
string identifier for the record - 'SMITHJ&Town and Country'.

I create a Form for my user, each line containing some identifying data
from a different database record, and a 'Submit' button (labelled
'Edit') named by an identifier as created above.

When the Form is processed, I determine which record the user wishes to
edit by checking the name of the pressed 'Edit' button.

When I 'explode' this name to its two constituent parts, I discover that
somewhere along the above process, 'Town and Country' has become
'Town_and_Country'. (I am using PHP5.)

Where and why has this happened?

Should I be prepared for any further character substitutions?

Re: Spaces becoming underlines

am 21.04.2008 10:07:58 von alvaroNOSPAMTHANKS

Alan M Dunsmuir escribió:
> I have two example strings, a name - 'SMITHJ' - and a short phrase -
> 'Town and Country' - which together uniquely identify a record on my
> database. I concatenate them with a separating '&' to create a single
> string identifier for the record - 'SMITHJ&Town and Country'.
>
> I create a Form for my user, each line containing some identifying data
> from a different database record, and a 'Submit' button (labelled
> 'Edit') named by an identifier as created above.
>
> When the Form is processed, I determine which record the user wishes to
> edit by checking the name of the pressed 'Edit' button.
>
> When I 'explode' this name to its two constituent parts, I discover that
> somewhere along the above process, 'Town and Country' has become
> 'Town_and_Country'. (I am using PHP5.)
>
> Where and why has this happened?
>
> Should I be prepared for any further character substitutions?

No code at all so I'll have to guess. You take database output and use
it as value for the name attribute in an input element:



Your DB contents are unrestricted (beyond field size) but the name
attribute is not:

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

http://www.w3.org/TR/html4/types.html#type-cdata

Than means you can expect all sort of data loss whenever your DB fields
have something that is not in the above list.

Without making big changes, I may suggest:



This should work if there aren't tabs or line feeds in your data.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Re: Spaces becoming underlines

am 21.04.2008 10:17:38 von luiheidsgoeroe

On Mon, 21 Apr 2008 06:11:31 +0200, Alan M Dunsmuir =

wrote:

> I have two example strings, a name - 'SMITHJ' - and a short phrase - =

> 'Town and Country' - which together uniquely identify a record on my =

> database. I concatenate them with a separating '&' to create a single =
=

> string identifier for the record - 'SMITHJ&Town and Country'.
>
> I create a Form for my user, each line containing some identifying dat=
a =

> from a different database record, and a 'Submit' button (labelled =

> 'Edit') named by an identifier as created above.
>
> When the Form is processed, I determine which record the user wishes t=
o =

> edit by checking the name of the pressed 'Edit' button.
>
> When I 'explode' this name to its two constituent parts, I discover th=
at =

> somewhere along the above process, 'Town and Country' has become =

> 'Town_and_Country'. (I am using PHP5.)
>
> Where and why has this happened?

Thank the evil that is register_globals. Because of this feature, all =

names in form fields are 'transposed' to a valid variable name in PHP. =

Which is why for instance in input type=3D"image" yields the
input>_x & _y in PHP, while the client actually sends me =

of input>.x and .y

> Should I be prepared for any further character substitutions?

Yes, unfortunately. All characters not valid in a PHP variable name will=
=

probably by substituted.
-- =

Rik Wasmus

Re: Spaces becoming underlines

am 21.04.2008 12:32:39 von Jerry Stuckle

Alan M Dunsmuir wrote:
> I have two example strings, a name - 'SMITHJ' - and a short phrase -
> 'Town and Country' - which together uniquely identify a record on my
> database. I concatenate them with a separating '&' to create a single
> string identifier for the record - 'SMITHJ&Town and Country'.
>
> I create a Form for my user, each line containing some identifying data
> from a different database record, and a 'Submit' button (labelled
> 'Edit') named by an identifier as created above.
>
> When the Form is processed, I determine which record the user wishes to
> edit by checking the name of the pressed 'Edit' button.
>
> When I 'explode' this name to its two constituent parts, I discover that
> somewhere along the above process, 'Town and Country' has become
> 'Town_and_Country'. (I am using PHP5.)
>
> Where and why has this happened?
>
> Should I be prepared for any further character substitutions?
>

Yep, as others have indicated, it's the name of the edit button that's
doing it.

It would have been better if you had submitted some code, it would be
easier. But I suspect you have one form with multiple edit buttons,
each edit button being identified by its respective record id.

One way to solve this would be to have separate forms for each entry,
each with a hidden field for the id and its own submit button. Another
one could have a single form with a single hidden field; when the user
clicks on the edit button, the hidden field is filled in with the
appropriate value through javascript, but this does require javascript
be enabled.

Probably the best way, IMHO, would be to redo your primary key on your
data. Rather than make it related to the data like you do have (a very
bad idea), have an independent field, i.e. an automatically incrementing
integer column. Then have the edit buttons with names such as edit_54,
edit_77, etc., where 54 and 77 would be the id's of your rows.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================