Skip to main content
WolfShade
Legend
August 27, 2012
Answered

Gah! Website has function that replaces chr(10) with spaces

  • August 27, 2012
  • 2 replies
  • 1796 views

Hello, everyone.

I am working on a website that has a function that will automatically replace all chr(10) with spaces when a form is submit. I cannot prevent this from being used.

When a form with a textarea is submit, all line breaks are being replaced with spaces, destroying the formatting of what was originally submit.

When pulling said text from a database, how can I go about reconstructing the line breaks and restoring the formatting?

Thank you,

^_^

    This topic has been closed for replies.
    Correct answer Miguel-F

    You could potentially use javascript to replace the lf characters before the form is submitted.  Replace all of the lf characters with some other character(s) that you can later (on the server-side) replace back into whatever character you want.

    I don't really like this solution but it could work.  It doesn't feel right to me because it is just a hack to get around the real issue.  I agree with Adam in that I would try to remove the offending software first.  Or at least have it stop stripping the lf characters.  Is it configurable as to what it replaces?

    2 replies

    Miguel-F
    Miguel-FCorrect answer
    Inspiring
    August 27, 2012

    You could potentially use javascript to replace the lf characters before the form is submitted.  Replace all of the lf characters with some other character(s) that you can later (on the server-side) replace back into whatever character you want.

    I don't really like this solution but it could work.  It doesn't feel right to me because it is just a hack to get around the real issue.  I agree with Adam in that I would try to remove the offending software first.  Or at least have it stop stripping the lf characters.  Is it configurable as to what it replaces?

    WolfShade
    WolfShadeAuthor
    Legend
    August 27, 2012

    What you suggest is what I wound up doing.  Hack, yes.  Unfortunately, it is my only option.  The function that replaces all the HTML is not configurable by me.  Only the higher-ups.

    ^_^

    Inspiring
    August 27, 2012

    What you suggest is what I wound up doing.  Hack, yes.  Unfortunately, it is my only option.  The function that replaces all the HTML is not configurable by me.  Only the higher-ups.

    Isn't that kind of subverting the intent of this policy to strip out this stuff?  If it's not your call to mess with the policy, are you sure you should be bypassing it?  Aren't you opening yourself up for a bit of grief?  You could well be on top of things already, but I figured I'd mention it just in case...

    --

    Adam

    Inspiring
    August 27, 2012

    You can't.  How can you tell which of the spaces used to be LFs, and which were already spaces?  You can't.  Simple as that.

    I would revisit this notion you have that "I cannot prevent this from being used".  You need ot go to whoever it is that makes that decision and say "we can't use that, because its screwing out data".

    --

    Adam

    WolfShade
    WolfShadeAuthor
    Legend
    August 27, 2012

    Unfortunately, I really can't prevent it from being used.  I am a federal contractor, my boss is the US gov't.  They want it used.  Period.

    ^_^

    Inspiring
    August 27, 2012

    Use a rich textarea.