As explained previously that the server validation will be more severe performed, because the data must be sent to the server for processing. The next result of new here is sent to the client. Certainly the language used here should also be language that supports client-server. Eg ASP, PHP, JSP and others. On this occasion we will about ASP.
<%@LANGUAGE="JSCRIPT"%>
<html> <head>
<title>.::Penggunaan Validasi Input Form::.</title>
</head>
<body>
<pre>
<form method="get" name="form1" action="form.asp">
NIM : <input type="text" name="nim" maxlength="8">
E-mail Address : <input type="text" name="mail" maxlength="30">
<input type="hidden" value="baru" name="sembunyi">
<input type="submit" value="kirim">
</form>
<hr>
</pre>
<%
var ukuran = Request.QueryString("nim").length;
if (Request.QueryString("sembunyi") == "baru")
if ((ukuran < 8) || (ukuran > 8))
Response.Write("Jumlah Karakter pada NIM masih salah")
else if (isNaN(Request.QueryString("nim")))
Response.Write("NIM haruslah berupa bilangan 8 digit")
else if ((String(Request.QueryString("mail")).indexOf("@",1)) < 1)
Response.Write("Penulisan Alamat Email masih Salah")
else
{
%>Selamat datang Peserta dengan nim <%=Request.QueryString("nim")%>
<br>
Alamat Email Anda adalah <%=Request.QueryString("mail")%><%
}
%>
</body> </html>
Description:
- To be able to manipulate the value of request.form and request.querystring by using a string object, then the first value obtained string of the request made by using the function 'String (request.colection)'
- Checking the contents of the new form will be done when it occurs at least one time delivery of data from the form to get form.asp, this can be seen through an examination of the value of the element 'hidden'
- Any object - the object and functions Built-In, which has been studied in JavaScript can all be used on an ASP script. With notes on The first line of the page should be in terakan identifier <% @ LANGUAGE = "JScript"%>
- This page will process the NIM client input 2 and E-Mail, then The input will be checked the truth of writing.
Save the above file with the name form.asp. If run in a browser, it will look like the following:
Then fill out the form and click the OK button, then the value will be delivered processed by form.asp file itself. Function isnan () is used to perform checks whether the value entered in the form of numerical NIM. If the form numeric, then the form will be processed, if not then it will display the numeric Message: NIM should be the number of 8 digits. Here is an example of the result if NIM input numeric and e-mail address is entered correctly:
Use the form input validation with ASP as necessary, because form validation in the above example is done on the server, meaning that after the browser sends the data to the server, then the server will perform validation, and the result is returned to the browser. It will take time, especially if internet network traffic when it is busy. To avoid this, validation should be performed directly in the browser (client-side) by using client-side scripting language.
Exercise Form
Write the source code below and save it into a file with the file name as stated in any source code.
<HTML>
<HEAD>
<TITLE> .:: Penanganan Form ::. </TITLE>
</HEAD>
<BODY>
<p align="center" style="margin-top: 0; margin-bottom: 0">
<font size="4" color="#0000FF" face="Tahoma">PROGRAM PROFESIONAL STT
TELKOM</font></p>
<p align="center" style="margin-top: 0; margin-bottom: 0">
<font size="4" color="#0000FF" face="Tahoma">KELAS WEB MASTER</font></p>
<p align="center" style="margin-top: 0; margin-bottom: 0">
<font size="4" color="#FF0000" face="Tahoma">
<marquee behavior="alternate">DESAIN DAN TATA LETAK WEB DENGAN
HTML</marquee></font></p>
<HR>
</BODY>
Form yang kudu diisi.
<!-- #include file = "header.html" -->
<html>
<head>
<title>.:: Penanganan Form ::.</title>
</head>
<body BgColor = "#05F5F5">
<form method = "POST" action = "tampilan.asp">
<font face = "Arial">
<Table border=0 width=721>
<tr>
<td width=75> <font size="2">Nama </font> </td>
<td width=6> <font size="2">: </font> </td>
<td width=158>
<input type = "text" NAME="txNama" size="20" ></td>
<td width=135> <font size="2" face="Arial">Tempat/Tanggal Lahir </font>
</td>
<td width=6>:</td>
<td width=155><font face = "Arial">
<input type = "text" size="20" NAME="txTglLahir"></font></td>
</tr>
<tr>
<td width="75"> <font size="2">Nim </font> </td>
<td width="6"> <font size="2">: </font> </td>
<td width="158">
<input type="password" name="txNim" size="20"></td>
<td width="135"> <font size="2" face="Arial">Asal Kota</font></td>
<td width="6"> :</td>
<td width="155">
<SELECT NAME=kota SIZE=1>
<OPTION SELECTED>Bandung
<OPTION>Jakarta
<OPTION>Medan
<OPTION>Surabaya
<OPTION>Yogyakarta
</SELECT>
</td>
</tr>
<tr>
<td width="75"> <font size="2">Pilihan </font> </td>
<td width="6"> <font size="2">: </font> </td>
<td width="158">
<input type="radio" name="pilihan"
value="Web Programming" checked>
<font size="2"> ASP</font></td>
<td width="135"> <font size="2" face="Arial">Hobby </font> </td>
<td width="6"> <font size="2">:</font></td>
<td width="155"> <font face = "Arial">
<input type="checkbox" name="ckPil" value="Membaca">
<font size="2"> Membaca </font> </td>
</tr>
<tr>
<td width="75"> <font size="2"> </font> </td>
<td width="6"> <font size="2"> </font> </td>
<td width="158">
<input type="radio" name="pilihan">
<font size="2"> Flash</font></td>
</td>
<td width="155"> </td>
<td width="4"> </td>
<td width="148"><font face = "Arial">
<input type="checkbox" name="ckPil" value="Musik">
<font size="2"> Musik </font> </font> </td>
</tr>
<tr>
<td width="75"> <font size="2"> </font> </td>
<td width="6"> <font size="2"> </font> </td>
<td width="158"><input type="radio" name="pilihan">
<font size="2"> Java Script</font> </td>
<td width="135"> </td>
<td width="6"> </td>
<td width="155"> <font face = "Arial">
<input type="checkbox" name="ckPil" value="Olah Raga">
<font size="2"> Olah Raga </font> </font> </td>
</tr>
<tr>
<td width="75" valign="top"> <font size="2" face="Arial"> Peminatan
</font>
</td>
<td width="6" valign="top"> <font size="2">: </font> </td>
<td width="158"> <font face = "Arial">
<SELECT NAME="minat" SIZE=3 MULTIPLE>
<OPTION SELECTED>Pendidikan
<OPTION>Hardware
<OPTION>Software <OPTION>Staff IT
<OPTION>Telekomunikasi
</SELECT></font></td>
<td width="135" valign="top"> <font size="2" face="Arial"> Komentar Anda
</font> </td>
<td width="6" valign="top">:</td>
<td width="155">
<textarea NAME="txKomen" rows="3" cols="20">
</textarea></td>
</tr>
<tr>
<td colspan="2"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input type="submit" Value="Kirim Form">
</td>
<td>
<font face = "Arial">
<input type="reset" Value=" Batal "></font></td>
</tr>
</table>
</form>
</body> </html>
Run the program on your browser, the page will appear as
below: