Home arrow PHP arrow Page 4 - Creating a Simple Threaded Discussion Forum

Postre.php - PHP

Most websites have some method of interacting with a visitor. Some have a chat system and others have shoutboxes or other ways to attract the visitor to return. One of the most used methods is a discussion forum. And this is what we are going to create and discuss in this article (the first of two parts).

TABLE OF CONTENTS:
  1. Creating a Simple Threaded Discussion Forum
  2. Index.php
  3. viewarticle.php
  4. Postre.php
By: Jacques Noah
Rating: starstarstarstarstar / 39
October 16, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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!



 
 
>>> More PHP Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: