Building a Registration Page


Once you've created a database table to store user information, you're ready to build a registration page. The registration page contains an HTML form where new users can register a user name and password for logging in to your site. An Insert Record server behavior is added to the registration page to update the table of users in the database. This behavior enables the form data to be used to create a new record in the login database when the user clicks the submit button. An additional server behavior, Check New Username, is added to make sure that the user name is unique before a new record is created in the database. If it's not unique, the server cancels the Insert Record process and opens a new page that alerts the user that the user name is already in use.

In the exercises in this section, we use PHP and the users table of the Login database to define a recordset, add an HTML form for user registration, and add Insert Record and Check New Username server behaviors.

You need to create a connection to the Login database before you can define a recordset using the users table. For more details on using PHP to connect to a MySQL database, see "To connect to a database with PHP/MySQL," in Chapter 4.

To define a recordset for the registration page:

1.

Open a new PHP page in Dreamweaver (File > New > Dynamic page > PHP). Save the page as registration.php.

2.

In the Application panel group, click the Bindings tab to access the Bindings panel.

3.

Click the plus (+) button and choose Recordset (Query) to add a recordset (Figure 13.3).

Figure 13.3. Click the plus button on the Bindings panel and choose Recordset (Query) from the menu.


The Recordset dialog appears.

4.

In the Name field, enter a name for the recordset. Choose a name that will help you to identify the recordset later.

For this exercise we're defining a recordset for a registration page, so we named our recordset register (Figure 13.4).

Figure 13.4. Create a new recordset using the Recordset dialog.


5.

From the Connection drop-down list, select the name for your connection to the Login database. Our connection is named connLogin.

6.

From the Table drop-down list, choose users.

7.

In the Columns section, select the All radio button.

You've chosen to add all four fields from the users table to the recordset.

8.

Click the Test button to preview the recordset.

The Test SQL Statement window appears (Figure 13.5).

Figure 13.5. View the recordset data in the Test SQL Statement window.


9.

Click OK to close the Test SQL

Statement window, and then click OK in the Recordset dialog to close it and save the recordset.

10.

Save the page.

You've created a recordset using all the fields in the users table of the Login database. You'll use this recordset in the remaining exercises in this section.

To create a user-registration form:

1.

Open the registration.php page from the preceding exercise.

2.

From the Insert menu, select Form > Form to add a form to your page (Figure 13.6).

Figure 13.6. Add a form to your page using the Insert menu.


3.

In Design view, select the form.

If the form boundaries aren't visible, choose View > Visual Aids > Invisible Elements.

4.

In the Property inspector, type register in the Form Name box (Figure 13.7).

Figure 13.7. Type a name for the form in the Form Name box in the Property inspector.


Leave the Action and Method fields blank. They'll be filled in automatically when you add the Insert Record server behavior in the following exercise.

5.

From the Insert menu, select Form > Text Field to add a text field to the form.

6.

In Design view, select the text field.

7.

In the Property inspector, type Name in the TextField name box (Figure 13.8). In the Char Width and the Max Chars fields, type 30. In the Type section, select the Single Line radio button.

Figure 13.8. Set properties for the Name text field in the Property inspector.


You've inserted a 30-character text field called Name in the registration form. This field will be used to collect the visitor's name.

8.

Repeat Steps 5 through 7 to add a 50-character text field named userName and an 8-character text field named Password.

9.

From the Insert menu, select Form > Hidden Field to add a hidden field to the form.

The Tag Editor dialog appears.

10.

In the Name field, type Access. In the Value field, type guest (Figure 13.9). Click OK to close the Tag Editor.

Figure 13.9. Type a name and a value for the hidden field in the Tag Editor dialog.


The value of the hidden field is submitted when the form data is submitted. When the value guest is assigned to the Access field, every new user is automatically assigned guest access privileges. Once the site administrator verifies the e-mail address, the access privileges can be changed to member.

11.

From the Insert menu, select Form > Button to add a button to the form.

12.

In Design view, select the button. In the Property inspector, type submit in the Button Name box (Figure 13.10). In the Value field, type Submit. In the Action section, select the Submit Form radio button.

Figure 13.10. Enter a name and value for the submit button in the Property inspector.


13.

Save the page.

You've created a registration form with three fields for users to enter a name, user name, and password. You also added a hidden field to set the initial access level to guest.

Tip

  • You can set properties for form objects in either the Tag Editor or the Property inspector. You can also set them by entering the property values directly in the Code view window.


To add a server behavior to update the users table:

1.

Open the registration.php page from the preceding exercise.

2.

In the Application panel group, click the Server Behaviors tab to access the Server Behaviors panel.

3.

Click the plus (+) button, and choose Insert Record from the Server Behaviors menu (Figure 13.11).

Figure 13.11. Choose Insert Record from the Server Behaviors menu.


The Insert Record dialog appears.

4.

From the Submit Values From dropdown list, select register (Figure 13.12).

Figure 13.12. Choose the form, the connection, and the database table in the Insert Record dialog.


5.

From the Connection drop-down list, select your connection to the Login database; our connection is named connLogin.

6.

From the Insert Table drop-down list, choose users.

7.

In the Columns box, verify that the right information is shown for each column by selecting each column and checking the information in the Value and Submit As fields.

All the columns in the users table are listed in the Columns box. When you select a name from this list, the Value field shows the form object that is associated with that column. For example, the form object called Name is associated with the Name column in the users table. The Submit As field shows the datatype for the columnfor example, text for the Name column.

8.

In the After Inserting, Go To field, type a name for the page to open after the user has clicked the submit button to submit the form data. Our page is named login.php.

You'll build this page in the "Using a Login Page" section, later in this chapter.

9.

Click OK to close the dialog and add the server behavior to the page.

10.

Save the page.

To add a server behavior to check for duplicate names:

1.

Open the registration.php page from the preceding exercise.

2.

In the Application panel group, click the Server Behaviors tab to access the Server Behaviors panel.

3.

Click the plus (+) button and choose User Authentication > Check New Username from the Server Behaviors menu (Figure 13.13).

Figure 13.13. Choose Check New Username from the User Authentication submenu in the Server Behaviors menu.


The Check New Username dialog appears.

4.

From the Username Field drop-down list, select userName (Figure 13.14).

Figure 13.14. Use the Check New Username dialog to select the userName form field and enter a filename for a page to open if that user name is already being used.


userName is the name of the form text field that visitors use to enter a user name.

5.

In the If Already Exists, Go To field, enter the name of the page to open if the user name is already being used by another registered user. Our page is named chooseAgain.php.

6.

Click OK to close the dialog and add the server behavior to the page.

7.

Save the page.

8.

Create a new PHP page (File > New > Dynamic page > PHP). Save it as chooseAgain.php.

9.

Type a message on the page to let the visitor know that the user name he or she entered is already in use. Include a link to the registration page (registration.php) (Figure 13.15).

Figure 13.15. A page opens that lets the user know that the user name he or she entered is already in use. A link to the registration page is included on the page.


10.

Save the page.

11.

Preview the registration.php page in a browser (File > Preview in Browser). Enter information in the form fields for one of the four registered users you added when you created the users table, and then click the Submit button. The chooseAgain.php page should appear (Figure 13.15).

You've now added a Check New Username server behavior to verify that a user name is unique before inserting a new record in the users table of the Login database. If the user name is not unique, the Insert Record process is canceled, and the user is notified that the name is already taken.




Macromedia Dreamweaver 8 Advanced for Windows and Macintosh. Visual Quickpro Guide
Macromedia Dreamweaver 8 Advanced for Windows and Macintosh: Visual QuickPro Guide
ISBN: 0321384024
EAN: 2147483647
Year: 2004
Pages: 129
Authors: Lucinda Dykes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net