您好,登錄后才能下訂單哦!
php實現簡單表單代碼
<html>
<head>
<?php
$message_name=$message_email="";
$m_name=$m_email=true;
$name=$email="";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
if(empty($_POST["name"])){
$message_name="姓名是必填的";
$m_name=false;
}else{
$name=text_input($_POST["name"]);
if(!preg_match("/^[0-9a-zA-Z]*$/",$name))
{
$message_name="姓名只能是數字和字母";
$m_name=false;
}
}
if(empty($_POST["name"])){
$message_email="電子郵箱是必填的";
$m_email=false;
}else{
$email=text_input($_POST["email"]);
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
$message_email="電子郵箱格式不正確";
$m_email=false;
}
}
}
function text_input($data){
$data=trim($data);
$data=stripcslashes($data);
$data=htmlspecialchars($data);
return $data;
}
?>
<style type="text/css">
span.dx
{
color:#FF0000;
}
</style>
</head>
<body>
<table align="center" width="800">
<caption> <h2> 注冊 <h2><p> </caption>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<tr>
<td width="150">姓名:</td>
<td width="650">
<input type="text" name="name" value="<?php echo $name;?>">
<span class="dx">* <?php echo $message_name;?></span>
</td>
</tr>
<tr>
<td width="150">電子郵箱:</td>
<td width="650"><input type="text" name="email" value="<?php echo $email;?>">
<span class="dx">* <?php echo $message_email;?></span>
</td>
</tr>
<tr>
<td width="500"><span class="dx">(注意!"*" 表示必須填寫的)</span></p></td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="提交">
</td>
</tr>
<?php
if(isset($_POST["submit"])&&$m_name&&$m_email){
echo '<tr><td>';
echo "姓名:".$name;
echo '</td></tr>';
echo '<tr><td>';
echo "電子郵箱:".$email;
echo '</td></tr>';
}
?>
</form>
</table>
</body>
</html>
附:
<?php
// 模式定界符后面的 "i" 表示不區分大小寫字母的搜索
if (preg_match ("/hi/i", "Welcome to hi-docs.com.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
?>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。