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.
<br> when user presses Enter
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: <br> when user presses Enter
I don't know what you mean.
My suggestions are either <textarea>, BBCode, or TinyMCE, or a combination of those.
My suggestions are either <textarea>, BBCode, or TinyMCE, or a combination of those.
Re: <br> when user presses Enter
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
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> </dd>
</dl>
<p align="center">
<input type=SUBMIT value="Send Message">
<input type="RESET"></p>
</form></td>
</tr>
</table></body>
</html>-
iBroughtCookies
- Forum Newbie
- Posts: 10
- Joined: Wed Jun 24, 2009 12:09 pm
Re: <br> when user presses Enter
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:
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!
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);
?>
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!
Last edited by Benjamin on Wed Jun 24, 2009 12:48 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Reason: Changed code type from text to php.
Re: <br> when user presses Enter
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?
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
anyways, leave it
i am using wysiwyg editors.
thanks for help
i am using wysiwyg editors.
thanks for help
Re: <br> when user presses Enter
This one is even bettercalifdon wrote:http://alexking.org/projects/js-quicktags