Page 1 of 1

<br> when user presses Enter

Posted: Wed Jun 24, 2009 10:33 am
by anand
Hi, I am making a forum where I want to have a system by which, while composing a message, whenever a user presses the enter key, then a new line ( \n or <br>) should come up. Also, same goes for bold and italics.

( P.S. Just like this forum.)

Please help.

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 10:44 am
by jayshields
I don't know what you mean.

My suggestions are either <textarea>, BBCode, or TinyMCE, or a combination of those.

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 11:19 am
by Eric!
The actual text area is done in HTML with a textarea and a form. The data is then passed on to a php script which needs to filter it for possible XSS, SQLi or email (if going to the mail() function) attacks. Please educate your self on how to filter for those things before making your site available to the public.

Here is a form that passes the data via $_POST to message.php

Code: Select all

<html>
<head>
<title>Contact Us</title>
</head>
<body>
<div align="center">
  <center>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="453">
  <tr>
    <td valign="top" height="100%" style="border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:none; border-bottom-width:medium" width="453">
    <form name="Message" action="message.php" method="POST" >
      <p><strong>Enter your message in the space provided below:</strong></p>
      <dl>
        <dd>
        <textarea name="Comments" rows="5" cols="42" style="text-align: left; line-height: 100%" maxlength="1000"></textarea></dd>
        <dd>&nbsp;</dd>
      </dl>
      <p align="center">
      <input type=SUBMIT value="Send Message">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="RESET"></p>
    </form></td>
  </tr>
</table></body>
</html>

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 12:25 pm
by iBroughtCookies
I would send the data to mysql, then when the data is pulled FROM mysql(I.E. when a user views a page), then you would run this code:
So let's say that you already retrieved the post data, and it's stored in the variable $text:

Code: Select all

 
<?php
$text = str_replace('
', '<br />', $text);
$text = preg_replace('/[b](.*?)[\/b]', '<b>$1<\/b>', $text);
$text = preg_replace('/[i](.*?)[\/i]', '<i>$1<\/i>', $text);
?>
 
Now $text WOULD contain formatted code;
HOWEVER, I can pretty much tell you for a fact that that preg_replace is wrong because I don't know how to use regular expressions :(
Still learning!

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 1:55 pm
by anand
ok, let me explain.

I have a textarea where users can write reviews. Now to make that attractive, users might want to add designs, .like bold, italics, list etc.

now, how to give that features to users?

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 2:01 pm
by califdon

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 2:06 pm
by anand
anyways, leave it

i am using wysiwyg editors.

thanks for help

Re: <br> when user presses Enter

Posted: Wed Jun 24, 2009 2:11 pm
by anand
This one is even better