Tutorial PHP 6


1. buka dreamweaver anda dan buat lagi file baru dengan nama Validasi_Form dan isikan dengan coding berikut..



<?php
    session_start();
    if(isset($_SESSION['eror'])){
        $eror = $_SESSION['eror'];
        $_POST = $_SESSION['post'];
        unset($_SESSION['eror']);
        unset($_SESSION['post']);
    }
   
    if (empty($nama) || empty($gender) || empty($email) || empty($alamat) || empty($kota) || empty($email) || empty($password) || empty($no_hp) || 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 style="background-color:blue; background-repeat:repeat;">
<p><center>VALIDASI FORM 2 FILE MENGGUNAKAN SESSION</center></p>

<form name="form-name" method="post" action="Valid_Script.php">
    <table cellspacing="0" cellpadding="4" bgcolor="#FFFFFF" border="1" width="700" height="420" Style='border-radius:20px;border-color:white; box-shadow: 0 0 5px 5px black; position:fixed;left:350px;top:55px;'>
        <tr>
            <td rowspan="11"><img src="logotelkom.jpg" width="150" height="160" /></td>
        </tr>
        <tr>
            <td colspan="3"><div style="background-color:#06C"><center>INPUTAN BIODATA</center></div></td>
        </tr>
        <tr>
            <td width="53%">Nama Lengkap</td>
            <td width="3%">:</td>
            <td width="44%"><input placeholder="Nama Lengkap" name="nama" id="nama" type="text" value="<?php echo isset($_POST['nama']) ? $_POST['nama'] : '';?>"/><font color=red><?php echo isset($eror['nama']) ? $eror['nama'] : '';?></font></td>
        </tr>
        <tr>
            <td>Jenis Kelamin</td>
            <td>:</td>
            <td><input type="radio" name="gender" value="L" <?php echo isset($_POST['gender']) ? $_POST['gender'] == "L" ? ' checked' : '' :"" ; ?>/> &nbsp;Laki-Laki
    
            <input type="radio"  name="gender" value="P" <?php echo isset($_POST['gender']) ? $_POST['gender'] == "P" ? ' checked' : '' : "" ; ?> /> &nbsp;Perempuan
            <font color=red><?php echo isset ($eror['gender'])? $eror['gender'] : '';?></font>
     </td>
           
        </tr>
        <tr>
            <td>TTL</td>
            <td>:</td>
            <td><input name="kota" type="text" id="kota" placeholder="Tempat" value="<?php echo isset($_POST['kota']) ? $_POST['kota'] : '';?>" />, <?php $bulan=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");

echo '<select name="hari">';
echo "<option value=hari>Hari</option>";
$hari=1;
$haripilih = isset($_POST['hari']) ? $_POST['hari'] : "hari";

while($hari<=31){
echo "<option value=$hari";
echo $hari == $haripilih ? " selected" : "";   
echo '>'.$hari.'</option>';
    $hari++;
}
echo '</select>';

echo '<select name="bulan">';
echo "<option value=bulan>Bulan</option>";
$jumlah=count($bulan);
$bulanpilih = isset($_POST['bulan']) ? $_POST['bulan'] : "bulan";
for($i=0; $i<$jumlah ; $i++){
    echo "<option value=$bulan[$i]";
    echo $bulan[$i] == $bulanpilih ? " selected" : "";
    echo '>'.$bulan[$i].'</option>';
}
echo '</select>';

echo '<select name="tahun">';
echo "<option value=tahun>Tahun</option>";
$tahunpilih = isset($_POST['tahun']) ? $_POST['tahun'] : "tahun";
for($tahun=1990; $tahun<2013; $tahun++){
    echo "<option value='$tahun'";
    echo $tahun == $tahunpilih ? " selected" : "";
    echo '>'.$tahun.'</option>';
}
echo '</select>';?><font color=red><?php echo isset($eror['kota']) ? $eror['kota'] : '';?></font></td>
        </tr>
        <tr>
            <td>Email</td>
            <td>:</td>
            <td><input name="email" id="email" placeholder="Email" type="text" value="<?php echo isset($_POST['email']) ? $_POST['email'] : '';?>"/><font color=red><?php echo isset($eror['email']) ? $eror['email'] : '';?></font></td>
        </tr>
        <tr>
            <td>Password</td>
            <td>:</td>
            <td><input name="password" id="password" placeholder="Password" type="password" value="<?php echo isset($_POST['password']) ? $_POST['password'] : '';?>"/><font color=red><?php echo isset($eror['password']) ? $eror['password'] : '';?></font></td>
        </tr>
        <tr>
            <td>Alamat</td>
        <td>:</td>
        <td><input type='text' placeholder="Alamat" name="alamat" size="40" value="<?php echo isset($_POST['alamat']) ? $_POST['alamat'] : ''; ?>" />
        <font color=red><?php echo isset($eror['alamat']) ? $eror['alamat'] : '';?></font>
        </td>
        </tr>
        <tr>
            <td>No Hp</td>
            <td>:</td>
            <td><input name="no_hp" id="no_hp" placeholder="NO HP" type="text" value="<?php echo isset($_POST['no_hp']) ? $_POST['no_hp'] : '';?>"/><font color=red><?php echo isset($eror['no_hp']) ? $eror['no_hp'] : '';?></font></td>
        </tr>
        <tr>
            <td>Inputkan Captcha <br /><img src="Captcha.php?date=<?php echo date('YmdHis'); ?>" alt="security image" /></td>
            <td>:</td>
            <td><input type="text" name="pin" placeholder="Isikan Captcha" value="<?php echo isset($_POST['pin']) ? $_POST['pin'] : '';?>"/><font color=red><?php echo isset($eror['pin']) ? $eror['pin'] : '';?></font></td>
        </tr>
        <tr>
            <td colspan="3"><center><input name="submit" id="submit" type="Submit" value="Submit" /></center></td>
        </tr>
    </table>
</form>
</body>
</html>

2. lalu save dalam 1 folder dengan site yang benar ..
3. buat lagi file baru dengan nama Captcha dan isikan dengan coding berikut..

<?php
session_start();
$alphaNumeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$random = substr(str_shuffle($alphaNumeric), 0, 5);
$image = imagecreatefromjpeg("background2.jpg");
$textColor = imagecolorallocate ($image, 0, 0, 0); //black
imagestring ($image, 5, 5, 8, $random, $textColor);
$_SESSION['image_random_value'] = md5($random);
//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modeified: " . gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
?>

4. 2. lalu save dalam 1 folder dengan site yang benar ..
5. jalankan hasilnya di browser, maka hasilnya akan seperti ini ..



Tidak ada komentar:

Posting Komentar