Validating Usernames and Adding New Authentication Records via a Form Submission

Example

Registering for a password protected subscription service.

MGI Tags

  • mgiAuthenticateDB
  • mgiGet
  • mgiIf
  • mgiSendMail
  • mgiSet

Steps

  1. Create a subscription form.
  2. Name the form fields.
  3. Enter a form action and method.
  4. Save the subscription form.
  5. Create a subscription processing page.
  6. Save the subscription processing page.
  7. Open the subscription processing page in a text editor.
  8. Insert an mgiSet tag and an mgiAuthenticateDB tag in Validate mode.
  9. Insert an mgiIf tag, an mgiAuthenticateDB tag in AddRecord mode, and an mgiSendMail tag.
  10. Save the subscription processing page.
  11. FTP the subscription form and processing page to the web server running MGI.
  12. Complete the subscription form.


Step 1: Create a subscription form.

Create a form to collect subscription information including the user's choice of login and password. Enter HTML form fields on a page using a graphic editor or text editor. Enter a label and default size text field for Name, Address, Phone, Email and Username. Enter a label and password field for Password. Finally, enter a submit button named "Register". The following is an example subscription form.
Contact Information
Name  
Address  
Phone  
Email  
   
Please choose a Username and Password. (Both are case-sensitive)
   
Username  
Password  
   

Step 2: Name the form fields.

Name each text field and the password field with a unique name. For example, name the first text field "Name", the second text field "Address", etc. You may use capitalization and spaces in the form field names.

Step 3: Enter a form action and method.

A form action sends subscription information to the subscription processing page for verification and processing. Enter the name of the subscription processing page (process.html) in the action parameter of the <FORM> tag. Enter "post" in the method parameter of the <FORM> tag. For example,
<FORM ACTION="process.html" METHOD="post">
...text fields, password field, and submit button appear here...
</FORM>

Step 4: Save the subscription form.

Save the subscription form and name it "subscription.html".

Step 5: Create a subscription processing page.

Create a page to process the subscription information, validate the username, add the username and password to the authentication database and display a thank you message to the user.

Step 6: Save the subscription processing page.

Save the subscription processing page and name it "process.html".

Step 7: Open the subscription processing page in a text editor.

Open the subscription processing page (process.html) in a text editing program that allows you to view and modify the HTML.

Step 8: Insert an mgiSet tag and an mgiAuthenticateDB tag in Validate mode.

On the subscription processing page, validate the user's chosen login for uniqueness and set the returned value (Yes or No) in a variable by entering an mgiAuthenticateDB tag in Validate mode within the body of an mgiSet tag. Insert your cursor in the location where you want the thank you message to appear. Enter a beginning mgiSet tag, name parameter, and ending mgiSet tag. In the name parameter, name the page variable "Validation".
<mgiSet name="Validation">
...Value of the variable appears here...
</mgiSet>
Enter an mgiAuthenticateDB tag, mode parameter, login parameter and group parameter in the body of the mgiSet tag. In the mode parameter, enter "Validate". In the login parameter, embed the value of the username that was entered in the form with an mgiFieldContent tag. In this example, the username field was named "Username". In the group parameter, enter the name of the group to use when validating the login name. The group parameter is not required. If the group parameter is not included, the username will be compared to all usernames in the MGI Authentication database for uniqueness.
<mgiSet name="Validation">
<mgiAuthenticateDB mode="validateLogin" 
login={mgiFieldContent name="Username"} group="Subscriber">  
</mgiSet>
The username validation process returns one of two values, yes or no. "Yes" indicates that the username is used and is not unique. "No" indicates that the username is not used and is unique. The value (Yes or No) is set in the page variable named "Validation". In the next step, enter MGI tags to perform a conditional comparison with the "Validation" variable and display an error message or add the username to the MGI Authentication database and an email that contains the subscription information depending on the value of the variable.

Step 9: Insert an mgiIf tag, an mgiAuthenticateDB tag in AddRecord mode, and an mgiSendMail tag.

After the ending mgiSet tag, enter a beginning mgiIf tag, target parameter, name parameter, value parameter, mgiElse tag, and ending mgiIf tag to perform a comparison with the value in the variable. In the target parameter, enter "Variable" as the target of the comparison. In the name parameter, enter the name of the variable that is the target of the comparison, "Validation". In the value parameter, enter the first value to compare, "Yes".
<mgiIf target="Variable" name="Validation" value="Yes">
...Result if the comparison is true appears here...
<mgiElse>
...Result if the comparison is false appears here...
</mgiIf>
To display an error message to users when their username is already in use, enter the message in the first body of the mgiIf tag (i.e., when the comparison is true). To display a thank you message, add the username and password to the MGI Authentication database, and send an email containing the subscription information, enter the message, an mgiAuthenticateDB tag in AddRecord mode and an mgiSendMail tag in the second body of the mgiIf tag (i.e., when the comparison is false).
 
Enter the mode parameter, login parameter, password parameter and group parameter with the mgiAuthenticateDB tag. In the mode parameter, enter "AddRecord". In the login parameter, embed the value of the username that was entered in the form with an mgiFieldContent tag. In this example, the username field was named "Username". In the password parameter, embed the value of the password that was entered in the form with an mgiFieldContent tag. In this example, the password field was named "Password". In the group parameter, enter the authentication group that the subscriber belongs to (Subscriber).
 
Enter the beginning mgiSendMail tag, to parameter, from parameter, subject parameter, mailserver parameter, and ending mgiSendMail tag after the mgiAuthenticateDB tag. In the "to" parameter, enter the email address to send each subscription to. In the "from" parameter, enter the email address that appears in the "from" line of the email header. In the subject parameter, enter the subject of the email. In the mailserver parameter, enter the outgoing mailserver to send the email. In the body of the mgiSendMail tag, enter a label, an mgiFieldContent tag and name parameter for each field of subscription information in the subscription form.
<mgiIf target="Variable" name="Validation" value="Yes">

Your username already exists.  Use the "Back" button on your browser
and choose another username.  Usernames are case-sensitive, so you
may try the same username with different capitalization.

<mgiElse>

Thank you for subscribing to our service.  You may access the
service immediately.

<mgiAuthenticateDB mode="AddRecord" 
login={mgiFieldContent name="Username"} 
password={mgiFieldContent name="Password"} group="Subscriber"> 

<mgiSendMail to="subscriptions@domain.com" from="webmaster@domain.com" 
subject="Subscription" mailserver="mail.domain.com">
    Name: <mgiFieldContent name="Name">
 Address: <mgiFieldContent name="Address">
   Phone: <mgiFieldContent name="Phone">
   Email: <mgiFieldContent name="Email">
Username: <mgiFieldContent name="Username">
Password: <mgiFieldContent name="Password">
</mgiSendMail>

</mgiIf>

Step 10: Save the subscription processing page.

Save the changes you have made to the subscription processing page.

Step 11: FTP the subscription form and processing page to the web server running MGI.

Upload the subscription form and subscription processing page from your local computer to the web server using an FTP program.

Step 12: Complete the subscription form.

Access the subscription form in a web browser. Complete the form choosing a username and password, then click the "Register" button to submit your subscription information to the processing page. If the username you chose is unique, then the message "Thank you for subscribing to our service. You may access the service immediately." is displayed, your username and password are added to the "Subscriber" group in the MGI Authentication database and an email is sent to "subscription@domain.com" that contains your subscription information.
 
If the username you chose is not unique, then the message "Your username already exists. Use the "Back" button on your browser and choose another username. Usernames are case-sensitive, so you may try the same username with different capitalization." is displayed, the username and password are not added to the MGI Authentication database and the subscription email is not sent.


[Return to the Password Protecting Pages Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]