Add conferences with validation

In this topic you will learn how to create the form that allows adding new conference information into the database. The insert operation will be handled with the Insert Record Form Wizard. However, not any kind of data will be allowed into the database. Information that is submitted must obey several rules:

  1. The start date must be in the future.

  2. The end date must be greater than the start date entered by the user.

  3. If no conference center has been specified, the address will not be required. If a conference center is entered, the address will become mandatory.

To build this page, you must first build the basic insert form, with no special validation options. These will be configured afterwards.

Build the insert form

The insert form will be created using the Insert Record Form Wizard from ImpAKT:

  1. Open the add page in Dreamweaver.

  2. Go to the Insert bar > MX Kollection tab and click on the Insert Record Form Wizard button (the first on the left edge). The user interface that loads is divided into three steps. Configure them as shown below:

  3. In the first step define database related information, and what page to load after the insert completes:

  4. In the second step define the fields to use in the transaction. You can set the fields properties by selecting each one of them and using the controls below the Form fields grid:

  5. The third step of the wizard allows you to define validation rules for each field. You do not have to change any rule at this point, as it will be done later on.

  6. Click Finish to exit the wizard and apply the changes.

 

All form elements have been added to the page by the wizard. The insert form is fully functional, missing only the validation elements explained on top of this page. This is how the page should look in browser

 

Compare dates in the same form

In this section of the tutorial you will learn how to enforce date rules: the start date will be set to be in the future, and the end date will be set to be further into the future than the start date. This is accomplished for the form added with the Insert Record Form Wizard by editing the Validate Form server behavior that is automatically added.

This is how the server behavior tab should look like after having added the insert form above:

 

To define the validation rules for dates, follow the steps below:

  1. Double-click the Validate Form server behavior to edit it.

  2. The interface displays all the recognized form fields in a grid, with their names and properties. You can change the settings for any of them by selecting it in the grid and changing values in the controls below. For this part, you are only interested in defining rules for the start and end date.

  3. First the start date. It must be in the future, which can translate to it being greater than today. To define this rule:

  4. Next, the end date. The condition for this field is that it must be greater than the start date.

  5. This is all that is needed to set up date validation rules. The configured user interface should look like the following:


                           

  6. Click OK to close the interface and apply the changes.

Now test the page. Save it and preview it in browser. If you try entering an incorrect end date, the entered error message will be displayed:

 

 

The next step is to make the address field required only when a conference center has been specified.

Make a field required if another field is filled in

Requiring a field when another has a value also requires the use of the Validate Form server behavior, which will start conditioned by the fact that the other field has a value. Because the rest of the validation rules have to get executed independent from this condition you will add another Validate Form server behavior which will work only on the address field:

  1. Go to the Server Behavior tab > Plus (+) > MX Kollection > Form Validation and apply the Validate Form server behavior.

  2. By default, all fields are marked as not required and without any validation - you can see it in the grid. To make the address field required, select it in the grid, and then check the Required checkbox below the grid:


                           

  3. Also check the Custom message option, and in the Error message text field enter Please specify the address of the convention center.

  4. Next you have to configure the form validation to execute only when a conference center has been specified (in the building_con field). To do so, click on the Advanced tab. This is where you can define a condition to start the execution. You can either type the condition directly, or, better yet, use the Condition Builder.

  5. In the Advanced tab click the Build Condition button. This will open a new user interface with three fields: the two expressions and the operator. The two text boxes for expressions have the InterAKT dynamic data icon. Configure this user interface as follows:

  6. Back in the Validate Form user interface, the condition you built has been entered into the text box:


     

  7. You can now click OK to apply the server behavior to the page.

Save the page and load it in a browser. To test it, enter correct dates (you've already configured it above) and only the conference center name, with no address. An error message will be displayed:

 

The application is now complete. It will only allow adding conferences that start and end appropriately, and will require an address whenever a conference center is specified.