Validasi form

_FB_NAME_ · Sep 23, 2012
Master, ane mau nanya nich, ane dah nyoba validasi form yg user friendly sesuai dengan tutorial yg dikasih master ellyx tp k nda muncul pesan tanda merah pada form yang harus di isi dan data yang benar juga ikut ilang...
mohon bantuan nya master,,,
<?php 
session_start();

if (session_is_registered('id_admin'))
{
?>
<script type="text/javascript" src="jquery.js"></script>
	<script>
	function suggest(inputString){
		if(inputString.length == 0) {
			$('#suggestions').fadeOut();
		} else {
		$('#country').addClass('load');
			$.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').fadeIn();
					$('#suggestionsList').html(data);
					$('#country').removeClass('load');
				}
			});
		}
	}
	
	function fill(thisValue) {
		$('#country').val(thisValue);
		setTimeout("$('#suggestions').fadeOut();", 100);
	}
	
	function fill2(thisValue) {
		$('#kode').val(thisValue);
		setTimeout("$('#suggestions').fadeOut();", 100);
	}
	</script>
	
	<style>
	#result {
		height:20px;
		font-size:12px;
		font-family:Arial, Helvetica, sans-serif;
		color:#333;
		padding:5px;
		margin-bottom:10px;
		background-color:#FFFF99;
	}
	#country{
		padding:3px;
		border:1px #CCC solid;
		font-size:12px;
	}
	.suggestionsBox {
		position: absolute;
		left: 0px;
		top:40px;
		margin: 26px 0px 0px 0px;
		width: 200px;
		padding:0px;
		background-color:#999999;
		border-top: 3px solid #999999;
		color: #fff;
	}
	.suggestionList {
		margin: 0px;
		padding: 0px;
	}
	.suggestionList ul li {
		list-style:none;
		margin: 0px;
		padding: 6px;
		border-bottom:1px dotted #666;
		cursor: pointer;
	}
	.suggestionList ul li:hover {
		background-color: #FC3;
		color:#000;
	}
	ul {
		font-family:Arial, Helvetica, sans-serif;
		font-size:11px;
		color:#FFF;
		padding:0;
		margin:0;
	}
	
	.load{
	background-image:url(loader.gif);
	background-position:right;
	background-repeat:no-repeat;
	}
	
	#suggest {
		position:relative;
	}
	</style>

	<body onLoad="document.form.elements['notel'].focus();">
	<div class="post">
		<div class="entry">
			<h2 align="center"><strong>Input Data PSB</strong></h2>
			<p align="center">&nbsp;</p>
			<p>
			<form action="?<?php echo paramEncrypt('page=./setup/psb2')?>" method="post" name="form">
			<table>
			<tr>
				<td>No Telefon</td><td><input type="text" name="notel" size="15" value="<?php echo isset($_POST['notel']) ? $_POST['notel'] : '';?>"/> 

<div style="color:red"><?php echo isset($error['notel']) ? $error['notel'] : '';?></div></td>
			</tr>
				<tr>
				<td>Nama Pelanggan</td><td><input type="text" name="nama" size="30" value="<?php echo isset($_POST['nama']) ? $_POST['nama'] : '';?>"/> 

<div style="color:red"><?php echo isset($error['nama']) ? $error['nama'] : '';?></div>  </td>
			</tr>
				
			<tr>
				<td>Alamat</td><td><input type="text" name="alamat" size="55" value="<?php echo isset($_POST['alamat']) ? $_POST['alamat'] : '';?>"/> 

<div style="color:red"><?php echo isset($error['alamat']) ? $error['alamat'] : '';?></div></td>
			</tr>
			
			<tr>
				<td>id</td><td><input type="text" name="id" size="35"/></td>
			</tr>
			
			<tr>
				<td>state</td><td><input type="text" name="state" size="25" value="Jawa Tengah" readonly="readonly"/></td>
			</tr>
			<tr>
				<td>city</td><td><input type="text" name="city" size="35" value="Tegal" readonly="readonly"/></td>
			</tr>
			<tr>
				<td>No HP</td><td><input type="text" name="hp" size="25"/></td>
			</tr>
			<tr>
				<td>Tanggal Akhir ID</td><td><input type="text" name="tgl_akhir" size="25"/></td>
			</tr>

			<tr> 
				<td>info dari :</td><td><select name='sales'>
<option value='....'>pilih kebawah</option>
<option value='plasa'>plasa Telkom</option>
<option value='iklan'>iklan tv / koran</option>
<option value='147'>telkom 147</option>
<option value='sofyan'>sofyan</option>
<option value='darmo'>darmo</option>
<option value='christofer'>christofer</option>
<option value='heri'>heri</option>
</select>
</td></tr>
			<tr> 
				<td>Paket :</td><td><select name='paket'>
<option value='....'>pilih kebawah</option>
<option value='mail'>mail</option>
<option value='chat'>Chat</option>
<option value='socialia'>Socialia</option>
<option value='Load'>Load</option>
<option value='family'>Family</option>
<option value='Executive'>Executive</option>
<option value='biz'>Biz</option>
</select>
</td></tr>
<tr>
				<td>Keterangan</td><td><input type="text" name="keterangan" size="25"/></td>
			</tr>

			<tr>
                  <td>Tanggal</td>
                  <td colspan="2"><input type="text" name="tanggal_transaksi" size="15" value="<?php if(empty($_POST['tanggal_transaksi'])){ echo $tanggal;}else{ echo 

$_POST['tanggal_transaksi']; }?>"/>
					<a href="javascript:void(0)" onClick="if(self.gfPop)gfPop.fPopCalendar(document.postform.tanggal_transaksi);return false;" 

><img src="calender/calender.jpeg" alt="" name="popcal" width="34" height="29" border="0" align="absmiddle" id="popcal" /></a>				
				</td>
                </tr>
			<tr>
				<td><input type="submit" value="Simpan" /></td>
			</tr>
			</table>
			</form>
			
			<br />
			<!---MENAMPILKAN TABEL PERKIRAAN--->
			<a href="./laporan~pdf/psb~pdf.php" target="_blank" title=" Tampilkan dalam file pdf">
			<img src="images/pdf-icon.jpeg" border="0"/>
			</a>
			<table class="datatable">
			<tr>
				<th>No Telefon</th><th>Nama Pelanggan</th><th>Alamat</th><th>Tanggal Transaksi</th>
			</tr>
			<?php
	
			$query=mysql_query("select * from data order by tanggal_transaksi asc");
			while($row=mysql_fetch_array($query)){
				
				?>
				<tr>
					<td align="center"><?php echo $row['notel'];?></td><td><?php echo $row['nama'];?></td>
					<td align="right"><?php echo $row['alamat'];?></td><td><?php echo $row['tanggal_transaksi'];?></td>
					
				</tr>
				<?php
				
			}
			?>
			
			</table>
			
			
			</p>
		</div>
	</div>
	</body>
	
	
	<?php
	if($_POST){ 
	
		$notel=$_POST['notel'];
		$nama=ucwords($_POST['nama']);
		$alamat=$_POST['alamat'];
		$id=$_POST['id'];
		$city=$_POST['city'];
		$state=$_POST['state'];
		$hp=$_POST['hp'];
		$tgl_akhir=$_POST['tgl_akhir'];
		$sales=$_POST['sales'];
		$paket=$_POST['paket'];
		$keterangan=$_POST['keterangan'];
		$tanggal_transaksi=$_POST['tanggal_transaksi'];
		$error = array();  
		 if(empty($nama)){  
      $error['nama'] = 'Nama tidak boleh kosong';  
        }  
    if(empty($notel)){  
      $error['notel'] = 'Email tidak boleh kosong';  
    }  
    if(empty($alamat)){  
      $error['alamat'] = 'Alamat tidak boleh kosong';  
    }  
    
     if(empty($error)){$query=mysql_query("insert into data (notel,nama,alamat,id,city,state,hp,tgl_akhir,sales,paket,keterangan,tanggal_transaksi) 
							values

('$notel','$nama','$alamat','$id','$city','$state','$hp','$tgl_akhir','$sales','$paket','$keterangan','$tanggal_transaksi')");
							}
		
		if($query){
			?><script language="javascript">document.location.href="?<?php echo paramEncrypt('page=./setup/psb2')?>"</script><?php
		}else{
			echo mysql_error();
		}
	
	}else{
		unset($_POST['notel']);
	}
	?>
	
<?php 
}else{
	echo "Forbidden Access!";
}
?>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Sep 30, 2012 · 0 Suka · 0 Tidak Suka
kamu menulis kodenya terbalik, tidak sesuai dengan tutorial yang sudah saya kasi
<?php 
session_start();
 
if (session_is_registered('id_admin'))
{
?>
<?php
	if($_POST){ 
 
		$notel=$_POST['notel'];
		$nama=ucwords($_POST['nama']);
		$alamat=$_POST['alamat'];
		$id=$_POST['id'];
		$city=$_POST['city'];
		$state=$_POST['state'];
		$hp=$_POST['hp'];
		$tgl_akhir=$_POST['tgl_akhir'];
		$sales=$_POST['sales'];
		$paket=$_POST['paket'];
		$keterangan=$_POST['keterangan'];
		$tanggal_transaksi=$_POST['tanggal_transaksi'];
		$error = array();  
		 if(empty($nama)){  
      $error['nama'] = 'Nama tidak boleh kosong';  
        }  
    if(empty($notel)){  
      $error['notel'] = 'Email tidak boleh kosong';  
    }  
    if(empty($alamat)){  
      $error['alamat'] = 'Alamat tidak boleh kosong';  
    }  
 
     if(empty($error)){$query=mysql_query("insert into data (notel,nama,alamat,id,city,state,hp,tgl_akhir,sales,paket,keterangan,tanggal_transaksi) 
							values
 
('$notel','$nama','$alamat','$id','$city','$state','$hp','$tgl_akhir','$sales','$paket','$keterangan','$tanggal_transaksi')");
							}
 
		if($query){
			?><script language="javascript">document.location.href="?<?php echo paramEncrypt('page=./setup/psb2')?>"</script><?php
		}else{
			echo mysql_error();
		}
 
	}else{
		unset($_POST['notel']);
	}
	?>
<script type="text/javascript" src="jquery.js"></script>
	<script>
	function suggest(inputString){
		if(inputString.length == 0) {
			$('#suggestions').fadeOut();
		} else {
		$('#country').addClass('load');
			$.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').fadeIn();
					$('#suggestionsList').html(data);
					$('#country').removeClass('load');
				}
			});
		}
	}
 
	function fill(thisValue) {
		$('#country').val(thisValue);
		setTimeout("$('#suggestions').fadeOut();", 100);
	}
 
	function fill2(thisValue) {
		$('#kode').val(thisValue);
		setTimeout("$('#suggestions').fadeOut();", 100);
	}
	</script>
 
	<style>
	#result {
		height:20px;
		font-size:12px;
		font-family:Arial, Helvetica, sans-serif;
		color:#333;
		padding:5px;
		margin-bottom:10px;
		background-color:#FFFF99;
	}
	#country{
		padding:3px;
		border:1px #CCC solid;
		font-size:12px;
	}
	.suggestionsBox {
		position: absolute;
		left: 0px;
		top:40px;
		margin: 26px 0px 0px 0px;
		width: 200px;
		padding:0px;
		background-color:#999999;
		border-top: 3px solid #999999;
		color: #fff;
	}
	.suggestionList {
		margin: 0px;
		padding: 0px;
	}
	.suggestionList ul li {
		list-style:none;
		margin: 0px;
		padding: 6px;
		border-bottom:1px dotted #666;
		cursor: pointer;
	}
	.suggestionList ul li:hover {
		background-color: #FC3;
		color:#000;
	}
	ul {
		font-family:Arial, Helvetica, sans-serif;
		font-size:11px;
		color:#FFF;
		padding:0;
		margin:0;
	}
 
	.load{
	background-image:url(loader.gif);
	background-position:right;
	background-repeat:no-repeat;
	}
 
	#suggest {
		position:relative;
	}
	</style>
 
	<body onLoad="document.form.elements['notel'].focus();">
	<div class="post">
		<div class="entry">
			<h2 align="center"><strong>Input Data PSB</strong></h2>
			<p align="center">&nbsp;</p>
			<p>
			<form action="?<?php echo paramEncrypt('page=./setup/psb2')?>" method="post" name="form">
			<table>
			<tr>
				<td>No Telefon</td><td><input type="text" name="notel" size="15" value="<?php echo isset($_POST['notel']) ? $_POST['notel'] : '';?>"/> 
 
<div style="color:red"><?php echo isset($error['notel']) ? $error['notel'] : '';?></div></td>
			</tr>
				<tr>
				<td>Nama Pelanggan</td><td><input type="text" name="nama" size="30" value="<?php echo isset($_POST['nama']) ? $_POST['nama'] : '';?>"/> 
 
<div style="color:red"><?php echo isset($error['nama']) ? $error['nama'] : '';?></div>  </td>
			</tr>
 
			<tr>
				<td>Alamat</td><td><input type="text" name="alamat" size="55" value="<?php echo isset($_POST['alamat']) ? $_POST['alamat'] : '';?>"/> 
 
<div style="color:red"><?php echo isset($error['alamat']) ? $error['alamat'] : '';?></div></td>
			</tr>
 
			<tr>
				<td>id</td><td><input type="text" name="id" size="35"/></td>
			</tr>
 
			<tr>
				<td>state</td><td><input type="text" name="state" size="25" value="Jawa Tengah" readonly="readonly"/></td>
			</tr>
			<tr>
				<td>city</td><td><input type="text" name="city" size="35" value="Tegal" readonly="readonly"/></td>
			</tr>
			<tr>
				<td>No HP</td><td><input type="text" name="hp" size="25"/></td>
			</tr>
			<tr>
				<td>Tanggal Akhir ID</td><td><input type="text" name="tgl_akhir" size="25"/></td>
			</tr>
 
			<tr> 
				<td>info dari :</td><td><select name='sales'>
<option value='....'>pilih kebawah</option>
<option value='plasa'>plasa Telkom</option>
<option value='iklan'>iklan tv / koran</option>
<option value='147'>telkom 147</option>
<option value='sofyan'>sofyan</option>
<option value='darmo'>darmo</option>
<option value='christofer'>christofer</option>
<option value='heri'>heri</option>
</select>
</td></tr>
			<tr> 
				<td>Paket :</td><td><select name='paket'>
<option value='....'>pilih kebawah</option>
<option value='mail'>mail</option>
<option value='chat'>Chat</option>
<option value='socialia'>Socialia</option>
<option value='Load'>Load</option>
<option value='family'>Family</option>
<option value='Executive'>Executive</option>
<option value='biz'>Biz</option>
</select>
</td></tr>
<tr>
				<td>Keterangan</td><td><input type="text" name="keterangan" size="25"/></td>
			</tr>
 
			<tr>
                  <td>Tanggal</td>
                  <td colspan="2"><input type="text" name="tanggal_transaksi" size="15" value="<?php if(empty($_POST['tanggal_transaksi'])){ echo $tanggal;}else{ echo 
 
$_POST['tanggal_transaksi']; }?>"/>
					<a href="javascript:void(0)" onClick="if(self.gfPop)gfPop.fPopCalendar(document.postform.tanggal_transaksi);return false;" 
 
><img src="calender/calender.jpeg" alt="" name="popcal" width="34" height="29" border="0" align="absmiddle" id="popcal" /></a>				
				</td>
                </tr>
			<tr>
				<td><input type="submit" value="Simpan" /></td>
			</tr>
			</table>
			</form>
 
			<br />
			<!---MENAMPILKAN TABEL PERKIRAAN--->
			<a href="./laporan~pdf/psb~pdf.php" target="_blank" title=" Tampilkan dalam file pdf">
			<img src="images/pdf-icon.jpeg" border="0"/>
			</a>
			<table class="datatable">
			<tr>
				<th>No Telefon</th><th>Nama Pelanggan</th><th>Alamat</th><th>Tanggal Transaksi</th>
			</tr>
			<?php
 
			$query=mysql_query("select * from data order by tanggal_transaksi asc");
			while($row=mysql_fetch_array($query)){
 
				?>
				<tr>
					<td align="center"><?php echo $row['notel'];?></td><td><?php echo $row['nama'];?></td>
					<td align="right"><?php echo $row['alamat'];?></td><td><?php echo $row['tanggal_transaksi'];?></td>
 
				</tr>
				<?php
 
			}
			?>
 
			</table>
 
 
			</p>
		</div>
	</div>
	</body>
 
<?php 
}else{
	echo "Forbidden Access!";
}