Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

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:

  1. Open the post_message.php page in Dreamweaver.
  2. 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.
  3. Launch the Insert Record Form Wizard from the MX Kollection tab of the Insert bar (see Figure 4).

    Insert Record Form Wizard icon

    Figure 4. Insert Record Form Wizard icon

    The wizard steps you through the process of generating the form and the insert transaction.

  4. 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.

  5. 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=

  6. Click the blue lightning bolt icon next to the text box (see Figure 5). This opens the The InterAKT Dynamic Data dialog box.

    InterAKT Dynamic Data icon

    Figure 5. InterAKT Dynamic Data icon

  7. Select the type of variable and enter its name (see Figure 6):

    1. In the Get Values From pop-up menu, select URL Parameter.
    2. In the Variable text box, enter the name: id_top.

      InterAKT Dynamic Data dialog box

      Figure 6. InterAKT Dynamic Data dialog box

  8. Click OK to return to Step 1 of the Insert Record Form Wizard, which should now look similar to Figure 7.

    Step 1 of the Insert Record Form Wizard

    Figure 7. Step 1 of the Insert Record Form Wizard

  9. Click Next to proceed to Step 2, where you have to configure your form fields as follows:

    1. Remove the idmsg_msg and id_init_msg fields from the grid. These fields are not needed at this time. The idmsg_msg column is needed only when replying (which is currently not the case), and the idinit_mg field will receive its value after the transaction is completed.
    2. Set the idtop_msg field to be displayed as Text, and set Default Value to be equal to the URL parameter named id_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.
    3. Set the idusr_msg field to be displayed as text, with Default Value equal to the session variable kt_login_id. Click the blue lightning bolt icon to access the InterAKT Dynamic Data dialog box, select the session variable kt_login_id (see Figure 8), and then click OK.

      Selecting the kt_login_id session variable for the user ID

      Figure 8. Selecting the kt_login_id session variable for the user ID

  10. 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.

    Setting the date field

    Figure 9. Setting the date field

  11. Keep the default settings of the subject_msg field.
  12. Set the content_msg field to be displayed as a text area.
  13. 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).

    Using a check box for the subscription

    Figure 10. Using a check box for the subscription

    At this point, Step 2 of the wizard should be configured as shown in Figure 11.

    Step 2 of the Insert Record Form Wizard

    Figure 11. Step 2 of the Insert Record Form Wizard

  14. 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 and content_msg columns mandatory. Select each of them in the grid and select the Required option (see Figure 12).

    Step 3 of the Insert Record Form Wizard

    Figure 12. Step 3 of the Insert Record Form Wizard

  15. 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.

    Form added by the wizard

    Figure 13. Form added by the wizard

  16. Since the Idtop, Idusr, and Date 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.

    Final version of the message insert form

    Figure 14. Final version of the message insert form

  17. In the Property inspector, enter Post in the Value text box to change the label of the Submit button (see Figure 15).

    Changing the label of the submit button

    Figure 15. Changing the label of the submit button

In the next section, you will learn how to associate messages to a thread.

Comments