You are here: DEVPPL Forum Programming PHP and MySQL Forum
NOTIFICATIONS
54.059
MEMBERS
15.676
TOPICS
62.240
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Textarea form element and PHP/MySQL

0

Loading

Textarea form element and PHP/MySQL

Postby Mneder » Thu Oct 14, 2004 6:35 pm

This is probably a "newbie" question but here it goes: (question first then background)

My questions is whether there is a php or SQL solution to allowing people to input multiple paragraphs in a single "textarea" HTML field and then maintaining those paragraph breaks in the HTML output by my PHP code.


I have created a form that web visitors can fill out. It has the typical one line "input type=text" fields and a "textarea" field. I would like to allow people to put in multiple paragraphs (separated by a blank line) in the textarea field.

When I store the "textarea" content in the MySQL DB and subsequently display it via my PHP script for the world to see, the multiple paragraphs put into the textarea are collapsed into one big paragraph by the normal HTML behavior (because there are no "p" or "br" tags). I tried to use the "PRE" tag to prevent this but then the problem turns into a wrapping issue. I have tried different variations of the "Wrap" attribute to the "textarea" field, but am not happy with the results when compared across the IE, Netscape, Opera, Safari, Windows/Mac browsers.
Mneder
 
Reputation: 0
Posts: 1
Joined: Thu Oct 14, 2004 5:55 pm
Location: Mountain View, CA
Highscores: 0
Arcade winning challenges: 0

Textarea form element and PHP/MySQL - Sponsored results

Sponsored results

Login to get rid of ads

 

0

Loading

Postby Malcolm » Fri Oct 15, 2004 12:20 am

Once you have submitted the forum pass the variable through nl2br to have line breaks entered as HTML.
Like:
Code: Select all
$ktextarea_input = nl3br($_POST['textarea']);


Also, make the forms method=post:
Code: Select all
<form name="form1" action="page2.php" method="post">

Using post as the forms method allows the data not only to be secure but also allows you to have a larger text lenght.

Hope that helps :)
Image
Malcolm
 
Reputation: 0
Posts: 198
Joined: Thu Oct 07, 2004 10:53 pm
Location: Ontario, Canada
Highscores: 0
Arcade winning challenges: 0
^ Back to Top