Spaces becoming underlines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan M Dunsmuir

    Spaces becoming underlines

    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_Count ry'. (I am using PHP5.)

    Where and why has this happened?

    Should I be prepared for any further character substitutions?
  • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

    #2
    Re: Spaces becoming underlines

    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_Count ry'. (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:

    <input name="<?=htmlsp ecialchars($foo )?>" ... >

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



    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:

    <input name="record_id " value="<?=htmls pecialchars($fo o)?>" ... >

    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
    --

    Comment

    • Rik Wasmus

      #3
      Re: Spaces becoming underlines

      On Mon, 21 Apr 2008 06:11:31 +0200, Alan M Dunsmuir
      <alan@moonrake. demon.co.ukwrot e:
      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_Count ry'. (I am using PHP5.)
      >
      Where and why has this happened?
      Thank the evil that is register_global s. 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="image" yields the <name of
      input>_x & <name of input>_y in PHP, while the client actually sends <name
      of input>.x and <name of input>.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

      Comment

      • Jerry Stuckle

        #4
        Re: Spaces becoming underlines

        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_Count ry'. (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@attgl obal.net
        =============== ===

        Comment

        Working...