Accessibility

Dreamweaver Article

 

Building a subscribe/unsubscribe app in PHP with Dreamweaver CS3


Table of Contents

Signing up for a subscription

The subscription page should be simple and clear. You want to keep any barriers to signing up as low as possible. The following example page has a single form field to gather the e-mail address and a submit button, clearly labeled Subscribe Me! (see Figure 3).

A clear and simple subscription page

Figure 3. A clear and simple subscription page

The text field is named txtEmail by selecting the page element and entering the name in the provided field on the far left of the Property inspector. The form action property is left blank, so the Dreamweaver Insert Record behavior can add its own code. One other field is inserted into the form: a hidden field labeled SubSubscription with a value of 1. This hidden field will be used by the Insert Record server behavior to populate the identically named field in the database and indicate a subscription has been authorized. Remember that for this Boolean database column, 1 means subscribed.

Note: It's always a good idea to validate your form fields. You can use the Dreamweaver Validate Form behavior or insert the Spry Validation Text Field if you prefer.

To apply the Insert Record server behavior, follow these steps:

  1. From the Server Behaviors panel, choose Add (+) and, from the list, select Insert Record.
  2. When the Insert Record dialog box opens, make sure that the current form is selected in the Submit values from list. In my example, I kept the default name, form1.
  3. Choose your connection from the Connection list. My connection is connSubscribe.
  4. Select the table you want to insert your new record into from the Insert table list. My table is called subs.
  5. In the Columns area, you only need to specify a form element for one of the database columns (see Figure 4):

    • Leave the first entry—'ID' Is an Unused Primary Key—at its default settings.
    • Select the SubEmail entry and from the Value list, choose FORM.txtEmail and verify that Submit as is set to Text.
    • Keep the third entry (SubSubscribed) at its default settings. Because you named the hidden form element the same as the database column, Dreamweaver automatically made the assignment for you.

    Specifying the column elements

    Figure 4. Specifying the column elements

  6. In the After inserting, go to field, enter confirm_subscribe.php.
  7. Click OK and save your page.