<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['submit'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek="Harus diisi lengkap!!";
}
?>
<html>
<head></head>
<body>
<h1><?echo $cek ?></h1><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="post" name="form1">
<p>Nama : <input type="text" name="nama" value="<?php echo $nama ?>"/></p>
<p>Jenis Kelamin : <input type="radio" name="gender" value="L"
<?php ($gender=="L")? print 'checked=""': print '';?>/>
Laki-Laki
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""': print ''; ?>/>
Perempuan</p>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if(isset($_POST['submit'])){//apakah data ter-submit?
/*membuat variabel untuk menyimpan data yang dikirim*/
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
//cek apakah data yang dikirim tidak kosong
if($nama=='' || $gender==''){
echo'<h2>Maaf Data Kurang Lengkap</h2>';
}else{
/*cek jenis kelamin*/
if($gender=='L'){
echo '<h2>Selamat Datang Bro, '. $nama.' !!</h2>';
}else{
echo '<h2>Selamat Datang Sis, '. $nama.' !!</h2>';
}
}
echo "<a href='".$_SERVER['PHP_SELF']."'>Reset</a>";// hasil
}
?>
Tidak ada komentar:
Posting Komentar