Verifying Form Information

Introduction

Validating form information saves you time in processing a form requested. If you require specific information or information in a specifc format, use the mgiValidateData tag to check the for the existence of the data or the format of the data and return an error message or redirect visitors to a separate error page when data is invalid.

In this example, a doctor's office is accepting online registrations and validates specific data including required fields, email addresses, and appointment dates.

MGI Tags

Steps

  1. Create a medical registration form.
  2. Create a registration processing page and open it in a text editor.
  3. Validate the form information and send a formatted email.
  4. Save the registration processing page.
  5. FTP the registration form and processing page to the web server running MGI.
  6. View the registration form in a web browser and request an appointment.


Step 1: Create a medical registration form.

Create a medical registration form with form elements. In this example, the form has six sections including Contact Information, Medical History, Insurance Information, Emergency Contact Information, Reason for Visit and Appointment Date.
 
Name each form element uniquely. Enclose all form elements with HTML <FORM> tags and post the form to the registration processing page (register.mgi).
 
This is code for an example medical registration form.
<FORM ACTION="register.mgi" METHOD="POST">
<H2><CENTER>Medical Appointment Registration</CENTER></H2>
<P>Please complete all information as adequately as possible.
This will save you time during your initial visit to our clinic.
Required fields are marked in <B>bold</B>.</P>
<P><CENTER><TABLE BORDER="0" CELLSPACING="2" CELLPADDING="3" 
WIDTH="500">
  <TR>
    <TD COLSPAN="2" BGCOLOR="#66cccc"><B><FONT SIZE="+1">Patient
      Information</FONT></B></TD>   
  </TR>
  <TR>
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Name:
    </FONT></B></TD> 
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Address,
      City, State, Zip Code:</FONT></B></TD> 
  </TR>
  <TR>
    <TD WIDTH="50%" VALIGN="TOP"><INPUT NAME="Patient Name"
      TYPE="text" SIZE="30"></TD> 
    <TD WIDTH="50%" VALIGN="TOP"><INPUT NAME="Patient Address"
      TYPE="text" SIZE="30"><BR>
      <INPUT NAME="Patient City" TYPE="text" SIZE="15">
      <INPUT NAME="Patient State" TYPE="text" SIZE="2">
      <INPUT NAME="Patient Zip" TYPE="text" SIZE="5"></TD> 
  </TR>
  <TR>
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Phone
      Number:</FONT></B></TD> 
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Email
      Address:</FONT></B></TD> 
  </TR>
  <TR>
    <TD WIDTH="50%"><INPUT NAME="Patient Phone" TYPE="text"
      SIZE="30"></TD> 
    <TD WIDTH="50%"><INPUT NAME="Patient Email" TYPE="text"
      SIZE="30"></TD> 
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#66cccc"><B><FONT SIZE="+1">Medical
      History</FONT></B></TD>
  </TR>
  <TR>
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Please
      list all current medications and dosages:</FONT></B></TD> 
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Please
      describe any previous medical conditions including operations:
      </FONT></B></TD> 
  </TR>
  <TR>
    <TD WIDTH="50%"><TEXTAREA NAME="Medications" ROWS="5"
      COLS="27"></TEXTAREA></TD>
    <TD WIDTH="50%">&nbsp;<TEXTAREA NAME="Medical Conditions"
      ROWS="5" COLS="27"></TEXTAREA></TD> 
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#66cccc"><B><FONT SIZE="+1">Insurance
      Information</FONT></B></TD>
  </TR>
  <TR>
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Insurance
      Provider:</FONT></B></TD> 
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Group
      Number:</FONT></B></TD> 
  </TR>
  <TR>
    <TD WIDTH="50%"><INPUT NAME="Insurance Provider"
      TYPE="text" SIZE="30"></TD> 
    <TD WIDTH="50%"><INPUT NAME="Group Number" TYPE="text"
      SIZE="30"></TD> 
  </TR>
  <TR>
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><FONT SIZE="-1">Claims
      Telephone Number:</FONT></TD> 
    <TD WIDTH="50%">&nbsp;</TD> 
  </TR>
  <TR>
    <TD WIDTH="50%"><INPUT NAME="Claims Phone" TYPE="text"
      SIZE="30"></TD> 
    <TD WIDTH="50%">&nbsp;</TD> 
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#66cccc"><B><FONT SIZE="+1">Emergency
      Contact Information</FONT></B></TD>
  </TR>
  <TR>
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Name:</FONT>
    </B></TD> 
    <TD WIDTH="50%" BGCOLOR="#eeeeee"><FONT SIZE="-1">Address,
      City, State, Zip Code:</FONT></TD> 
  </TR>
  <TR>
    <TD VALIGN="TOP"><INPUT NAME="Contact Name" TYPE="text"
      SIZE="30"></TD> 
    <TD VALIGN="TOP"><INPUT NAME="Contact Address" TYPE="text"
      SIZE="30"><BR>
      <INPUT NAME="Contact City" TYPE="text" SIZE="15">
      <INPUT NAME="Contact State" TYPE="text" SIZE="2">
      <INPUT NAME="Contact Zip" TYPE="text" SIZE="5"></TD> 
  </TR>
  <TR>
    <TD BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Phone Number:
    </FONT></B></TD> 
    <TD BGCOLOR="#eeeeee"><FONT SIZE="-1">Alternate Phone
      Number:</FONT></TD> 
  </TR>
  <TR>
    <TD><INPUT NAME="Contact Phone" TYPE="text" SIZE="30"></TD> 
    <TD><INPUT NAME="Contact Alt Phone" TYPE="text" 
      SIZE="30"></TD> 
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#66cccc"><B><FONT SIZE="+1">Reason for
      Visit</FONT></B></TD>
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#eeeeee"><FONT SIZE="-1">Please describe
      the reason for your current visit to our clinic:</FONT></TD>
  </TR>
  <TR>
    <TD COLSPAN="2">
  <TEXTAREA NAME="Reason for Visit" ROWS="5" COLS="60">
    </TEXTAREA></TD>
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#66cccc"><B><FONT SIZE="+1">Appointment
      Date</FONT></B></TD>
  </TR>
  <TR>
    <TD COLSPAN="2" BGCOLOR="#eeeeee"><B><FONT SIZE="-1">Select your
      preferred appointment date. The date you choose cannot be more
      than 30 days after the current date (<mgiDate>).</FONT></B></TD>
  </TR>
  <TR>
    <TD COLSPAN="2">
      <P><CENTER><SELECT NAME="Month">
      <OPTION SELECTED VALUE="">Month
      <OPTION VALUE="01">January
      <OPTION VALUE="02">February
      <OPTION VALUE="03">March
      <OPTION VALUE="04">April
      <OPTION VALUE="05">May
      <OPTION VALUE="06">June
      <OPTION VALUE="07">July
      <OPTION VALUE="08">August
      <OPTION VALUE="09">September
      <OPTION VALUE="10">October
      <OPTION VALUE="11">November
      <OPTION VALUE="12">December
      </SELECT> <SELECT NAME="Day">
      <OPTION SELECTED VALUE="">Day
      <OPTION>01
      <OPTION>02
      <OPTION>03
      <OPTION>04
      <OPTION>05
      <OPTION>06
      <OPTION>07
      <OPTION>08
      <OPTION>09
      <OPTION>10
      <OPTION>11
      <OPTION>12
      <OPTION>13
      <OPTION>14
      <OPTION>15
      <OPTION>16
      <OPTION>17
      <OPTION>18
      <OPTION>19
      <OPTION>20
      <OPTION>21
      <OPTION>22
      <OPTION>23
      <OPTION>24
      <OPTION>25
      <OPTION>26
      <OPTION>27
      <OPTION>28
      <OPTION>29
      <OPTION>30
      <OPTION>31
      </SELECT> <SELECT NAME="Year">
      <OPTION SELECTED VALUE="">Year
      <OPTION>2001
      <OPTION>2002
      </SELECT></CENTER></TD>
  </TR>
</TABLE></CENTER></P>
<P><CENTER><input type="submit" value="Submit Registration"></CENTER>

Step 2: Create a registration processing page and open it in a text editor.

Create a page named "register.mgi" to format the registration information and send it to the designated address via email. Open the page in a text editing program that allows you to view and modify the HTML and code of the page.

Step 3: Validate the form information and send a formatted email.

Use the mgiValidateData tag to verify the existence of required form information, verify the format of the required email address, and verify the upper range of the selected appointment date. Since the default behavior of the mgiValidateData tag is to display the data when it is verified, the formatted body of the email is built in a page variable. A conditional comparison is then performed with the contents of the page variable to determine if errors are present. If errors are present, an error message is displayed. If errors are not present, a receipt message is displayed and the formatted email is sent.
 
To verify the existence of data, enter the mgiValidateData tag and data parameter. Embed an mgiPostArgument tag and name parameter in the data parameter. The post argument name is the name of the form information to validate.
 
To verify the format of a required email address, enter the mgiValidateData tag, data parameter and format parameter. Embed an mgiPostArgument tag and name parameter in the data parameter. The post argument name is the name of the form field that contains the email address to validate. In the format parameter, enter "emailAddress".
 
To validate dates you must first format the date in the default mm-dd-yyyy format or with another specified format. Enter the mgiValidateData tag, data parameter, type parameter, and upperSpan parameter. Embed an mgiPostArgument tag and name parameter in the data parameter. The post argument name is the name of the page variable that contains the properly formatted date information. In the type parameter, enter "Date". In the upperSpan parameter, enter the maximum number of days (from the current datte) that the date value is valid (e.g., "30").
 
For information that is not required, enter an mgiPostArgument tag and name parameter to display the data from the specified form field.
 
Use an mgiIf tag to check for "invalid data" errors produced by the mgiValidateData tag. If errors exist, display an error message. If errors do not exist, send the formatted email using the mgiSendMail tag. In the "to" parameter of mgiSendMail, enter the recipient's email address. In the "from" parameter, enter the sender's email address. In this example, the patient's email address is embedded as the sender of the email. In the "subject" parameter, enter the subject of the email. In the "mailServer" parameter, enter the address of the outgoing SMTP server. The formatted email is displayed in the body of the mgiSendMail tags with an mgiGet tag.
 
This is an example registration processing page.
<H2><CENTER>Medical Appointment Submission</CENTER></H2>

<mgiSet name="FormattedDate">
<mgiPostArgument name="Month">-<mgiPostArgument name="Day">-
<mgiPostArgument name="Year">
</mgiSet>

<mgiSet name="Validation">
Patient Information
-------------------
     Name: <mgiValidateData 
data={mgiPostArgument name="Patient Name"}>
  Address: <mgiValidateData 
data={mgiPostArgument name="Patient Address"}>
           <mgiValidateData 
data={mgiPostArgument name="Patient City"}> 
           <mgiValidateData 
data={mgiPostArgument name="Patient State"}> 
           <mgiValidateData 
data={mgiPostArgument name="Patient Zip"}>
    Phone: <mgiValidateData 
data={mgiPostArgument name="Patient Phone"}>
    Email: <mgiValidateData 
data={mgiPostArgument name="Patient Email"} 
           format="emailAddress">

Medical History
---------------
Medications:
<mgiValidateData data={mgiPostArgument name="Medications"}>

Conditions:
<mgiValidateData data={mgiPostArgument name="Medical Conditions"}>

Insurance Information
---------------------
  Provider: <mgiValidateData 
data={mgiPostArgument name="Insurance Provider"}>
     Group: <mgiValidateData 
data={mgiPostArgument name="Group Number"}>
    Claims: <mgiPostArgument name="Claims Phone">
   
Emergency Contact
-----------------
      Name: <mgiValidateData 
data={mgiPostArgument name="Contact Name"}>
   Address: <mgiPostArgument name="Contact Address">
            <mgiPostArgument name="Contact City"> 
            <mgiPostArgument name="Contact State"> 
            <mgiPostArgument name="Contact Zip">
     Phone: <mgiValidateData 
data={mgiPostArgument name="Contact Phone"}>
 Alt Phone: <mgiPostArgument name="Contact Alt Phone">
 
 
Reason for Visit
----------------
<mgiPostArgument name="Reason for Visit">

Requested Appointment Date: <mgiValidateData type="date" 
data={mgiGet name="FormattedDate"} upperSpan="30">
</mgiSet>

<mgiIf lhs={mgiGet name="Validation"} relationship="contains" 
rhs="invalid data">

<p><b>An error has occurred processing your appointment request.</b> 
Please use the "Back" button on your browser and verify the 
information you have entered.  Make sure all required fields 
have been completed, all email addresses are formatted 
properly and that your selected appointment date is not more 
than 30 days from today's date.

<mgiElse>

<P>Your registration and appointment information has been received.
Please bring copies of any previous medical records during your
visit. Your appointment time will be verified by phone.

<mgiSendMail to="registration@domain.com" 
from={mgiPostArgument name="Patient Email"} 
subject="Medical Registration" mailserver="mail.domain.com">
<mgiGet name="Validation">
</mgiSendMail>

</mgiIf>

Step 4: Save the registration processing page.

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

Step 5: FTP the registration form and processing page to the web server running MGI.

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

Step 6: View the registration form in a web browser and request an appointment.

View the registration form in a web browser. Complete and submit the form. An email with the following format is sent to the specified recipient.
Patient Information
-------------------
     Name: Charles Washington
  Address: 123 Main Ave
           Durham NC 21546
    Phone: 123-456-7894
    Email: charles@dbulls.net

Medical History
---------------
Medications:
Allegra - 50 MG

Conditions:
Allergies
Diabetes

Insurance Information
---------------------
  Provider: Blue Cross/Blue Shield
     Group: F8993H232121
    Claims: 704-256-8945
   
Emergency Contact
-----------------
      Name: Helen Washington
   Address: 123 Main Ave
            Durham NC 21546
     Phone: 123-456-7894
 Alt Phone: 856-456-7845
 
 
Reason for Visit
----------------
Yearly physical and checkup.

Requested Appointment Date: 06-03-2001


[Return to the Forms Submission Menu]


[Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]


[MGI Guides Main Menu] [User Guide Main Menu]