Posting to the Forum

 

This lesson is part of an ongoing Foruml tutorial. The first part is here: Build your own Forum, along with all the files you need. The previous lesson is here.

The final part of the walkthrough looks at how to allow users to post a new topic on the forum. There is one useful database technique that may come in handy in your own code - how to deal with primary key fields that are not auto-incrementing numbers. Let's make a start.


The Post Form

The form that the user fills in to post a new topic is this:

A Basic form to Post forum replies


As you can see, it's fairly basic, and you can definitely improve on this!

The form is similar to the Reply form, except for the addition of a text box. And we're doing the same things in the code: hand over values to another php page for processing. If you open the page called postForm.php, you can examine the code for yourself.

Again, we're using the POST method to post the form data to a php page:

METHOD ='POST' ACTION ='resultsP.php'

The page we're posting the data to is called resultsP.php. We'll take a look at this code in a moment, but notice the hidden variables:

$hidSec = "<INPUT TYPE = Hidden Name = h1 VALUE =" . $secCode . ">";
$hidMem = "<INPUT TYPE = Hidden Name = h2 VALUE =" . $memberid . ">";

We want to hand over the forum section code (secWP), and the member id. The text box on the form has been given the name tp, and the text area is called post. With this in mind, take a look at the resultsP.php page (in your forum folder).