RE: Formatting a form box

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What? Nobody said "This has nothing to do with PHP and databases?"  Sheesh... someone must be sleeping. :)  Ok, so it sorta does relate..

But yeah... no2br() will do it for you.  Textarea input types DO send a newline and/or carriage return (didn't test and might be system specific), so if you just take your form $_POST data and use nl2br() before you store it in the database (or probably after... should be able to store a newline/carriage return in the database) it should produce the results you desire.

test.php:

<form action="test.php" method="post">
<textarea name="testarea">
</textarea>
<input type="submit">
</form>
<?php

if (isset($_POST['testarea'])) {

  echo nl2br($_POST['testarea']);

}
?>

Look at the source code after you submit if you have any doubts/questions.

-TG

= = = Original message = = =

use the nl2br() function to convert the newlines to <br>


bastien

>From: Alex Major <alex.major@xxxxxxxxxxxx>
>To: <php-db@xxxxxxxxxxxxx>
>Subject:  Formatting a form box
>Date: Thu, 12 Jan 2006 16:33:01 +0000
>
>Hi there,
>On one of my forms, there is a section where users can put images etc..and
>then it is displayed on my php pages. My question is how do I make it so
>that the html formatting is automatically done. For example when someone is
>typing something, and wants to start a new paragraph although they press
>return when typing when the data is displayed from the MySQL database on a
>website it's just continuous text. For it to start a new paragraph they 
>have
>to put <p> in when they are typing in this box. They do not know all the
>html formatting codes, and so I need someway of making so that it is easy
>for them to have formatted text without doing all the html.
>Also things like changing colours, bold, italic and things would be good.
>Something like on forums, where when you enter a new post you have all the
>formatting options.
>
>Hope this makes sense,
>Regards,
>Alex.


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux