Rozi. Diberdayakan oleh Blogger.

Sabtu, 07 Desember 2013

Praktikum ASP 6

pertama kita buat dulu file new dulu ASP web Aplication 
ketikkan script berikut,beri nama form_validation_result sebagai penampil hasil dari isian form nantinya :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Valid_Form_Result.aspx.cs" Inherits="Bab3.Tugas.ValidasiFormResult" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            font-size: xx-large;
            font-weight: bold;
        }
    </style>
</head>
    <body Style="background-image:url(images.jpg); background-repeat:repeat;">
    <form id="form1" runat="server">
    <div style="margin-top: 71px">
        <table align="center">
        <tr>
        <td>
        <asp:Label ID="lblNama" runat="server" CssClass="auto-style1" ForeColor="Yellow"></asp:Label><br />
        </td>
        </tr>
        <tr>
        <td>
        <asp:Label ID="lblNIS" runat="server" CssClass="auto-style1" ForeColor="Yellow"></asp:Label><br />
        </td>
        </tr>
        <tr>
        <td>
        <asp:Label ID="lblUmur" runat="server" CssClass="auto-style1" ForeColor="Yellow"></asp:Label><br />
        </td>
        </tr>
        <tr>
        <td>
        <asp:Label ID="lblEmail" runat="server" CssClass="auto-style1" ForeColor="Yellow"></asp:Label><br />
        </td>
        </tr>
        <tr>
        <td>
        <asp:Label ID="lblPassword" runat="server" CssClass="auto-style1" ForeColor="Yellow"></asp:Label><br />
        </td>
        </tr>
        </table>
    </div>
    </form>
</body>
</html>
lalu file new seperti tadi lagi,beri nama valid_form:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Valid_Form.aspx.cs" Inherits="Bab3.Tugas.ValidasiForm" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Isi Form</title>
    <link href="MyStyle.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .auto-style3 {
            width: 160px;
        }
        .auto-style4 {
            height: 30px;
        }
        .auto-style5 {
            width: 160px;
            height: 30px;
        }
    </style>
</head>
<body Style="background-image:url(images.jpg); background-repeat:repeat;">
    <form id="form1" runat="server">
    <div>
        <asp:ValidationSummary ID="vsSum" CssClass="div" runat="server" Width="286px" 
            ShowMessageBox="true" />
        </div><br />
        <center><table style="width:70%;" >           
            <tr>
                <th colspan="4">FORM BIODATA</th>
            </tr>
            <tr>
                <td rowspan="7">
                    <center><img src="asm.jpg" height="160px" />
                </td>
            </tr>
            <tr>
                <td class="auto-style4">Nama Lengkap :</td>
                <td class="auto-style5">
                    <asp:TextBox ID="txtNama" runat="server" Width="165px" Height="30px"></asp:TextBox></td>
                <td class="auto-style4">&nbsp;<asp:RequiredFieldValidator ID="rfvNama" runat="server" ControlToValidate="txtNama"
                    CssClass="RequiredFieldValidator" ErrorMessage="Nama harus diisi"
                    Text="<img src='stacks_image_91.png' width='25px' class='center' />Nama Harus Diisi" />
                    </td>
            </tr>
            <tr>
                <td class="auto-style1">NIS :</td>
                <td class="auto-style3">
                    <asp:TextBox ID="txtNIS" runat="server" Width="165px" Height="30px"></asp:TextBox></td>
                <td class="auto-style4">&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNIS"
                    CssClass="RequiredFieldValidator" ErrorMessage="NIS harus diisi"
                    Text="<img src='stacks_image_91.png' width='25px' class='center' />NIS Harus Diisi" />
                    </td>
            </tr>
            <tr>
                <td class="auto-style1">Umur :</td>
                <td class="auto-style3">
                    <asp:TextBox ID="txtUmur" runat="server" Width="165px" Height="30px"></asp:TextBox></td>
                <td class="auto-style4">&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtUmur"
                    CssClass="RequiredFieldValidator" ErrorMessage="Umur harus diisi"
                    Text="<img src='stacks_image_91.png' width='25px' class='center' />Umur Harus Diisi" />
                    </td>
            </tr>
            <tr>
                <td class="auto-style1">Email :</td>
                <td class="auto-style3">
                    <asp:TextBox ID="txtEmail" runat="server" Width="165px" Height="30px"></asp:TextBox></td>
                 <td class="auto-style4">&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtEmail"
                    CssClass="RequiredFieldValidator" ErrorMessage="Email harus diisi"
                    Text="<img src='stacks_image_91.png' width='25px' class='center' />Email Harus Diisi" />
                    </td>
            </tr>
            <tr>
                <td class="auto-style1">Password :</td>
                <td class="auto-style3">
                    <asp:TextBox ID="txtPass" runat="server" Width="165px" Height="30px"></asp:TextBox>
                </td>
                 <td class="auto-style4">&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtPass"
                    CssClass="RequiredFieldValidator" ErrorMessage="Password harus diisi"
                    Text="<img src='stacks_image_91.png' width='25px' class='center' />Password Harus Diisi" />
                    </td>
            </tr>
            <tr>
                <td class="auto-style1">Confirm Password :</td>
                <td class="auto-style3">
                    <asp:TextBox ID="txtConfirm" runat="server" Width="165px" Height="30px"></asp:TextBox>
                </td>
                <td class="auto-style4">&nbsp;<asp:CompareValidator ID="cvPass" runat="server" ControlToCompare="txtConfirm" ControlToValidate="txtPass" ErrorMessage="&lt;img src='stacks_image_91.png' width='25px' /&gt;&lt;font color=red /&gt; Password dan Confirm harus sama"></asp:CompareValidator>
                    </td>
            </tr>
        </table>
        <br />
        <asp:Button ID="KIRIM" runat="server" Text="Daftar" Height="36px" Width="145px" PostBackUrl="~/Tugas/Valid_Form_Result.aspx" />
    </form>
</body>
</html>
setelah itu buat file css nya untuk mempercantik :
body {
    text-align: center;
    vertical-align: central;
}
.div {
    margin: 0px auto;
    text-align: left;
    padding: 15px;
    border: 1px dashed #333;
    background-color: #ffd800;
}
table {
    color: #333;
    font-family: Arial;
    width: 510px;
    border-collapse: collapse;
    border-spacing: 0;
    margin-right: 49px;
    text-align: left;
}
td, th {
    border: 1px solid #ccc;
    height: 30px;
    transition: all 0.3s;
}
th {
    background: #f3f3f3;
    font-weight: bold;
    text-align: center;
}
td {
    background: #FAFAFA;
    vertical-align: central;
}
.td {
    text-align: center;
}
tr td:hover {
    background: #666;
    color: #fff;
}
TEXTAREA, INPUT[type="text"] {
    font-family: Tahoma;
    font-size: 14px;
    color: #808080;
    padding: 3px;
    background: #EEEfff;
    border-left: solid 1px #c1c1c1;
    border-top: solid 1px #cfcfcf;
    border-right: solid 1px #cfcfcf;
    border-bottom: solid 1px #6f6f6f;
}
    INPUT[type="text"]:focus, INPUT[type="text"]:active {
        border-color: #646464;
        background-color: #16bec4;
    }
.rfv {
    color: red;
}
    .rfv:hover {
        color: white;
    }
.center {
    vertical-align: top;
maka hasilnya :

Praktikum PHP 6


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>
    &nbsp;Laki-Laki<input type="radio" name="gender" value="<?php echo isset($_POST['gender']) ? $_POST['gender'] : ''; ?>Laki - Laki<?php echo isset($_POST['gender']) ? ' checked' : ''; ?>"/>
     
            &nbsp;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)">&nbsp;Reset&nbsp;</button>&nbsp;<button type="Submit" name="submit" >&nbsp;Kirim&nbsp;</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
 

Blogroll

About

Masukan alamat Email kamu disini untuk mendapatkan artikel terbaru..!