Page 1 of 1
Help needed making code tags in forms (like in phpbb2)
Posted: Mon Feb 24, 2003 5:56 am
by Always_Stuck
Sorry, I do not really know how to explain this very well, as I do not know what I need.
I have a form that people type into which is then displayed as HTML. The problem is there is no formatting as my users do not know HTML.
I would like to have tags like the ones used in phpbb2 (the quick tags that appear above the form to allow bold and underline). So the user could just click on the bold button and suitable code will appear on the form.
I think I have an idea of how to get the form to convert the tags placed into HTML, but have not got a clue how to do get the buttons to place tags on the form!
(Also how can you make php/HTML realise when the user has made their own paragraph?)
Any help would be welcome!
Posted: Mon Feb 24, 2003 6:16 am
by patrikG
Hi Always_Struck,
this thread should help you:
viewtopic.php?t=6710

Posted: Mon Feb 24, 2003 6:45 am
by Always_Stuck
Thanks, that explains how to change the code to html and back, but how do you do the buttons hat make the code appear on the form straight away (Surely the page does not reload as the text that has already been typed would not appear)
(This might also help me understand how to make the page do things with php without constantly sending the variables back to the page through _POST and _GET)
Posted: Mon Feb 24, 2003 7:02 am
by patrikG
Use javascript. Below is some code which has a little button which inserts a smilie where the cursor is. However, the script does a bit too much for your purpose: it, not very elegantly, yet cross-browser, keeps track of where the cursor is, then inserts it there. Have play with it.
I suggest you read some FORM-related tutorials at webmonkey.com (Javascript-tutorials are at
http://hotwired.lycos.com/webmonkey/pro ... index.html), the Danny Goodman book "Dynamic HTML. The Definite Reference" will also give you valuable clues.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=content-type content=text/html;charset=iso-8859-1>
<script language="Javascript">
function smile()
{
smileText=document.getElementById('textarea1').value;
tempText1=smileText.substring(0,cursorPos);
tempText2=smileText.substring(cursorPos,smileText.length);
document.getElementById('textarea1').value=tempText1+":)"+tempText2;
cursorPos=smileText.length+2;
}
function keyPress(e)
{
var textlength=document.getElementById('textarea1').value;
if(navigator.appName == "Netscape")
var keypressed = e.which;
else
var keypressed = event.keyCode;
switch(keypressed)
{ case 37: // LEFT ARROW
cursorPos--;
// alert(cursorPos);
return;
case 39: // RIGHT ARROW
if (textlength.length>cursorPos)
cursorPos++;
// alert(cursorPos+" length: "+textlength.length);
return;
default: cursorPos++;
}
}
if(navigator.appName == "Netscape")
document.onkeydown = keyPress;
var cursorPos=0;
</script>
<BODY bgColor="#ffffee"><BR><BR>
<TEXTAREA id=textarea1 rows=10 cols=50 onkeydown="keyPress()"></textarea>
<input type=button value=Smilie onClick="smile();">
</FORM></BODY></HTML>
alternatively, have a look at the source-code of the "post"-page of this forum (with all the buttons, smilies etc.).
Posted: Mon Feb 24, 2003 7:14 am
by Always_Stuck
Thats Great, exactly the kind of thing I am looking for, I guess I better learn Javascript!
Just one more question, with these forums it records when you start a new line, but in my form I need to manually insert a BR tag, how can the code tell when the user has selected a new line?
Posted: Mon Feb 24, 2003 7:20 am
by patrikG
Posted: Mon Feb 24, 2003 8:18 am
by Always_Stuck
patrikG, THANK YOU!
I have been searching for these answers for weeks and you have just told me them a few hours! You have been a big help
I think I will be using this Forum more in the future
Thanks again