Insert both company and main contact

When adding a new company, almost in all cases you already have at least one contact for it. So, wouldn't it be easier if you could add the main contact alongside the company? This means that you will insert information into the company and the contact tables from the same page, using a single page submit operation.

In MX Kollection 3 you can do this, by using the Insert Into Two Tables Wizard. To build such a page, you need to follow the next steps:

  1. First create a new file in the site structure, in the company folder. The name used in this tutorial is insertcomcon. To create a new file, select the company folder in the Files tab, and then select the New option from the File menu. Type in the file's name, followed by the extension required by your server model .
  2. Open the newly created file in Dreamweaver. The page design will be similar to the one used for the regular company insertion page. Copy the design section and change the header text to "Add company and main contact" (without the quotes):


                                
  3. Click in the empty paragraph after the horizontal rule, and apply the Insert Into Two Tables Wizard. You can open it by clicking on its button, found on the MX Kollection tab of the Insert bar.
  4. The wizard's user interface can have three or five steps, depending on whether you have MX Form Validation installed or not. The first three steps define all options for the tables and fields used in the transaction , while the last two steps allow setting up validation rules for each form field.
  5. This wizard benefits from the user interface persistence implemented by MX Kollection 3. If you haven't already created the insert page for companies and the insert page for contacts, you should do that now. If you already have created them, proceed with configuring the wizard:
    · In the first step you must configure the connection, table and primary key fields to use:



    · The Connection drop-down menu already contains the connection you've already used throughout this tutorial.
    · In the Master table drop-down menu select the company_com table. The id_com field is selected by default in the Primary key column drop-down menu.
    · In the Detail table drop-down menu select the contact_con table. The Primary key column and Foreign key column will be automatically completed with id_con and idcom_con.
    · Thanks to the user interface persistence, the After inserting, go to text field already contains the name of the index file.
    · At this point you can already click the Finish button to exit the wizard's configuration, as the fields to use for each table's form have their properties set from the persistence cache. Browse through the wizard's next steps to make sure everything is in order:



    ... the company's name and address fields ...



    ... and the contact's table fields.
    · As you can see, the idcom_con field does not appear in the Form fields grid of the wizard's third step. That is because the value for the foreign key field is set automatically to the unique identifier of the company that is added.
    · At this point click on the finish button to add all elements into the page. The wizard will add the HTML form elements, as well as the server behaviors used to perform the insert operation.


                       
  6. Now the insertcomcon page is finished, and you can save and test it. Preview the page in the browser by pressing the F12 key, and add a new company and its main contact. When you return to the listing page, you will notice the new pair being displayed:

          

If you prefer this method of adding a company, replace the link to add a company from the index page, to point to the new insert page (insertcomcon).

In the next topic, you will learn how to enhance this insert method by allowing the choice of adding some more contacts after the company insert.