Post classified ads

Posting a new ad to the site is reduced to a simple insert operation, that will populate the ads_ads table with the entered data. The file that contains the elements to allow users post a new ad is called post_ad and is stored in the site root.

 

Now, to create the actual insert form, you will use the Insert Record Form Wizard. Open it by pressing its corresponding button on the MX Kollection tab of the Insert panel, and configure it as follows:

  1. First of all, in the wizard's first step, select the database connection created at the beginning of this tutorial, the table into which the insert operation will take place (ads_ads) and the page that will be opened if the transaction is successful.


     

  2. In the second step of the wizard, you will have to define what table column to display in the form, how they will be represented and submitted. When you move on to the second step by pressing the Next > button, the Form fields grid will already be populated with almost all the columns in the ads_ads table. The one that is missing is the primary key.

  3. As you have noticed in the application planning section, the ads_ads table stores the following data: the user, ad type, ad category and ad location ID's, the title and the content of the ad. The ID's are stored as numeric values, and in order to display them conveniently for the users, you should use drop-down menus that retrieve their values from the type, category and location table. The user ID is most easily taken from the session variable.

  4. Select the fields from the grid, and change their properties as follows:
    · For the idusr_ads field, set the Display as to text, and in order to retrieve the currently logged in user's ID, in the Default Value text-box select the kt_login_id session variable from the InterAKT Dynamic Data dialog box:



    · The next field is the idtyp_ads, that stores the id of the ad type. Types are stored in a separate table, type_typ. To avoid having the users enter the numeric value, set the form element to be used to Menu (from the Display as drop-down menu). Two more buttons became available: Add recordset and Menu Properties. As their names suggest, the first will be used to create a recordset that will retrieve the types from the database, and the second will configure the menu to use the correct columns to display labels, and store values.
    · Click on the Add Recordset button. The standard new recordset dialog box will open. Configure it to retrieve all records from the type_typ table, through the database connection you've created at the beginning of this tutorial. When you're done configuring it, click OK to return to the Insert Record Wizard.
    · Now configure the menu to use the recordset you've just created. Click the Menu properties button, and select the appropriate options: the recordset name, the label column (name_typ) and the values column (id_typ). Then click on OK to finish configuring the menu.
    · For the category and location fields, you will proceed in a similar manner, changing the recordset each time to retrieve data from the desired tables: category_cat and location_loc. For the category recordset, there is one more thing to consider: the main categories cannot have ads, so you must filter the recordset so that records that have the idcat_cat field equal to the entered value 0 will not be retrieved, as you can see in the image below:



    · There are only three more fields left to configure: for the title, you can use the default settings, but for the content, change the form element from text-field into a text area.
    · The last field, the date_ads, which stores the date when the ad was posted will not be visible in the page, as it will be automatically filled in. Change its associated form element to text, and enter in the Default value text field the following mark-up: {NOW}. This will be automatically replaced at runtime by the Transaction Engine with the current date in the correct format.

    Note:
    If you are using a Microsoft Access database, in the Submit as drop-down menu, for the date_ads column, another option will be available: Date MS Access. Select this option when submitting the date.

    · Now the Insert Record Form Wizard step 2 dialog box looks like:


     

  5. The third step of the wizard is only available if you have MX Form Validation installed, either as a separate product, or as a part of MX Kollection. It allows you to set rules for the form elements, submitting them only if they pass validation. You will not need validation on these fields, so you can safely skip this step.

  6. If you forgot something, or did it wrong, you can click on the < Back / Next > buttons to move through  the wizard's steps. When you consider the configuration to be finished, click the Finish button to close the wizard.

  7. The wizard will add some server behaviors, for the transaction and the associated triggers, as well as all form elements required. After closing the wizard, remove the first row of the table, the one containing the idusr text. The Dreamweaver editable area will look as follows:

 

Due to the Restrict Access to page server behavior you've added to the page in the first step, you must first login with the correct user name and password before accessing the actual insert form. After you log in however, open the post ad page, and complete it with some test data. Open the database server management software, and check if the submitted data has been correctly inserted into the database.

The next topic shows you how to use MX Includes in order to improve your site.