Buat Form registrasi,dengan nama form-registrasi.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Membership Form</tittle>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--common.cs merupakan code dari buku Beginning PHP 5.3-->
</head>
<body>
<h1>Formulir Pendaftaran</h1>
<form action="registrasi2.php" method ="POST">
<div style ="width:30 cm;">
<label for ="nama">Nama</label>
<input type ="text" name ="nama" id="nama" value = ""/>
<label for = "nim">N I M</label>
<input type="text" name ="nim" id ="nim" value ="" />
<label for = "password1">Password</label>
<input type="password" name ="password1" id ="password1" value ="" />
<label for ="laki-laki">Apakah Anda Laki-Laki...</label>
<input type="radio" name="jk" id="Laki-Laki" value ="Laki-Laki"/>
<label for="perempuan">...atau perempuan?</label>
<input type="radio" name="jk" id="perempuan" value="perempuan"/>
<label for ="paket">paket yang anda pilih?</label>
<select name="paket" id="favoriteWidget" size="1">
<option value="platinum">Paket Platinum</option>
<option value="gold">Paket Gold</option>
<option value="silver">Paket Silver</option>
</select>
<input type="submit" name="daftar" id="daftar" value="Daftar"/>
</div>
</form>
</body>
</html>
Buat css untuk mengatur ukuran formnya dengan nama common.css:
/*Page Body */
body {font-family : Arial,helvetia,sans-serif;}
/*definition lists*/
dl {
width:100%;
margin:2em 0;
padding: 0;
clear: both;
overflow:auto;
}
dt {
width:30%;
float : left ;
margin:0;
padding: 5px 9.9% 5px 0; 0
order-top:1px solid #DDDDB7;
font-weight:bold;
overflow:auto;
clear:left;
}
dd {
width : 60%;
float :left;
margin:0;
padding:6px 0 5px 0;
border-top:1px solid #DDDDB7;
overflow:auto;
}
/*headings*/
h1{
font-weight:bold;
margin:35px 0 14px;
color:#666;
font-size:1.5em;
}
h2{
font-weight:bold;
margin:30px 0 12px;
color:#666;
font-size:1.3em;
}
h3{
font-weight:normal;
margin:30px 0 12px;
color:#666;
font-size:1.2em;
}
h4{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:1.0em;
}
h5{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:0.9em;
}
/*form*/
label { display:block;
float:left;
clear:both;
text-align:right;
margin:0.6em 5px 0 0;
width: 40%;
}
input,select,textarea {
float:right;
margin:1em 0 0 0;
width:57%;
}
input {
border:1px solid #666;
}
input[type=radio], iinput[type=checkbox],input[type=submit],input[type=reset],input[type=button],input[type=image]{
width:auto;
}
Buat file untuk menampilkan isi dari form-registasi.html,degan nama registrasi.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<title>Membership Form</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1>Anda Telah Terdaftar</h1>
<p>Berikut adalah data anda:</p>
<dl>
<dt>Nama Anda </dt><dd><?php echo $_POST["nama"]?></dd>
<dt>NIM</dt><dd><?php echo $_POST["nim"]?></dd>
<dt>Password</dt><dd><?php echo $_POST["password"]?></dd>
<dt>Jenis Kelamin</dt><dd><?php echo $_POST["jk"]?></dd>
<dt>Paket yang anda Pilih</dt><dd><?php echo $_POST["paket"]?></dd>
</dl>
</body>
</html>
* Praktikum 6.2
Tambahkankan Password & Konfirmaasi password.jika password dan konfirmasi password tidak sama,maka muncul message box "Password tidak sama".code nya sebagai berikut :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Membership Form</tittle>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--common.cs merupakan code dari buku Beginning PHP 5.3-->
</head>
<body>
<h1>Formulir Pendaftaran</h1>
<form action="registrasi2.php" method ="POST">
<div style ="width:30 cm;">
<label for ="nama">Nama</label>
<input type ="text" name ="nama" id="nama" value = ""/>
<label for = "nim">N I M</label>
<input type="text" name ="nim" id ="nim" value ="" />
<label for = "password1">Password</label>
<input type="password" name ="password1" id ="password1" value ="" />
<label for = "password2">Konfirmasi Password</label>
<input type="password" name ="password2" id ="password2" value ="" />
<label for ="laki-laki">Apakah Anda Laki-Laki...</label>
<input type="radio" name="jk" id="Laki-Laki" value ="Laki-Laki"/>
<label for="perempuan">...atau perempuan?</label>
<input type="radio" name="jk" id="perempuan" value="perempuan"/>
<label for ="paket">paket yang anda pilih?</label>
<select name="paket" id="favoriteWidget" size="1">
<option value="platinum">Paket Platinum</option>
<option value="gold">Paket Gold</option>
<option value="silver">Paket Silver</option>
</select>
<input type="submit" name="daftar" id="daftar" value="Daftar"/>
</div>
</form>
</body>
</html>
File registrasi.php akan muncul seperti dibawah ini jika saat konfirmasi password tidak sama dengan password yang kita masukkan sebelumnya.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<title>Membership Form</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<?php
if ($_POST["password1"] != $_POST["password2"]){
echo "<script>alert ('password tidak sama ');</script>";
}
else
{?>
<h1>Anda Telah Terdaftar</h1>
<p>Berikut adalah data anda:</p>
<dl>
<dt>Nama Anda </dt><dd><?php echo $_POST["nama"]?></dd>
<dt>NIM</dt><dd><?php echo $_POST["nim"]?></dd>
<?php if (($_POST["password1"])== $_POST["password2"]){?>
<dt>Password</dt><dd><?php echo $_POST["password"]?></dd>
<?php } ?>
<dt>E-Mail</dt><dd><?php echo $_POST["email"] ?> </dd>
<dt>Jenis Kelamin</dt><dd><?php echo $_POST["jk"]?></dd>
<dt>Paket yang anda Pilih</dt><dd><?php echo $_POST["paket"]?></dd>
</dl>
<?php } ?>
</body>
</html
2.Membuat code form-registrasi dengan html 5, maka jika ada field yang tidak di isi akan diberi peringatan .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--common.cs merupakan code dari buku Beginning PHP 5.3-->
</head>
<body>
<h1>Formulir Pendaftaran</h1>
<form action="registrasi2.php" method ="POST">
<div style ="width:30 cm;">
<label for ="nama">Nama</label>
<input type ="text" name ="nama" id="nama" value = "" required = 'required'/>
<label for = "nim">N I M</label>
<input type="text" name ="nim" id ="nim" value ="" required = 'required' />
<label for = "password1">Password</label>
<input type="password" name ="password1" id ="password1" value ="" required = 'required'/>
<label for = "password2">Konfirmasi Password</label>
<input type="password" name ="password2" id ="password2" value ="" required = 'required' />
<label for ="laki-laki">Apakah Anda Laki-Laki...</label>
<input type="radio" name="jk" id="Laki-Laki" value ="Laki-Laki" required = 'required'/>
<label for="perempuan">...atau perempuan?</label>
<input type="radio" name="jk" id="perempuan" value="perempuan" required = 'required'/>
<label for ="paket">paket yang anda pilih?</label>
<select name="paket" id="favoriteWidget" size="1">
<option value="platinum">Paket Platinum</option>
<option value="gold">Paket Gold</option>
<option value="silver">Paket Silver</option>
</select>
<input type="submit" name="daftar" id="daftar" value="Daftar"/>
</div>
</form>
</body>
</html>
3.Menambahkan field e-mail pada form-registrasi kemudian dimunculkan pada file php:
form registrasi:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--common.cs merupakan code dari buku Beginning PHP 5.3-->
</head>
<body>
<h1>Formulir Pendaftaran</h1>
<form action="regis4.php" method ="POST">
<div style ="width:30 cm;">
<label for ="nama">Nama</label>
<input type ="text" name ="nama" id="nama" value = "" required = 'required'/>
<label for = "nim">N I M</label>
<input type="text" name ="nim" id ="nim" value ="" required = 'required' />
<label for = "password1">Password</label>
<input type="password" name ="password1" id ="password1" value ="" required = 'required'/>
<label for = "password2">Konfirmasi Password</label>
<input type="password" name ="password2" id ="password2" value ="" required = 'required' />
<label for = "email">E-Mail</label>
<input type="text" name ="email" id ="email" value ="" required = 'required' />
<label for ="laki-laki">Apakah Anda Laki-Laki...</label>
<input type="radio" name="jk" id="Laki-Laki" value ="Laki-Laki" required = 'required'/>
<label for="perempuan">...atau perempuan?</label>
<input type="radio" name="jk" id="perempuan" value="perempuan" required = 'required'/>
<label for ="paket">paket yang anda pilih?</label>
<select name="paket" id="favoriteWidget" size="1">
<option value="platinum">Paket Platinum</option>
<option value="gold">Paket Gold</option>
<option value="silver">Paket Silver</option>
</select>
<input type="submit" name="daftar" id="daftar" value="Daftar"/>
</div>
</form>
</body>
</html>
untuk file php :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<title>Membership Form</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<?php
if ($_POST["password1"] != $_POST["password2"]){
echo "<script>alert ('password tidak sama ');</script>";
}
else
{?>
<h1>Anda Telah Terdaftar</h1>
<p>Berikut adalah data anda:</p>
<dl>
<dt>Nama Anda </dt><dd><?php echo $_POST["nama"]?></dd>
<dt>NIM</dt><dd><?php echo $_POST["nim"]?></dd>
<?php if (($_POST["password1"])== $_POST["password2"]){?>
<dt>Password</dt><dd><?php echo $_POST["password"]?></dd>
<?php } ?>
<dt>E-Mail</dt><dd><?php echo $_POST["email"] ?> </dd>
<dt>Jenis Kelamin</dt><dd><?php echo $_POST["jk"]?></dd>
<dt>Paket yang anda Pilih</dt><dd><?php echo $_POST["paket"]?></dd>
</dl>
<?php } ?>
</body>
</html>
0 komentar: