762
3. To select the form, click the form’s boundaries or click the <form> tag
in the bottom-left corner of the Document window.
Selecting the form lets you modify that form’s properties in the
Properties inspector.
4. In the Properties inspector, enter a name for the form in the Form ID
field.
You probably want to use something descriptive, such as insert_form.
Don’t set the Action or Method fields because the Insert Record server
behavior sets these fields for you.
5. Add a text field by choosing Insert➪Form➪Text Field.
You can also add other form objects, depending on the type of data that
you want to insert into the database table. See Book II, Chapter 7 for
more on the different form objects.
6. In the Input Tag Accessibility Attributes dialog box, enter a descrip-
tive ID and a text label.
7. (Optional) Tweak the Style and Position settings as desired.
8. Click OK.
9. For each column that you allow the user to add data to, repeat
Steps 5–8.
For the employee table example, we added each field but arranged the
fields in a slightly different order on the form.
10. Press Enter (Windows) or Return (Mac) to insert a new line so that the
element appears on a separate line.
You can also use a table element to align your fields (see Book II,
Chapter 7 for more information).
11. Insert a submit button on the page by choosing Insert➪Form➪Button.
If the Input Tag Accessibility Attributes dialog box appears, click Cancel.
12. With the button selected, change the Value text in the Properties
inspector to Insert.
The example form looks like Figure 3-4.
Adding the Insert Record server behavior
You have to add the Insert Record server behavior to your page so that it
can process the data in the form submission.
You must have an active database connection before you can add the Insert
Record server behavior. See Book VII for details on setting up a database
connection.
Building a Record Insert Page Block by Block
55_610770-bk09ch03.indd 76255_610770-bk09ch03.indd 762 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 3
Building Record Insert
Pages and Restricting
Site Access
763
Figure 3-4:
The
completed
form.
To add the Insert Record server behavior, follow these steps:
1. In the Server Behaviors panel, click the plus (+) icon and select Insert
Record in the drop-down list that appears.
The Insert Record dialog box appears.
2. Select your form in the Submit Values From drop-down list.
3. In the Connection drop-down list, select a database connection that
contains the table that you want to insert data into.
4. In the Insert Table drop-down list, select the database table that you
want to insert a record into.
The database columns appear in the Columns section, as shown in
Figure 3-5.
Depending on your dynamic page type, the Insert Record dialog box may
appear slightly different. For example, ColdFusion calls the Connection
field a data source and includes options for Username and Password
database fields. However, these differences don’t change the following
steps.
Building a Record Insert Page Block by Block
55_610770-bk09ch03.indd 76355_610770-bk09ch03.indd 763 5/6/10 1:21 PM5/6/10 1:21 PM
764
5. (Optional) To modify the associated database column or data type of a
field, select the column from the column list and then modify the fol-
lowing fields in the dialog box:
• Value: Select the form field. Each form field appears in the list.
• Submit As: Select the data type. The data type that you select here
should mirror the database column data type. The types are text,
integer, date, and check box formats.
Dreamweaver automatically links the form fields that have the same
name as the database field.
Figure 3-5:
Use the
Insert
Record
dialog box
to choose
which fields
supply
values
from the
form to the
database
table.
6. For each field that you need to change, repeat Step 5.
7. In the After Inserting, Go To text field, enter the page that you want to
go to after inserting the record. Or click the Browse button and select
a file.
For the ASP.NET dynamic page type, you have a choice also for the On
Failure, Go To text box and a Display Debugging Information check box.
You fill in these fields to display debugging information or redirect a
user if the record insert fails. The rest of the dialog box works the same
as the other document types.
8. Click OK.
Dreamweaver adds the server behavior to the page. You now have a
complete page. Users can fill out the fields on the page and then click
the submit button.
You can make any visual changes to the form by using Dreamweaver’s tools
for changing fonts, colors, and placement.
Building a Record Insert Page Block by Block
55_610770-bk09ch03.indd 76455_610770-bk09ch03.indd 764 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 3
Building Record Insert
Pages and Restricting
Site Access
765
Testing Your Record Insert Page
After you create a record insert page (see “Building a Record Insert Page
Block by Block” section, earlier in this chapter), you probably want to test
your page. Follow these steps to do so:
1. Open the Record Insert page.
2. Choose File➪Preview in Browser➪Name of Browser.
3. When Dreamweaver asks if it’s okay to copy files to your testing site,
click OK.
Your browser launches and displays the Record Insert page.
4. Enter some sample data into the fields.
Figure 3-6 shows some test data for the employee table.
Figure 3-6:
Entering
data into
the Record
Insert page.
5. Click the Insert Record button.
When the data is added successfully, the browser opens the success
page.
Be sure that both your Record Insert page and success page transfer to the
testing server. If not, when you click the button on the insert page, you get a
Page Not Found error message.
The success page in our example simply contains the text Inserted
Successfully.
Testing Your Record Insert Page
55_610770-bk09ch03.indd 76555_610770-bk09ch03.indd 765 5/6/10 1:21 PM5/6/10 1:21 PM
766
If you want to double-check that the insert worked, follow these steps:
1. Open the Databases panel.
2. Expand the database you are working with by clicking the arrow.
3. Expand the Tables item to display the table you are working with.
4. Right-click the table on the page.
5. Choose View Data from the pop-up menu.
The View Data dialog box appears, as shown in Figure 3-7.
Figure 3-7:
The View
Data dialog
box shows
the newly
inserted
data.
In the dialog box, you can see that the data was inserted correctly into the
table.
Building a Login Page
A login page enables registered users to log in to a Web site. Dreamweaver
CS5 comes with a sample design of a login page. You can also design your
own.
The following sections show you how to complete the steps to building your
own login page.
Building a Login Page
55_610770-bk09ch03.indd 76655_610770-bk09ch03.indd 766 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 3
Building Record Insert
Pages and Restricting
Site Access
767
Setting up a database table
If you set up the employee entry page, as described earlier in the chapter,
you’ve already created this table.
Creating the HTML form on the login page
If you want to design your own login page, first you need to create a new
page and add an HTML form with a username text box, a password text box,
and a submit button. This process is similar to the process of adding a form
to a data entry page.
Adding a Log In User server behavior to the page
After adding a form to your login page (as described in the preceding sec-
tion), the final step is to add the Log In User server behavior, which checks
to make sure that the user entered a valid username and password.
To add the Log In User server behavior to your login page, open the page
and follow these steps:
1. In the Server Behaviors panel, click the plus (+) icon and choose User
Authentication➪Log In User.
The Log In User dialog box appears.
2. In the Get Input From Form field, select the form used on the login
page.
3. In the Username Field and Password Field text boxes, select the appro-
priate form fields.
4. If you are using ColdFusion, enter your username and password.
5. In the Table drop-down list, select the database table that you will
check the form fields against.
We selected the users table.
6. In the Username Column and Password Column drop-down lists, spec-
ify the table columns for the username and password.
For example, the users table that we selected in Step 5 contains user-
name and password columns, so we selected those columns.
7. In the If Login Success, Go To text box, enter the name of the page to
open if the user logs in successfully.
Or you can click the Browse button and select the page.
Building a Login Page
55_610770-bk09ch03.indd 76755_610770-bk09ch03.indd 767 5/6/10 1:21 PM5/6/10 1:21 PM
768
8. In the If Login Fails, Go To text box, enter the name of the page to
open if the user is unable to log in.
Or you can click the Browse button and select the page.
9. Indicate whether you want to grant access to this page based on just the
username and password, or based on the authorization level as well.
Having multiple authentication levels provides more flexibility for
segregated access to information but also comes at the cost of added
complexity (and time administering your user’s levels and categorizing
information). Most people can get by without setting up multiple access
levels to their sites.
10. Click OK.
Your login page is now complete.
Restricting Access to Your Pages
If you have a Web page that you don’t want all users to be able to view, you
can restrict access to it. To do this, you add the Restrict Access to Page
server behavior to the page so that only authorized users can view the page.
If an unauthorized user attempts to open the restricted page, the user is
redirected to another page.
Here are a few examples of when restricted access may be useful:
✦ You have a page that you want to be viewed only by users with
Administrator privileges.
✦ You want to make sure that users log in before they can view a specific
page.
✦ You want to review newly registered users before allowing them to
access members-only pages.
To restrict access to a page, you need to do the following tasks:
✦ Add the Restrict Access to a Page server behavior to that page.
✦ If you want to use authorization levels to further restrict page access,
you need to add a column to your user database table to maintain infor-
mation about which access privileges each user is entitled to.
Restricting Access to Your Pages
55_610770-bk09ch03.indd 76855_610770-bk09ch03.indd 768 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 3
Building Record Insert
Pages and Restricting
Site Access
769
Follow these steps to restrict access to a page:
1. Open the page you want to restrict access to.
2. In the Server Behaviors panel, click the plus (+) icon and choose User
Authentication➪Restrict Access to Page.
The Restrict Access to Page dialog box appears.
3. In the Restrict Based On area, select one of the following options:
✦ Username and Password: Select this option if you want only users
with a valid username and password to access the restricted page.
✦ Username, Password, and Access Level: Select this option if you
want only users with specific access privileges to be able to view the
page. Specify one or more authorization levels for the page — for
example, Administrator.
4. In the If Access Denied, Go To text box, enter the name of the page to
open if an unauthorized user attempts to open the restricted page.
5. Click OK.
Dreamweaver adds a server behavior to the page ensuring that only autho-
rized users can access the page.
Restricting Access to Your Pages
55_610770-bk09ch03.indd 76955_610770-bk09ch03.indd 769 5/6/10 1:21 PM5/6/10 1:21 PM
770
Book IX: Developing Applications Rapidly
55_610770-bk09ch03.indd 77055_610770-bk09ch03.indd 770 5/6/10 1:21 PM5/6/10 1:21 PM
Chapter 4: Developing Record
Update and Delete Pages
In This Chapter
✓ Creating record update pages
✓ Trying out your record update page
✓ Deleting records by using delete pages
✓ Putting your delete page to the test
I
n previous chapters in this minibook, we’ve shown you how to browse,
search, and insert data. But before you go away thinking that you’ve dis-
covered everything you need to know about Web apps, we need to tell you —
in the words of a late-night television infomercial — but wait, there’s more!
The record update and delete operations are the last two database func-
tions commonly used in dynamic database sites. For example, suppose that
employees at your company can view their employee data online. Over
time, they may want to change their employment details. Or perhaps an
H.R. administrator may need the ability to delete an employee record. In
any case, you need to give users the ability to update and delete database
records from a Web page, which is what this chapter is all about.
Building an Update Page
Before users can update a record, they need to be able to search for the
record that they want to update. Therefore, you need to create a search
page and a results page. (See Book IX, Chapter 2 for full details on how to
create and work with search and results pages.) Additionally, you need to
create an update page so that users can enter the data for updating the
record. Here’s a closer look at the three pages that you need to create:
✦ Search page: This page allows users to search for a record that they
want to update. For example, in the case of an employee record, the
search page simply searches the employee that’s logged in because
employees can’t modify other employee information.
✦ Results page: This page displays the record in a form. The form defaults
to the values currently in the database (before the update) and has an
update button.
56_610770-bk09ch04.indd 77156_610770-bk09ch04.indd 771 5/6/10 1:21 PM5/6/10 1:21 PM
772
✦ Update page: This page performs the update and tells the user when an
update is successful.
Here’s how the update process works:
1. The user enters search criteria in the form on the search page and then
clicks the Submit button.
2. The browser displays the results of the search on the results page.
3. The user selects a record to update on the results page and clicks the
Submit button.
4. The browser displays the update page.
The first step in the update process is to create a search and results page
set. If you haven’t already created these pages, check out Book IX, Chapter
2 for details. Then read the following sections for details on building the
update page.
Creating link to the update page
After you create the search and results pages, you need to create a link on
the results page to open the update page and display the selected record in
an HTML form.
However, before you begin, quickly create a blank dynamic page of the
desired type and save it as update.php (the three-letter file extension varies
based on the app server you are working with). This is a blank placeholder
page that will eventually be used to update a record from the results page.
After you have created a blank dynamic page, open the results page that
you created based on the instructions back in Book IX, Chapter 2 and follow
these steps:
1. Select the placeholder for the dynamic content for which you want to
create a link.
For example, we selected the last_name field to use as the link field, as
shown in Figure 4-1. The field placeholder appears as {employee_search.
last_name}.
2. In the Properties inspector, click the Browse for Folder icon to the
right of the Link field.
3. In the Select File dialog box, select the update page that you just cre-
ated.
For example, we selected update.php as the update page. For other
language types, use the appropriate file extension (such as .asp) rather
than .php.
Building an Update Page
56_610770-bk09ch04.indd 77256_610770-bk09ch04.indd 772 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
773
Figure 4-1:
The
Document
window for
the results
page.
4. Click the Parameters button.
The Parameters dialog box appears.
5. Enter the key field from your database record in the Name column.
The key field is a field that always has a unique value. For example,
we entered empid because this field contains a unique ID for each
employee.
6. Click the Value column to the right of Name.
The Value edit box is highlighted.
7. Click the Bind to Dynamic Source (lightning bolt) icon to the right of
the highlighted box.
The Dynamic Data dialog box appears, as shown in Figure 4-2.
8. Select the key field from the recordset, and then click OK.
After you click OK, the Values field in the Parameters dialog box is
updated to contain the URL parameter.
9. Click OK to close the Parameters dialog box.
The Select File dialog box appears with an updated value in the URL
field. The value in this field varies depending on your dynamic page
type. Figure 4-3 shows the results for a PHP page.
Building an Update Page
56_610770-bk09ch04.indd 77356_610770-bk09ch04.indd 773 5/6/10 1:21 PM5/6/10 1:21 PM
774
Figure 4-2:
The
Dynamic
Data dialog
box.
Figure 4-3:
The updated
URL field in
the Select
File dialog
box.
10. Click Choose to close the Select File dialog box.
The Document window shows the new link.
11. Save the results page.
The results page is now complete.
Putting the update page together
The update page must read the URL parameter from the results page and
store it in a recordset. The recordset provides the default values for the
form that enables users to change values. The following sections show how
to create the recordset and the form.
Building an Update Page
56_610770-bk09ch04.indd 77456_610770-bk09ch04.indd 774 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
775
Creating the recordset to store the URL parameter
To create the recordset, follow these steps:
1. Open the results page you created in the preceding section.
You must have an active database connection to create the recordset.
See Book VII for details on creating a database connection.
2. In the Bindings panel, click the plus (+) icon and then select Recordset
(Query) from the menu that appears.
The Recordset dialog box appears.
3. Enter the name of the recordset in the Name field.
Use a name that describes the recordset data. For example, we entered
employee_update to indicate that the recordset relates to an update.
4. Select a database connection in the Connection drop-down list.
Depending on your dynamic page type, the Recordset dialog box may
appear slightly different. For example, ColdFusion calls the Connection field
a data source and includes optional Username and Password fields for the
database. However, these differences don’t change the following steps.
5. In the Table drop-down list, select the database table that you want to
update.
After you select a table, the Columns list displays the columns in that
table.
6. (Optional) If you want to include only some of the columns from the
table for updating, click the Selected option.
7. In the Columns list, select the columns that you want to update.
To select multiple columns, Ctrl+click (Windows) or Ô+click (Mac).
8. Configure the Filter area so that the database column is compared
against the URL parameter from the results page:
• In the first list, select the key column. For example, we selected
empid, which is the key column for the employee table.
• In the second list, select the equals sign (=). This selection limits the
result set to only the record that you want to update. You can update
only one record at a time.
• In the third list, select URL Parameter.
• In the fourth list, enter the name of the URL parameter defined in the
results page. For example, we entered empid, the same name as the
database key column name.
If your form’s field has a different name in the Properties inspector,
use that name as the parameter name.
Building an Update Page
56_610770-bk09ch04.indd 77556_610770-bk09ch04.indd 775 5/6/10 1:21 PM5/6/10 1:21 PM
776
The new recordset retrieves the information needed to update the
records that the user has selected to update. When the update page is
requested, it uses the record ID parameter sent to the page to filter the
recordset. The Recordset dialog box for the example looks like Figure 4-4.
9. Click OK.
The recordset is added to the Bindings panel list. Now when the user
selects a record on the results page, the update page builds a recordset
containing only the selected record.
Figure 4-4:
The
Recordset
dialog box
configured
to select
only the
record to
update
based
on the
specified
URL
parameter.
Adding a form to the update page
After creating the recordset for the update page (which you can read about
in the preceding section), you need to create the form that enables the user
to modify the record data. Dreamweaver can do the work for you with the
Record Update Form Wizard. This wizard automatically creates the form in
the Document window and adds the appropriate server behaviors to allow
updates.
If you’ve used the Insert Record Form Wizard, you’ll find this wizard similar.
Follow these steps to add an HTML form to your update page:
1. Choose Insert➪Data Objects➪Update Record➪Record Update Form
Wizard.
The Update Record Form dialog box appears.
Only one application object can exist on the same page. You can’t have
an update application object and a delete application object on the same
page.
Building an Update Page
56_610770-bk09ch04.indd 77656_610770-bk09ch04.indd 776 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
777
2. Select the database connection in the Connection drop-down list.
3. Select the database table that you want to update in the Table to
Update drop-down list.
4. From the Select Record From drop-down list, select the recordset that
you created, as described in the preceding section.
This list should default to the recordset that you created in the preced-
ing section.
5. In the Unique Key Column drop-down list, select a key column to iden-
tify the record in the database table.
For example, we selected empid. Leave the Numeric check box selected
if the key fields are numeric.
6. In the After Updating, Go To text box, enter the page that you want
to open after the record is updated. Alternatively, click the Browse
button to select a file.
For example, we selected a page called success.php, which simply dis-
plays a success message. You can create the page before or after enter-
ing the filename for it.
7. To remove unwanted columns from the update page, select the col-
umns in the Form Fields section and click the minus (–) icon.
By default, Dreamweaver includes all the columns of the table in the
form on the update page. The Form Fields section lists the columns in
which the user can enter data before submitting the update request. For
our example, we removed the empid file because it’s an autogenerated
key field. Removing this field eliminates the risk of the user changing the
key value to a duplicate value.
8. (Optional) If you want to make changes to how a field appears on
the update page, select the field from the list and fill in the following
fields in the dialog box:
• Label: Enter a descriptive label. This label appears on the form next
to the field. By default, Dreamweaver uses the column name as the
label. So, for example, rather than use the default label of first_name,
you could change it to First Name.
• Display As: Select a form type. The Display As list includes all the
basic form types, including check boxes, radio buttons, and menus. If
you select one of the types that needs additional configuration, such
as radio groups, a configuration dialog box appears.
• Submit As: Select the data format. The data format is the type of
data that the database column is expecting. The default matches the
current data type in the database. Your choices are Text, Numeric,
Double, Date, Checkbox Y/N, Checkbox 1/0, and Checkbox –1,0.
Building an Update Page
56_610770-bk09ch04.indd 77756_610770-bk09ch04.indd 777 5/6/10 1:21 PM5/6/10 1:21 PM
778
• Default Value: Specify a default value. The value that you enter in
the Default Value field is the initial value that appears in the form
for the particular field. If you don’t enter a value here, Dreamweaver
uses the current value from the database for the initial value.
You can change the dynamic data source for the default value by
clicking the Bind to Dynamic Source (lightning bolt) icon and select-
ing a binding. The value defaults to the value from the recordset. If
the data type is a menu, radio group, or check box, another dialog
box appears to configure the choices available to the user. For
example, a check box has a setting to determine whether it should be
automatically checked when the update page appears.
9. (Optional) Repeat Step 8 for each field that you want to modify in the
Form Field list.
The dialog box for the example looks like Figure 4-5.
Figure 4-5:
The Record
Update
Form dialog
box after
configuring
an update.
10. (Optional) If you want to change the order in which the fields appear
in the form, select a field and click the up arrow or down arrow.
Table fields should be grouped with similar fields (for example, address
fields should all be placed together).
11. Click OK to close the Record Update Form dialog box.
The new form appears as a basic table on your update page. Figure 4-6
shows the form created for the example. You can modify the appear-
ance of form objects as you can any other object in Dreamweaver, but
remember to not move them outside the form’s boundaries. (See Book
II, Chapter 7 for more on form objects.)
Building an Update Page
56_610770-bk09ch04.indd 77856_610770-bk09ch04.indd 778 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
779
Figure 4-6:
The
Document
window
now
contains
the update
form.
Testing Your Update Page
You can test your results page by previewing it in a browser. Before doing
so, make sure the latest versions of your search, results, and update pages
are on your server. Then follow these steps:
1. Open the search page in Dreamweaver.
2. Choose File➪Preview in Browser➪Name of Browser.
3. Enter search criteria in the box and click the Search button.
The results page is displayed with the matching records (see Figure 4-7).
4. Select a record to update by clicking the link for that record.
In our example, the last name for each employee is linked to the update
page. The browser displays the update page for that record. We clicked
the Jason Bourne link on the results page, and the browser displayed
the update page with the record for Jason, as shown in Figure 4-8.
Be sure that both your search results page and update page transfer to
the testing server. If both don’t transfer, you get a Page Not Found error
message when you click a link in the update results page.
5. Enter a new value for one or more of the fields on the update page.
For example, we added address info, as shown in Figure 4-9.
Testing Your Update Page
56_610770-bk09ch04.indd 77956_610770-bk09ch04.indd 779 5/6/10 1:21 PM5/6/10 1:21 PM
780
Figure 4-7:
The browser
displays
the rows
that can be
updated.
Figure 4-8:
The update
page is
displayed.
6. Click Update Record.
Your changes are saved to the database, and the success page appears
in the browser (see Figure 4-10).
What’s more, to verify the update was saved, you can navigate back to the
update results page to verify the new value.
Testing Your Update Page
56_610770-bk09ch04.indd 78056_610770-bk09ch04.indd 780 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
781
Figure 4-9:
More details
are provided
for Mr.
Bourne.
Figure 4-10:
Success!
Building Pages to Delete a Record
The typical process for deleting records from a database consists of a few
steps. First, users select which record to delete. After they select a record, a
confirmation page appears, asking them to confirm the delete request to pre-
vent deleting a record accidentally. Finally, a page appears indicating that
the record was successfully deleted from the database.
Building Pages to Delete a Record
56_610770-bk09ch04.indd 78156_610770-bk09ch04.indd 781 5/6/10 1:21 PM5/6/10 1:21 PM
782
For users to be able to delete a record, they first need to be able to find that
record in the database. Therefore, you need to create a search page and a
results page so that users can search for the record. See Book IX, Chapter 2
for details.
The following sections detail how to build the pages that allow a user to
delete a record from the database.
Creating delete links to open the confirmation page
After you create a search page and results page, you need to create a Delete
link for each record in the results table that users can click to open a confir-
mation page, which is a page that asks them to confirm the deletion.
However, before you begin, quickly create a blank dynamic page of the
desired type and save it as confirm.php (the extension varies based on the
app server you are working with). You’ll add content to this file in a moment,
but for now, you just need to link to it.
To create the links to the confirmation page, open the results page and
follow these steps:
1. Select the last column in the results repeated region.
2. Choose Insert➪Table Objects➪Table➪Insert Column to the Right.
An empty column appears at the end of the table. The empty column is
skinny.
3. Select the new column’s lower cell, which is part of the repeated
region.
4. Type Delete.
5. Select the text you just entered to apply a link to the text.
6. In the Properties inspector, enter the name of the confirmation page
in the Link field.
Defining the URL parameter to
pass to the confirmation page
After you create a delete link that displays the confirmation page (see the
preceding section), you want to modify that link so that it passes the identity
of the record that the user wants to delete. To define the URL parameter that
identifies which record to delete, follow these steps:
Building Pages to Delete a Record
56_610770-bk09ch04.indd 78256_610770-bk09ch04.indd 782 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
783
1. Follow Steps 1–6 in the “Creating delete links to open the confirma-
tion page” section, earlier in this chapter.
The deletion process follows a parallel pattern to the record update.
2. Click the plus (+) icon to add another parameter.
An empty row appears in the list.
3. Enter the name of a column that describes which record is about to be
deleted on the confirmation page.
For the employee table example, we are using the last name field. In a
real-world situation, you would probably want to add more fields to
confirm the deletion. But for this purpose, the last name field works fine.
Figure 4-11 shows the two parameters for the employee table.
Figure 4-11:
The
Parameters
dialog box
with the key
field and
descriptive
field.
4. Click OK to close the Parameters dialog box.
The Select File dialog box appears with an updated value in the URL
field. The value in this field varies depending on your dynamic page
type.
5. Click OK to close the Select File dialog box.
The Document window shows the new link.
6. Save the results page.
The results page is complete. The delete link now appears on the page,
as shown in Figure 4-12.
Building Pages to Delete a Record
56_610770-bk09ch04.indd 78356_610770-bk09ch04.indd 783 5/6/10 1:21 PM5/6/10 1:21 PM
784
Figure 4-12:
The
Document
window
with the
new Delete
link.
Building the confirmation page
The Confirmation page simply displays enough information to identify the
record that’s about to be deleted. This page consists of a form with a confir-
mation button.
To create a page that confirms the record deletion, you need to send two
parameters to the confirmation page:
✦ The record ID
✦ A field to display the name of that record
This page saves you from having to create another recordset with a filter to
look up information that’s already been retrieved from the database.
Follow these steps to create the confirmation page:
1. Open up your confirmation page.
We opened up confirm.php.
2. In the Bindings panel, click the plus (+) icon and select URL Parameter
from the list that appears.
The URL Variables dialog box appears.
Building Pages to Delete a Record
56_610770-bk09ch04.indd 78456_610770-bk09ch04.indd 784 5/6/10 1:21 PM5/6/10 1:21 PM
Book IX
Chapter 4
Developing Record
Update and Delete
Pages
785
3. In the Name field, enter the name of the database column that is the
key.
For the example, we entered empid because we need to create a binding
for the URL parameter empid.
4. Click OK.
The binding is created.
5. Repeat Steps 3 and 4 for the last name parameter.
For the example, we also created a last_name parameter.
6. Choose Insert➪Form➪Form to add a form.
7. Choose Insert➪Form➪Hidden Field to add a hidden field to store the
record ID.
The user doesn’t need to see the empid parameter, but that ID needs to
be part of the form submission.
8. With the hidden field selected, enter the name of the variable in the
Hidden Field text box in the Properties inspector.
For example, we entered empid_field.
9. Click the Bind to Dynamic Source (lightning bolt) icon next to the
Value field.
The Dynamic Data dialog box appears.
10. Select the type of binding (URL Parameter, for example) in the bind-
ings list.
For the example, we selected the empid URL parameter. You can leave
the other fields set to their defaults.
11. Click OK to close the Dynamic Data dialog box.
In the Properties inspector, Dreamweaver updates the Value field with
dynamic code to place the URL parameter in the hidden form field.
12. Click in the hidden field in the form and type Do you wish to delete
the record for ?
This text tells users they’re about to delete a record.
13. Position your cursor just before the question mark, click the plus (+)
icon in the Server Behaviors panel, and select Dynamic Text from the
menu that appears.
The Dynamic Text dialog box appears, as shown in Figure 4-13.
Building Pages to Delete a Record
56_610770-bk09ch04.indd 78556_610770-bk09ch04.indd 785 5/6/10 1:21 PM5/6/10 1:21 PM
786
Figure 4-13:
The
Dynamic
Text dialog
box.
14. Select the empid URL Parameter in the list, and then click OK.
If you’re using a different column as the key, select that parameter
instead.
15. Choose Insert➪Form➪Button to add a submit button to your form.
The Input Tag Accessibility Attributes dialog box appears.
16. Type delete_btn in the ID field.
17. Click OK to close the dialog box.
18. Select the button element on your page.
19. In the Properties inspector, enter Delete in the Value field.
The button’s text changes to Delete, as shown in Figure 4-14.
20. Save the page.
Use the name that you selected when creating the Delete link (see
“Creating delete links to open the confirmation page,” earlier in this
chapter).
But wait, there’s more! The page isn’t complete yet because it can’t
process the deletion. You need to add logic to delete the record, as
described in the following section.
Building Pages to Delete a Record
56_610770-bk09ch04.indd 78656_610770-bk09ch04.indd 786 5/6/10 1:21 PM5/6/10 1:21 PM