Creating a Simple Threaded Discussion Forum - Postre.php
(Page 4 of 4 )
This page enables you to reply to a specific thread. The thread number is passed on from the viewarticle page. Here we create a form and populate its title field with the $_SESSION['title'] variable.
<form name="form1" method="post" action="ins.php">
<input type="text" name="name">
<input type="text" name="title" value="<? echo "RE: " .
$_SESSION['title'] ."" ;?>">
<input name="parent" type="hidden" value='<? echo $parent//"".
$_GET['parent']. "";?>'>
</div>
<div align="center"><a href="index.php">Topic Listings</a>|<a
href="post.php?parent=0">Post New Topic</a> </div>
</div>
<div id="content2">
<p>
<center><textarea name="message" cols="75" rows="9"></textarea></center>
</p>
</div>
<div id="footer">
<center> <input type="submit" name="submit" value="submit"></form></center>
Once submitted, the form values are processed in the ins.php page and then inserted in the database.
post.php
This page is for new posts; it will send the form data off to the insert.php page, which will process and enter the details into the database.
And by the way...I've just created this function as something additional. The function will enable you to add... wait for it... smilies! All that the function does is to search for the ":D" or the ":A" delimiters and then replace that text with the images that has been assigned. You can extend this function by adding your own images and delimiters later on, to give your users a wider choice of smilies. Here's the function:
function insertsmilie($smilie) {
$smilie = str_replace(":D", "<img src="imagessmile.gif">",
$smilie);
$smilie = str_replace(":A","<img src="imagesangry.gif" >",
$smilie);
return $smilie;
}
fns_all.php
The script contains all the functions used throughout the application. I've already explained the main function called gettopics() and what it does. There is another function that I think needs a bit of explaining, the "badwords_filter($msg)" function. This function does exactly what its name implies, it replaces offensive words in a message that is posted. It is used in the ins.php script. It retrieves a list of bad words stored in a text file and then checks to see if any of them are included in the newly posted message. If it finds one, it replaces that word with XXX. Here's the code that does the job:
function badwords_filter($msg)
{
$obscenities = file("test.txt");
$newmsg = $msg;
foreach ($obscenities as $key=>$val)
{
$newmsg = str_replace(trim($val), "XXX", $newmsg);
}
return $newmsg;
}
Conclusion
Finally, I would suggest that you create a login script to go with this forum for the admin area.
Below is an example of an administrators area:

And this is what we will create next for our forum, in the next article. Till then have fun!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |