Skip to main content
Inspiring
February 2, 2007
Question

Line Break In INPUT TYPE=TEXT

  • February 2, 2007
  • 5 replies
  • 4364 views
More HTML-related, but it's within my ColdFusion application, so...

I have a standard text field (INPUT TYPE=TEXT) with a MAXLENGTH value... nothing fancy. Everyone knows that text fields (not to be confused with TEXTAREA) do not accomodate line breaks. On occasion however, I'm finding rows in our database where the user somehow managed to split what they've entered into two lines, for example:

John Smith has
a red car.

How is that even possible? I could easily write a quick script to remove hard returns in the data being submitted, but I'm more curious as to how it's possible (plus I don't feel like implementing a script on ever text field in my application). I've tried pasting in two-lines of text, no go. Shift + <Enter> doesn't work either. From what I can tell it's just a normal line break. Any ideas?
    This topic has been closed for replies.

    5 replies

    Inspiring
    February 8, 2007
    which database are you using? in order to test your condition properly we need to know your setup: CF ver, database type, web server used, etc...

    I have tested with CF702 on IIS and MySQL 5, and no, pasting milti-line text into <input type="text"> does not linebreaks - it only inserts first line.

    Another guess would be that maybe that field was of type memo/longtext before, and what you are seeing is text entered into it at that time? Has the database table been modified lately?

    Inspiring
    February 5, 2007
    The input is being copied/pasted from another document (my guess at least). If the copied text has a line break in it, it will be pasted that way in the input field and as long as the pasted text does not exceed the maxlength, it will be written to the database with a break in it.

    If none of your fields should have line breaks, you can just make a quick loop that uses the 'form' scope and just remove chr(10) & chr(13) from all the form fields before you do the rest of your validation on your action page. If you have certain fields that need to retain line breaks, just make a list of the fields and skip those fields in the loop.

    CR
    Inspiring
    February 7, 2007
    I'd like to think it's the cut-and-paste issue, but I've tried recreating it with no luck.

    Has anyone been able to reproduce the insertion of a line break into a single-line TYPE=TEXT field?
    Inspiring
    February 5, 2007
    to follow more on CJ's post:
    please do the <cfdump> of the query that pulls the data from the db and see if that displays your text on 2 lines as well...
    what type of database are you using?
    February 2, 2007
    To follow on to CJ's question, are you doing CFOUPUT in a table cell? If so, the table may be constraning the output width, causing the wrap. Or prehaps the user entered <BR> into the text box.
    February 2, 2007
    where are these rows being output to that you're seeing the text broken over 2 lines? a <cfoutput>? thru query analyzer (or whatever front-end tool exists for your database of choice)?
    Inspiring
    February 4, 2007
    I'm looking at the output directly in the database... somehow the user is able to break their text field input into two lines, at least that's how it's being stored in the database. Like I said, it's only happening once in a blue moon, and I can't recreate it.

    There's definitely no HTML line breaks in there, or else I'd actually see the code in the database.