 |
|
|  |
|
 |
14년 전 |
[PHP 폼(form)값의 유효성 체크]
클라이언트(자바스크립트)단이 아닌 서버단(PHP)에서 폼값을 체크하는 가장 짧은 예제입니다.
<!--넘기는 페이지 form.html ---->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>www.webmadang.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<style type="text/css">
<!--
td { font-family: "굴림"; font-size: 9pt }
-->
</style>
</head>
<body>
<form method="POST" action="form_validation.php">
<table width="393" border="0">
<tr>
<td width="72"> 이름</td>
<td width="311"> <input name="name" type="text" size="20"></td>
</tr>
<tr>
<td> 주소</td>
<td> <input name="addr" type="text" size="40"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="전송">
</div></td>
</tr>
</table>
</body>
</html>
<?
//받는 페이지 form_validation.php
function alert($msg)
{
echo"<script type='text/javascript'>alert('$msg');history.go(-1);</script>";
}
if (empty($_POST[name])){
$name = NULL;
alert("이름을 입력하여 주세요!");
}
if (empty($_POST[addr])){
$addr = NULL;
alert("주소를 입력하여 주세요!");
}
echo "입력완료";
?>
|
|
추천 : 303 |
추천
목록
|
|
|  |
|