This topic is locked

Forum template

3/23/2010 9:43:28 PM
Xlinesoft Labs
Sergey Kornilov

A few people asked how you can build a forum with PHPRunner. To illustrate this we have built very basic forum template that you can use, study, modify etc.
Forum template for PHPRunner 5.x/6.x download link.
For PHPRunner 7.x or better download it from our marketplace.
Unzip it to <Directory where PHPRunner installed>\templates\business. Then create a new project choosing Forum template from list of templates on the left.
This template is for PHPRunner at the moment. You also need to have CKEditor plugin installed in order to use this template.
A few words on how this forum works. Guest users are able to browse topics. To post a new topic or answer existing one you need to register. No threads or posts can be deleted. Users can edit their own posts though. Admin area and other potentially useful stuff were omitted for the sake of brevity.
Now the tricky part. When new topic is created we need to add a record to both Threads and Posts tables. Another trick is to make search function to search across both threads and posts.
1. Database

We have three tables here.

Users - serves as a login table

Threads - stores general thread info

Posts - stores actual posts
Threads and Posts are related as Master-Details.

2. SQL Query
Add a new dummy field to the SQL Query of Threads table. We are going to need this field on thread add page.






'' AS post

FROM threads

3. Pages and fields
Uncheck pages and fields we don't need.
4. Security screen
Turn on login page. Users table, username/password fields. Under User Login Settings enable options that make sense for this app.
Under Advanced Security settings enable Guest login and choose 'Users can see other users data; can edit their own data only' mode for posts table (users can edit their own posts). Use ID from Users table and userid from posts table to create a link.
5. Choose theme
Pick one of themes with search box on the top. We decided that Madrid will work the best for this application.
6. Visual Editor
We'll need to modify list pages of Threads and Posts tables to make it visually appealing.

  • Threads list page

    Remove unnecessary buttons, rename labels (records->threads), add new grid column named 'Stats' and drag number of child records (posts) there.
    Now we need to make Title link to posts page. Set 'View as' format to 'Custom' and enter the following code there:

$value = "<a href='posts_list.php?mastertable=threads&masterkey1=".$data["ID"]."' style='font-size: 120%'>".$value."</a>";

You might ask where this fancy URL came from. Before I started making changes in Visual Editor I built this app and went to Threads list page. A typical link to details page looks like posts_list.php?mastertable=threads&masterkey1=1. I replaced 1 with $data["ID"] and made it look more prominent (style='font-size: 120%').
A few final touches. Increase row height a bit to make the list of topics more readable. Drag 'Description' field to 'Topic' column and change font color to grey. Remove grid columns you no linger need.
Rename 'Add new' button to 'Start new topic'. To make this button appear on the left switch to HTML mode and find style descriptions in the beginning of the file.

Make #recordcontrols_block look as follows:

#recordcontrols_block{$id} {padding:13px 10px 9px 10px;text-align:left}

  • Posts list page
    Rearrange fields in similar fashion and remove unnecessary grid columns.
    Now we need to pull 'title' and 'description' fields from corresponding Threads record. Put mouse cursor into grid header row, switch to HTML mode and insert two placeholders there separated by space:

{$topic} {$description}

When you switch back to visual mode you can see those placeholders appear as yellow rectangles.
Rename 'Inline add' button to 'Add Reply' and move it to the left modify #recordcontrols_block description in HTML mode the same way we did it on Threads list page.

  • Threads add page
    Double-click on 'Message' field and set 'Edit as' format to 'Textarea'. Choose CKEditor from the list of Rich Text Editors.
    7. Events.
    Now the fun part.
    - AfterSuccessfulLogin event
    We need to save ID from users table in session variable and redirect user to Threads list page.


header("Location: threads_list.php");


  • Posts table: BeforeDisplay event
    Remember those 'title' and 'description' placeholders we added on posts list page. Now it's the time to populate them using $_REQUEST["masterkey1"] as a pointer to record in master table (Threads).

$rs = CustomQuery("select * from threads where id=".$_REQUEST["masterkey1"]);

$data = db_fetch_array($rs);

$xt->assign("topic", $data["title"]);

$str = "<span style='font-weight: normal'>".$data["description"]."</span>";

$xt->assign("description", $str);

Values in grid header row will appear bold on the page so we change font weight to normal for description field.

  • Posts table: Before record added event
    We want to timestamp each reply automatically and populate 'userid' field with ID value from Users table (saved in AfterSuccessfulLogin event).

$values["created"] = now();

$values["userid"] = $_SESSION["ID"];
return true;

  • Threads table: BeforeRecordAdded event
    The value of dummy field 'post' needs to be saved in session variable as we need to add it to Posts table. Since 'post' is a dummy (non-existent) field we need to remove it from the list of fields to be inserted using unset($values["post"]).

$_SESSION["post"] = $values["post"];

return true;

  • Threads table: AfterRecordAdded event
    Now we can add a record to Posts table linking it to the Thread we just created.

global $dal;

$posts = $dal->Table("posts");

$posts->threadid = $keys["ID"]; // thread ID

$posts->message = $_SESSION["post"]; // message we saved in session variable

$posts->created = now(); // timestamp

$posts->userid = $_SESSION["ID"]; // ID from users table


If we want to redirect user to another page after new topic was created - we need to do so in this event as well. Right now user stays on the same 'Start New Topic' page.

  • Threads page: BeforeSQLQuery event
    And the last step - we need to tweak search function a bit so it can search threads title and description fields as well as posts.
    IF statement makes sure this code executed only when we run search. We run search on JOIN query and then return a list of thread IDs that match our criteria.

if (@$_REQUEST["a"]=="integrated" && @$_REQUEST["ctlSearchFor"])

$strWhereClause = " id in (SELECT distinct threadid FROM threads inner join `posts` on

WHERE message like ('%".$_REQUEST["ctlSearchFor"]."%') or title like ('%".$_REQUEST["ctlSearchFor"]."%')

or description like ('%".$_REQUEST["ctlSearchFor"]."%'))";

This is it. You can build it now and run it in the browser.

As a next step you can add an admin area, give admin permissions to rename/delete topics, add mass email capabilities, add CAPTCHA etc. It also makes sense to allow users edit their own data i.e. change email address.
You are welcome to post questions and suggestions for the next version. If someone wants to take this template to the next level - we'll be glad to provide all required assistance including posting updated versions of template here.

titanic 3/25/2010

excellent... this tutorial will reduce the questions in future..

mcebula 3/25/2010
Kabukiblood 3/25/2010

So I installed this template, verified all information was correct, built it, but when I click New Topic I get the following error.
php error happened
Technical information

Error type 2

Error description include(plugins/ckeditor/ckeditor.php) [function.include]: failed to open stream: No such file or directory

URL localhost/forum/threads_add.php?

Error file C:\wamp\www\Forum\threads_add.php

Error line 844

SQL query
Any help would be greatly appreciated.

Sergey Kornilov 3/25/2010

make sure CKEditor plugin is installed. Check 'Rich Text Editor plugins' topic in PHPRunner manual for more info.

Kabukiblood 3/25/2010

make sure CKEditor plugin is installed. Check 'Rich Text Editor plugins' topic in PHPRunner manual for more info.

Thank you I am checking that now

Mwilson91325 5/3/2010

Any news on when we will see this for ASPrunner 6.2 for access?

sbillett 9/30/2010

You were asked in May 2010 when the ASPrunner Version would be ready, Any News??
I am am sure a man like you could knock it up in five minutes and make us all <img src='' class='bbc_emoticon' alt=':rolleyes:' /> happy <img src='' class='bbc_emoticon' alt=':rolleyes:' />

MrMyszek 4/27/2011


I tried several times to run the forum template PHPRunner 5.3 and each time it ended in failure. Please help where is the problem. I copied the unzipped files to a specified directory and does not appear in the window of the templates.

Thank you for your help.

Sergey Kornilov 4/28/2011

you need to contact support directly sending a screenshot that shows where you have installed this template on your system.

mitzi 12/21/2012

We'll have ASP version shortly along with step-by-step video tutorial. You also need to have CKEditor plugin installed in order to use this template.

Do you have it available already for the ASPrunner,please?

Tandy 4/6/2016

I have bought the New Forum Template 2 months ago.. When will the new Template be released?
Thank You.

Sergey Kornilov 4/19/2016

@Tandy Services,
Forum template was released, please logon to your Marketplace account and download it.

Tandy 4/19/2016

Thank you Sergey..