Adobe
In this tutorial you will use Developer Toolbox features to build a web application for managing the contacts of a person or company. Multiple companies or individuals can be created, each with one or more contacts. The application will let you:
This tutorial contains three parts, starting from the basic functionality, and enriching it with different features:
In this last part of the tutorial you will enhance the web-application already created by adding features that will save time and make it more user-friendly and interactive.
The following topics of the
tutorial are optional, as they only add features to the already finished
application. They will teach you how to:
This section contains the following topics:
The estimated completion time for this section is about 40 minutes. It depends on your authoring knowledge with Adobe Dreamweaver and Developer Toolbox.
The estimated completion time for all parts of this tutorial (considering the initial planning, the mandatory sections and the proposed improvements) is about 100 minutes. It also depends on your authoring knowledge with Adobe Dreamweaver and Developer Toolbox.
It's recommended that you follow all tutorial parts in the intended order to avoid potential problems.
In order to complete this tutorial, you need to install the following software and files:
I would recommend that you are familiar with Dreamweaver CS3 Recordsets. Working with Server Behaviors will also be helpful.
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 Developer
Toolbox you can do this by using the "Insert Into
Two Tables Wizard." To build such a page, follow the instructions below:
This wizard benefits from the user interface persistence implemented by Developer Toolbox. If you haven't already created the insert page for companies and the insert page for contacts, you should manually configure this wizard. If you have already created them, you will have to configure only the first step of this wizard and then just check the next steps to validate them:
In the first step you must configure the connection, table and primary key fields to use (see Figure 1).

Figure 1. First step of the "Insert Into Two Tables Wizard"
If you have created the insert companies and contact pages, it’s safe to click the Finish button to apply the code to the page—as the fields to use for each table's form have their properties set from the persistence cache. However, you may browse through the wizard's next steps to make sure everything is correctly filled in (see Figures 2 and 3).

Figure 2. The company's name and address fields

Figure 3. The contact's table fields
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 operations (see Figure 4).

Figure 4. Insert into two tables page in Design View
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.
In this section of the tutorial, you will learn how to configure the newly created insert page (insertcomcon), so that you can decide if you want to add more contacts after inserting the company and its first contact or not.
To accomplish this, you will need a way for the user to pass his decision (a menu, radio-button, checkbox), and a way to redirect to a specific page based on a condition. As for passing the decision part, there is no problem, only the choice of the HTML form elements remains. For the conditional redirect action, however, you would have some hand-coding to do.
Developer Toolbox has this need covered too, however, through the “Redirect To Page” trigger. As all the other Developer Toolbox triggers, this one can be turned into a conditional trigger, simply by using the expression builder on the Advanced tab.
To add this functionality, you will have to alter the design of the insert page (e.g. insertcomcon.php), and only then add the application logic that performs the actual task.
This alteration concerns adding a
new form element, so that the user option of whether to add some more contacts
or not can be passed to the trigger. The simplest of elements that can be used
effectively is a checkbox. To change the design, follow the instructions below:
Click in the second cell. Here is where you will insert the checkbox. Add it from the Forms tab of the Insert bar, by clicking on its button. Configure the checkbox, by changing its name to "addmore" and set the "Checked value" field to 1. Also, leave the "Initial State" on the Unchecked setting (see Figure 5).

Figure 5. The newly added checkbox in the Property inspector
Note: For ASP_VBScript users, you should select the Request Variable type, and then in the dialog box select Request.Form from the drop-down menu.
The actual operation will be based on the "Redirect To Page" trigger, which will be set to start on a custom condition: that the "Add more contacts" checkbox is checked.
To add and configure the redirect trigger, follow the instructions below:
For this trigger you will have to set options for both the Basic and Advanced tabs. On the Basic tab, just enter the page to which the user will be redirected. Either enter its name, or use the "Browse…" button to locate the insert page in the contact folder (see Figure 6).

Figure 6. The "Redirect to Page" trigger, Basic tab
Move on to the Advanced tab, where you can define a starting condition for the redirect. You can either write the condition in the text-field, or use the Condition Builder, by pressing the "Build condition" button. Let's use the latter (see Figure 7).

Figure 7. The "Redirect to Page" trigger, Advanced tab
It's time to build the actual condition. Follow the instructions below to construct it:
For the first term you will use the Form Variable defined when you've added the checkbox into the page. Click the blue lightning bolt icon to open the Developer Toolbox Dynamic Data user interface. Here, select the Form Variable option in the "Get values from" drop-down and then pick addmore from the "Variable" select (see Figure 8).

Figure 8. The Developer Toolbox Dynamic Data user interface
For the second operator, you will use an entered value. Since the Checked Value property for the checkbox has been set to 1, this is the value that the condition should use. This way, if the trigger's condition that the checkbox value equals 1 is true, the redirect will take place. Otherwise, the default redirect of the insert operation (to the main index) will execute (see Figure 9).

Figure 9. The Condition Builder settings for the Redirect To Page trigger
The expression will be displayed in the "Redirect To Page" trigger's Advanced tab, in the "Condition" text field.
When you add a company through this insert form, if the "Add more contacts" checkbox is checked, when submitting the page, you will be taken to the contact insert page, where you can continue adding entries (see Figure 10).

Figure 10. The insertcomcon.php page, browser view
In the next topic of the tutorial you will create a page that will automatically send birthday greetings to your contacts.
The next enhancement to your web application is meant to ease the task of checking daily which contact's birthday it is and use your e-mail client to send a greeting. It will all be done in an automatic manner at the click of a button.
You will have to create a new page in your site's root folder, which will contain the elements that send the e-mail. Switch to Files tab and create a new page; give it a suggestive name (e.g. birthday.php). Later on you’ll add a link in the main page, which will point to this one.
Note: If the Files tab is not visible, open it from Window > Files.
Sending the birthday greetings will be done in a semi-automatic manner at first. The page displays a list of all persons that were born on this day, allowing you to decide whether to send the e-mail or not. The automatic part is that you'll only have to click a single button to send the greeting to all people in the list.
To start creating the page, open it in Dreamweaver, and continue with this tutorial: you will create the design first. Later on, you'll add the code that does all of the actions.
When creating the basic design, the approach is the same as for the contact or company insert and update pages:
The list of people born on the day the page is being accessed is in fact a dynamic table, as it should retrieve the names from the contacts table. Before using the Dynamic Table command however, you have to create a recordset containing the names.
To create the recordset, follow the instructions below:
In the SQL text area, enter the following query:
For MySQL:
SELECT *
FROM contact_con
WHERE date_format(birthday_con, '%m%d') = date_format(now(), '%m%d')
For Microsoft Access:
SELECT
*
FROM contact_con
WHERE birthday_con = Date()
Note: Microsoft Access uses the same date format as your operating system to store date values.
For Microsoft SQL Server:SELECT
*
FROM dbo.contact_con
WHERE DAY(dbo.contact_con.birthday_con) =
DATEPART(DAY,GETDATE())
and MONTH(dbo.contact_con.birthday_con) =
DATEPART(MONTH,GETDATE())
Note: a query is a SQL command that will extract information from the tables of a database. Essentially, a query is a request for information from your database.
As you can see, the query above returns only the entries that have the birthday field set on the current day. The SQL query is the last thing done on the new recordset dialog box. Click Test to see if anyone is born on this day, or the OK button to add the recordset into the page (see Figure 11).

Figure 11. The standard Recordset’s Advanced view
After having created the recordset you can create the listing of its content, with the use of a dynamic table. To add a dynamic table, click on its button in the Data tab of the Insert bar. Configure it to display entries from the recordset created earlier, rsContacts, and to display all records. Also, set the table border, cell spacing and padding to 0. Click OK to add the dynamic table into the page (see Figure 12).

Figure 12. The Dynamic Table settings
At this point, a table with all data concerning the contacts has been added in the last page paragraph. Not all of the entries are useful, or meaningful, as only the actual contact name is of interest. Therefore, delete all table columns except the name_con one.
For the remaining column, change the name_con static text into a more understandable one: "Name". Also, set the cell as having the header property, from the Property inspector.
Next comes the switch that will start the mail sending operation: an HTML form button. Place one in a new paragraph below the dynamic table. When asked if a form tag should be added, answer "Yes". To make the button more intuitive, replace the Submit label with: "Send birthday greetings." Leave the button's name as is, "Submit."
The email sending is implemented through the use of one of Developer Toolbox's triggers: the “Send E-mail to Recipients from Recordset” trigger. However, as any trigger, it needs a transaction on page. As there is no need to add, update or delete anything, the only one that will suit this purpose is the custom transaction. The custom transaction allows you to define the fields to use, and the SQL which will use it. Also, you can just use it as a placeholder, with no SQL operation at all.
Add a "Custom Transaction" to the page, by clicking the Plus (+) button of the Server Behaviors tab, and selecting Developer Toolbox > Forms >Advanced > Custom Transaction. Configure it as follows:
Now that a transaction exists on the page, you can also add triggers that register to it, as the Send E-mail trigger, for instance. Therefore, you can finally complete the last action in this tutorial—apply the "Send E-mail to Recipients from Recordset" trigger:
Configure the trigger to send the correct e-mail to the correct addresses:
In the "Content" text area enter the message to pass to the recipient; in this case enter a Happy Birthday greeting from you (see Figure 13).

Figure 13. The "Send E-mail to Recipients From Recordset" interface
This was the last step to create the birthday greetings page. You can now save, upload and test it. If no names appear in the list, it may be due to the fact that no contacts in your table are born on this day. Either try again another day, or enter a contact whose birthday is today.
Note: For PHP users, when using the "Send E-mail to Recipients from Recordset" server behavior to send messages to a large number of recipients, make sure the value of the max_execution_time variable in your php.ini configuration file is sufficiently large to support the execution of the code. Sending many e-mail messages might take longer than the default setting, depending on your server configuration and specifications. If you encounter an error similar to the following: Fatal error: Maximum execution time of 30 seconds exceeded in c:\server\site\includes\common\lib\email\Pear\Net\Socket.php on line 241 please increase the value of the max_execution_time variable in php.ini, or contact your network administrator.
In this page you will use Query Builder to modify the main index.php page so that it will display the number of contacts per each company. To get a count of a company's contacts, you will have to modify the master1company_com recordset, which was generated by the "Nested Repeat Region" server behavior.
Follow the instructions below:
Once the query code looks like the one below, click the "QuB…" button on the right (see Figure 14).

Figure 14. The new SQL for the master1company_com recordset
After clicking OK, the Query Builder (QuB) interface will open in a separate browser window. The left side contains a Tables panel with a list of the tables in the current database. Select both tables as shown below (see Figure 15).

Figure 15. Select both tables in the Query Builder (QuB) browser window
Now both tables will be in the Database Diagram. Create a table relation by dragging the idcom_com foreign key (from the contact_con table) and dropping it on the id_com field (on the company_com table) as shown below (see Figure 16).

Figure 16. Linking the contacts and companies tables in Query Builder (QuB)
A blue line will now appear between the two tables (see Figure 17).

Figure 17. The relation between the company_com and contact_con tables
With the necessary fields now listed in the Columns section the various options can be used to further organize the data. On the contact_con.idcom_con field, we'll use the count option in the "Grouping" drop-down menu (see Figure 18).

Figure 18. The contents of the Columns section of the Query Builder page
This last step will give you a count of all the contacts associated with a company. You can verify the result in the Results preview panel (see Figure 19).

Figure 19. The actual results of the current SQL query
After selecting the query name, the SQL text area will contain the code built from the Query Builder interface (see Figure 20).

Figure 20. The SQL query created using Query Builder is now being used in Dreamweaver
Select the text labeled "Actions" in the Nested Repeat Region table (see Figure 21).

Figure 21. Selecting the "Actions" text in Design View
Take the count_idcom_con_1 field (shown in step 17) and drag it over to the Nested Repeat Region table. Drop it in the place of the "Actions" text. Then type the word "contacts" in the same cell. When you're done, the page should look like this (see Figure 22).

Figure 22. The index page listing the number of contacts as well, Design View
Now you can view the final page with the number of contacts in a browser (see Figure 23).

Figure 23. The index page listing the number of contacts as well, browser view
This concludes the Contact Management Application tutorial. You have taken three easy steps to create a full management system for your contacts.
You should take a look at the other Adobe Dreamweaver Developer Toolbox tutorials:
Razvan Cotlarciuc is a member of the Dreamweaver development team. When he is not working on job-related projects, he enjoys learning new technologies, surfing the Internet, and playing tennis.