Perhaps the most time-consuming and error-prone aspect of sending email to a group of people is entering the email addresses. The Search Users page of the Mail Merge application provides an easy way to collect and apply the required addresses. Typically in a workgroup, email is either sent to individuals whose email address is known or to a specific set of people tasked with a particular job, such as managers, whose email address might not be known by the sender. The Search Users page is structured to accommodate either scenario. You'll find that this search page is different from others in this book in several ways. First, there are two different search forms on the page: one that looks for individuals and another that concentrates on groups. Both forms have their own form buttons, but each button activates the same code and that's the second major difference. Instead of the form just passing parameters to another page to handle the actual search, the Search Users page first places all the selected search criteria into session variables, which can be referenced throughout the application. This process has the added benefit of ensuring that the currently selected criteria will be present if the user returns to this page either through the Back button or a link. After the variables are stored, the user is redirected to the results page. A simple recordset is used to gather the available groups for a drop-down list in one of the search forms. By attaching the list dynamically, new groups can be included as a search item as they become available, without additional coding. Step 1: Implement Search Users DesignThe obvious difference between this and most other Web application pages is that this page includes more than one form. When designing the layout for this page, make sure to completely separate the two forms by putting them in two separate table rows or divs. You'll also want to make sure that each form is named differently; the forms contained in our snippet are called SearchUsers and SearchAccessGroups, reflecting their functionality. However, for our purposes, it's important that the Submit buttons in both forms use the same name, such as Search; the identically named buttons will ensure that the same custom code is called regardless of which form is submitted.
Step 2: Add Database ComponentsAs mentioned in the introduction to this application page, only one recordset is required. To allow the user to select any of the groups set up for access to the workgroup, we'll create a recordset that includes the names of all the groups. If access groups are not are used in your workplace, you can substitute any other group that is suitable. Note If you create this page by hand, be careful if you copy and paste the first Search button to create the second. Dreamweaver automatically adds a number to the name of the second button to distinguish the two. If this happens to you, be sure to rename the second button the same as the first. Note For more details on access groups, see the User Log In application in Recipe 1.
Step 3: Data Binding ProcessWe'll put our recordset right to use and apply it to the list element found in the Access Groups form. In addition to making the list dynamic, we'll need to add a hidden form element next to the list. The hidden form element is required for our custom code (added later in this recipe) to work properly. Let's start by attaching the proper recordset values to the list element.
Now we'll add the hidden form element with the needed name and value.
We put this hidden form element in the Access Groups form so that our custom SQL statement (inserted later in the Mailing List page) will not find a match in the Email field when the AccessGroups list is used. Step 4: Set Form ActionIn many other search pages including those used elsewhere in this book the form action is set to another dynamic page, which handles the actual search depending on values passed from the initial search page. In this recipe, we're going to demonstrate an alternative approach that sets the action to the calling page this search page and uses custom code to redirect the user to the results page after certain session variables have been set. This "same page" method is effective when the search criteria are needed in various other pages in the application. Because we have two search forms, we'll need to set the actions for both of them, starting with the Search Users form:
Now let's repeat the same procedure for the second form:
Step 5: Insert Custom CodeWe're now ready for the final step in this recipe: inserting the custom code. As noted throughout the recipe, the custom code serves two purposes: to set the search criteria to easily accessible session variables and to send the user to the results page. The custom code is inserted at the top of the page. What keeps it from being called immediately? An if-then statement surrounds the code and ensures that it will be executed only when the Request string is equal to Search, which happens to be the name assigned to the Submit buttons in both forms. By naming the buttons the same (as we did at the start of this recipe), we're ensured of running the custom code when either is pressed.
Your page is now ready for initial testing, but until we complete the next page in the application Mailing List you won't be able to see the results of your search. |