Building a Forum with Dreamweaver – Part 3: Creating the Form That Enables Users to Post Messages
Creating the Form That Enables Users to Post Messages
To allow users to post a message, you need to create an insert form that takes user input and adds it to the message_msg
database table. To build the page, follow these steps:
- Open the post_message.php page in Dreamweaver.
- The layout is already created. In the main
<div>
container, select the placeholder text and remove it. This is where you will place the actual form for posting messages. -
Launch the Insert Record Form Wizard from the MX Kollection tab of the Insert bar (see Figure 4).
The wizard steps you through the process of generating the form and the insert transaction.
-
In Step 1, select the database connection you’ve created in Part 1 of this tutorial (
connForum
) and the table to insert data into (message_msg
). After posting the message, users should be redirected to the view_messages page, and the ID of the topic should be passed to it as a URL parameter. Otherwise, the page will be blank. -
To add the URL parameter to the page, without actually writing the code yourself, use the InterAKT Dynamic Data dialog box. Click the Browse button and select the view_messages.php page in the site root. Type the following text after the page name in the After Inserting Go To text box:
?id_top=
-
Click the blue lightning bolt icon next to the text box (see Figure 5). This opens the The InterAKT Dynamic Data dialog box.
-
Select the type of variable and enter its name (see Figure 6):
- In the Get Values From pop-up menu, select URL Parameter.
-
In the Variable text box, enter the name: id_top.
-
Click OK to return to Step 1 of the Insert Record Form Wizard, which should now look similar to Figure 7.
-
Click Next to proceed to Step 2, where you have to configure your form fields as follows:
- Remove the
idmsg_msg
andid_init_msg
fields from the grid. These fields are not needed at this time. Theidmsg_msg
column is needed only when replying (which is currently not the case), and theidinit_mg
field will receive its value after the transaction is completed. - Set the
idtop_msg
field to be displayed as Text, and set Default Value to be equal to the URL parameter namedid_top
. To do that, select the field and click the blue lightning bolt icon next to the Default Value text box. In the dialog box that opens, select URL Parameter from the first pop-up menu and enter id_top in the Variable field. -
Set the
idusr_msg
field to be displayed as text, with Default Value equal to the session variablekt_login_id
. Click the blue lightning bolt icon to access the InterAKT Dynamic Data dialog box, select the session variablekt_login_id
(see Figure 8), and then click OK. -
The date should also get its value automatically, in order to store the date and time when the message was posted. Select
date_message
, set Display As to Text Field, and set Default Value to the following mark-up code:{NOW_DT}
ImpAKT uses a simple markup language that is replaced at runtime with the corresponding values (in this case, the current date and time—see Figure 9). This markup language is easy to learn and is independent of the server model you are using. This means that
{NOW_DT}
will always be replaced with the current date and time, whether you work on ASP, PHP, or ColdFusion. - Keep the default settings of the
subject_msg
field. - Set the
content_msg
field to be displayed as a text area. -
The
subscribe_msg
column is stored as either 1 or 0 in your database. Therefore, you should display it as a check box; in the Submit As text box, enter Checkbox: 1,0 (see Figure 10).At this point, Step 2 of the wizard should be configured as shown in Figure 11.
-
Click Next to proceed to Step 3 of the wizard, where you define any needed validation rules. The user will only see the subject and content fields. To stop users from posting empty comments, be sure to make the
subject_msg
andcontent_msg
columns mandatory. Select each of them in the grid and select the Required option (see Figure 12). -
To apply these settings and complete the wizard, click the Finish button.
The web form is generated inside the center
<div>
container, and the necessary server behaviors are added to the Server Behaviors tab (see Figure 13). If you need to edit any of these behaviors (the Insert Record transaction or the Validation options), simply double-click their names in the Server Behaviors tab and the corresponding dialog box will open. -
Since the
Idtop
,Idusr
, andDate
fields do not need to show up at runtime, select their rows and remove them (see Figure 14). They should not be removed from the Insert Record transaction; remove them only from the HTML form. The idea is to have their values set automatically by the transaction—not to make them visible to users. -
In the Property inspector, enter Post in the Value text box to change the label of the Submit button (see Figure 15).
In the next section, you will learn how to associate messages to a thread.
Comments