file new >>ASP web Aplication
masukkan script berikut :
<?php
session_start();
if(isset($_SESSION['error'])){
$error
= $_SESSION['error'];
$true
= $_SESSION['true'];
$_POST
= $_SESSION['post'];
unset($_SESSION['error']);
unset ($_SESSION['true']);
unset($_SESSION['post']);
}
if (empty($nama) || empty($gender) || empty($tempat)
||empty($email) || empty($alamat) || empty($kota) || empty($kodepos) ||
empty($hp) || empty($captcha) || empty($hari) ||empty($bulan) ||empty($tahun)){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body background="1.jpg">
<font color="#FFFFFF"><center>VALIDASI
FORM 2 FILE MENGGUNAKAN SESSION</center></font>
<form action="save_form.php"
name="form1" method="post">
<table CElLSPACING="0"
cellpadding="4" border="1" width="700"
height="420" align="center"
bgcolor="#FFFFFF"
Style='border-radius:20px;border-color:white;box-shadow: 0 0 5px 5px black;
position:fixed;left:350px;top:55px;'><br />
<tr>
<td
width="21%" rowspan="11" Style=' border-top-left-radius:20px;
'><imgsrc="images.jpg" /></td>
<td colspan="3"
bgcolor="#0099FF" align="center" Style='
border-top-right-radius:20px; '><font color="#FFFFFF"
>INPUTAN BIODATA</font></td>
</tr>
<tr>
<td
width="150">NamaLengkap</td>
<td width="2" > :</td>
<td width="500"><input
type="text" placeholder="NamaLengkap" name="nama"
value="<?php echo isset($_POST['nama']) ? $_POST['nama'] :
'';?>" />
<span
style="color:red"><?php echo isset($error['nama']) ?
$error['nama'] : ''; ?></span>
<div
style="color:red"></div></td> </tr>
<tr>
<td>JenisKelamin</td>
<td>:</td>
<td>
Laki-Laki<input
type="radio" name="gender" value="<?php echo
isset($_POST['gender']) ? $_POST['gender'] : ''; ?>Laki - Laki<?php echo
isset($_POST['gender']) ? ' checked' : ''; ?>"/>
Perempuan<input type="radio" name=gender
value="<?php echo isset($_POST['gender']) ? $_POST['gender'] : '';
?>Perempuan<?php echo isset($_POST['gender']) ? ' checked' : '';
?>" />
<font
size="-1" color="red"><?php echo
isset($error['gender']) ? $error['gender'] : '';?></font>
<?php echo isset ($true['gender'])?
$true['gender'] : '';?></td>
</tr>
<tr>
<td>TempatLahir</td>
<td>:</td>
<td><input type="text"
placeholder="TempatLahir" name="tempat"
value="<?php echo isset($_POST['tempat']) ? $_POST['tempat'] :
'';?>" />
<span
style="color:red"><?php echo isset($error['tempat']) ?
$error['tempat'] : ''; ?></span>
<div
style="color:red"></div></td>
</tr>
<tr>
<td>TanggalLahir</td>
<td>:</td>
<td>
<?php $bulan=array("Januari"
,"Februari", " Maret" ,"April", "Mei",
"Juni", "Juli", "Agustus", "September",
"Oktober", "November", "Desember");
echo '<select name="hari">'; $hari=1;
while($hari<=31) { echo "<option
value='$hari'>$hari</option>"; $hari++; } echo '</select>';
echo '<select name="bulan">';
$jumlah=count($bulan); for($i=0; $i<$jumlah ; $i++){ echo '<option
value="'.$bulan[$i].'">'.$bulan[$i].'</option>'; } echo
'</select>';
echo "<select name='tahun'>";
for($tahun=1991; $tahun<2010; $tahun++){ echo "<option
value='$tahun'>$tahun</option>"; } echo '</option>'; ?>
</td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text"
placeholder="Email" name="email" id="email"
value="<?php echo isset($_POST['email']) ? $_POST['email'] :
'';?>"/>
<span
style="color:red"><?php echo isset($error['email']) ?
$error['email'] : ''; ?></span>
<div
style="color:red"></div></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><input type="text"
placeholder="Alamat" name="alamat" value="<?php
echo isset($_POST['alamat']) ? $_POST['alamat'] : '';?>"/>
<span
style="color:red"><?php echo isset($error['alamat']) ?
$error['alamat'] : ''; ?></span>
<div
style="color:red"></div></td>
</tr>
<tr>
<td>KodePos</td>
<td>:</td>
<td><input type="text"
placeholder="KodePos" name="kodepos" value="<?php
echo isset($_POST['kodepos']) ? $_POST['kodepos'] : '';?>"/>
<span
style="color:red"><?php echo isset($error['kodepos']) ?
$error['kodepos'] : ''; ?></span>
<div
style="color:red"></div></td>
</tr>
<tr>
<td>Kota</td>
<td>:</td>
<td><input type="text"
placeholder="Kota" name="kota" value="<?php echo
isset($_POST['kota']) ? $_POST['kota'] : '';?>"/>
<span
style="color:red"><?php echo isset($error['kota']) ?
$error['kota'] : ''; ?></span>
<div
style="color:red"></div></td>
</tr>
<tr>
<td>No. HP</td>
<td>:</td>
<td><input type="text"
placeholder="No.HP" name="hp" value="<?php echo
isset($_POST['hp']) ? $_POST['hp'] : '';?>"/>
<span
style="color:red"><?php echo isset($error['hp']) ? $error['hp']
: ''; ?></span>
<div
style="color:red"></div></td>
</tr>
<tr>
<td>Captcha
<img height="30" style="vertical-align:middle;" src="Captcha.php?data=<?php
echo date('YmdHis');?> alt="securiy image" /></td>
<td><center>:</center></td>
<td>
<input
name="pin" placeholder="Captcha" type="text"
value="<?php echo isset($_POST['captcha']) ? $_POST['captcha'] :
''; ?>" />
<font size="-1"
color="red"><?php echo isset($error['pin']) ? $error['pin'] :
'';?></font>
<font><?php echo isset
($true['pin'])? $true['pin'] : '';?></font>
</td>
</tr>
<tr>
<td colspan=4 align="center"
Style='
border-bottom-right-radius:20px;border-bottom-left-radius:20px;'><center><button
type="reset" value="Refresh"
ONCLICK="history.go(0)"> Reset </button> <button
type="Submit" name="submit"
> Kirim </button></CENTER></td>
</tr>
</table>
</FORM>
<?php
}
?>
</body>
</html>
laluselanjutnya file new lagidengannamaSave_form,danketikkan
script berikut:
<?php
if ($_POST){
session_start();
$nama =
$_POST['nama'];
$gender=isset($_POST['gender'])?
$_POST['gender']:"";
$tempat=$_POST['tempat'];
$email=$_POST['email'];
$hari = $_POST['hari'];
$bulan = $_POST['bulan'];
$tahun = $_POST['tahun'];
$emailPattern
= '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
$alamat =
$_POST['alamat'];
$kota =
$_POST['kota'];
$kodepos = $_POST['kodepos'];
$kodeposPattern
= '/^\d{5}([\-]\d{4})?$/';
$hp
=$_POST['hp'];
$CAPTCHA=$_POST['pin'];
$imgErr='<img
src=error.png height="20"
sytle="vertical-align:midle"><br>';
$error = array();
if(empty($nama)){
$error['nama']=$imgErr.'Namatidakbolehkosong';
}
if(empty($gender)){
$error['gender']=$imgErr.'JenisKelamintidakbolehkosong';
}
if(empty($tempat)){
$error['tempat']=$imgErr.'TempatLahirtidakbolehkosong';
}
if(empty ($email)){
$error['email'] = $imgErr.'Email
tidakbolehkosong';
} elseif (!preg_match($emailPattern, $email)){
$error['email'] = $imgErr.'Email
salahtulis (xxxxxxx@xxxxx.xxx)';
}
if(empty($alamat)){
$error['alamat']=$imgErr.'Alamattidakbolehkosong';
}
if(empty($kota)){
$error['kota']=$imgErr.'Kota
tidakbolehkosong';
}
if(empty($kodepos)){
$error['kodepos']=$imgErr.'KodePostidakbolehkosong';
} elseif
(!preg_match($kodeposPattern, $kodepos)){
$error['kodepos']
= $imgErr.'Salah Format (#####-####)';
}
if(empty($hp)){
$error['hp']=
$imgErr.'No. Hptidakbolehkosong';
}
if(empty ($CAPTCHA)){
$error['pin'] =
$imgErr.'Captchatidakbolehkosong';
} elseif (md5($_POST['pin']) <>
$_SESSION['image_random_value']){
$error['pin']
= $imgErr.'Andabukanmanusia';
}
if(empty($error)){
if($gender=='Laki
- Laki'){
echo'<font
color="#FFFFFF"
size="+1"><center>SelamatDatangSaudara
'.$nama.'<br>BerikutBiodatamu</center></font>';
}
else{
echo'<font
color="#FFFFFF"><center>SelamatDatangSaudari,
'.$nama.'<br>BerikutBiodatamu</center></font>';
}
print("
<table cellspacing='0' cellpadding='4'
align='center' bgcolor='#FFFFFF' border='1' width='650' height='300'
Style='border-radius:20px;border-color:white;
position:fixed;left:360px;top:110px;box-shadow: 0 0 5px 5px black; '>
<tr>
<td colspan='4'
bgcolor='#0099FF' Style=' border-top-left-radius:20px; border-top-right-radius:20px'>
<center><strong><font
color='black'><div class='Da'>DATA
DIRI</div></font></strong></center>
</td>
</tr>
<tr>
<td>NamaLengkap</td>
<td
width='1'><center>:</center></td>
<td> $nama</td>
</tr>
<tr>
<td>JenisKelamin</td>
<td><center>:</center></td>
<td> $gender </td>
</tr>
<tr>
<td>TTL</td>
<td><center>:</center></td>
<td>$tempat, $hari -
$bulan - $tahun</td>
</tr>
<tr>
<td>Alamat</td>
<td><center>:</center></td>
<td> $alamat</td>
</tr>
<tr>
<td>E-mail</td>
<td><center>:</center></td>
<td>$email</td>
</tr>
<tr>
<td>KodePos</td>
<td>:</td>
<td>$kodepos</td>
</tr>
<tr>
<td>Kota</td>
<td>:</td>
<td>$kota</td>
</tr>
<tr>
<td
Style=' border-bottom-left-radius:20px'>No. HP</td>
<td><center>:</center></td>
<td
style='border-bottom-right-radius:20px'>$hp</td>
</tr>
</table>
");
}
else{
$_SESSION['error']=$error;
$_SESSION['true']=$true;
$_SESSION['post']
=$_POST;
header("location:valid_form.php");
}
}
?>
Maka hasilnya :
Jika ada data yang kurang lengkap :
Jika benar maka hasil submit :
Semogaberhasil
Tidak ada komentar:
Posting Komentar