Jump to content


Photo

Insert line breaks on key press.


  • Please log in to reply
6 replies to this topic

#1 ldsmike88

ldsmike88
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts
  • LocationFlorida

Posted 03 October 2006 - 05:21 PM

I have several forms on my websites where the user can type in information, click submit, and it shows up somewhere on the website. The only problem is most of the people entering information don't have a clue how to write HTML. What I want to do is when the user presses submit I want to convert all the times they pressed enter into line break tags (br /). Does anyone know how to do this or have a really good tutorial I can use? Thanks!!

Michael

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 October 2006 - 08:59 PM

While you could do this in JS with a simple .replace() call onblur, or something equivalent, I would recommend that you do this on the server-side script.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 October 2006 - 10:24 AM

Use PHPs nl2br function instead. Use this when you display the data

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 October 2006 - 07:51 PM

It really depends what you're using it for... if you're _always_ going to be converting it, you might as well store it that way.  However, storing formatting in the DB is lazy and bad -- it's usually better to keep it pristine.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 ldsmike88

ldsmike88
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts
  • LocationFlorida

Posted 05 October 2006 - 01:09 AM

Well if I can do it with PHP does anyone know any good tutorials or have a script to copy and paste? Thanks!

Michael

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 October 2006 - 04:14 PM

If you want to convert newlines to html line break then use the nl2br function.

#7 ldsmike88

ldsmike88
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts
  • LocationFlorida

Posted 05 October 2006 - 06:47 PM

That nl2br works great. Thanks!

Michael




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users