Dreamweaver UltraDev Cookbook

New User Registration Example

Hiran de Silva
June 2000

This short tutorial is for Dreamweaver users learning Dreamweaver UltraDev Version 1.0 and ASP

I am assuming that

You are familiar with Dreamweaver
You are now a proud owner of Dreamweaver UltraDev trying to figure it out
You are comfortable with MS Access
You are new to VBScript but have done some simple programming before

 

How does the New User Registration Example work?

When a new user fills in the registration form the ASP code on the page checks whether a record with the same UserID exists in the members database. If a user with the same name exists he/she/it is invited to try again, otherwise the new record is added to the database. Try the demo.

Steps

1 Design your User Registration form - as in Dreamweaver
2 Create a Recordset - UltraDev will do this for you
3 Apply a Server Behavior - UltraDev will do this for you
4 Swap the code generated by UltraDev (!)
5 Add a little ASP code

You'll see how easy it is to get UltraDev to do most of the work. All we humans have to do is rearrange it slightly and add a little bit of code to tie it all together.

1 Design your New User Registration form

Ok. You already know how to create a form.

However, we will save ourselves a lot of bother by naming the text boxes the same names as the field names in the database table (in tblLogin in the members.mdb database). See Step 3 below.
Set the Method to POST and don't worry about the Action property. Step 3 takes care of that in the Go To URL box.

We will need 2 additional pages - one to tell them that the registration is successful, and the other to tell them to try another UserID. I have called these pages newregisterconfirm.asp and newregistertryagain.asp. In this tutorial these 2 pages can be normal HTML pages if you like - nothing wizzy here.

2 Create a Recordset

Why? We want to check whether the UserID already exists. We do this by getting the database to return a record, if any, that has UserID identical to what the new user has entered as his preferred UserID.

If you followed the Login tutorial earlier (you didn't?!) you are already familiar with creating recordsets. Except that here we are interested only in a matching UserID. Call this recordset rsCheckDuplicates.
So, in the Data Binding inspector go click the + and select Recordset (Query).
The dialog should be completed like this.

Now go to the HTML Source window and see the ASP code that UltraDev has generated for us. You'll soon see why we need to identify this block.

3 Apply a Server Behavior

In the Server Behaviors tab select Insert Record.
Select your Connection. I have called this connMembers.
Table to Update will be tblLogin, same as before.

If you followed my tip about naming your form fields, in the Get Values From section all the relevant boxes will be filled in by default. See how much hassle you have saved yourself when filling in the Form Elements box?
In the When Done Inserting section Go To URL should be your NewRegisterConfirm.asp page.

Click Ok.

Again, take a quick look at the block of code UltraDev created for us. But before you do have a glass of water handy because this is pretty mean looking code! Normally you wouldn't have to tweek anything here, but you need to identify where this block begins and ends so we can rock and roll smoothly in the next step.

4 Swap the code (!)

Why swap code?

Whether we do step 2 before 3 or the other way around UltraDev insists on placing the Recordset code after the Insert Record code.

But that's no good for our purposes here - we want the page to check if the UserID exists (ie, run the recordset bit) before it decides whether to insert the new record, right?

Now, in the HTML Source window, very carefully cut the recordset block and paste it above the insert block. Make sure you leave the <%@LANGUAGE="VBSCRIPT"%> at the top of the page.

Clever, isn't it?

5 Add a little ASP code

Type this bit of code immediately before the insert block.

And this code immediately after it.

Here's how it should look.

The logic here is very similar to what we used in the Login example. If the recordset returned a record then the UserID already exists in the table tblLogin. The user is then redirected to the page NewRegisterTryAgain.asp. One the other hand, if the recordset returned is at the EndOfFile (EOF) it means that the UserID does not exist in the table. So this must be a new UserID and so we want the Else part of the If ... Then to work. The code within the Else part inserts a new record.

That's all folks!

We haven't seen how to validate the form entries yet. Let's cover how to tackle this later - but if you like something that works now, there's a Dreamweaver extention for you at Yaromat's site.

Next time we'll look at:

How to get the New User Registration page to send a Confirmation Email automatically.
How to authenticate email address via an Authentication Link Back.

Troubleshooting Tips
Write a Review of this Tutorial
Read Reviews

Please send comments to Hiran de Silva.