php之form表单
<!DOCTYPE HTML>
<html>
<head>
<title>form</title>
<style type="text/css">
.err{
color: red;
}
</style>
</head>
<body>
<?php
$name = $email = $website = $commet = $gender = $nameErr = $emailErr = $genderErr = '';
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(empty($_POST['name'])){
$nameErr = "姓名为必填项";
}else{
$name = test_input($_POST['name']);
if(!preg_match("/^[a-zA-Z ]*$/" , $name)){
$nameErr = "姓名只允许字母和空格";
}
} if(empty($_POST['email'])){
$emailErr = "邮件为必填项";
}else{
$email = test_input($_POST['email']);
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/" , $email)){
$emailErr = "邮件格式不正确";
}
} if(empty($_POST['gender'])){
$genderErr = "性别为必选项";
}else{
$gender = test_input($_POST['gender']);
} $website = empty($_POST['website'])?'':test_input($_POST['website']);
$commet = empty($_POST['commet'])?'':test_input($_POST['commet']);
} function test_input($str){
$str = trim($str);
$str = stripslashes($str);
$str = htmlspecialchars($str);
return $str;
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<p>姓名:<input type="text" name="name" value="<?php echo $name;?>"/><span class="err">* <?php echo $nameErr; ?> </span></p>
<p>邮件:<input type="text" name="email" value="<?php echo $email;?>" /><span class="err">* <?php echo $emailErr; ?></span></p>
<p>网址:<input type="text" name="website" value="<?php echo $website;?>"/></p>
<p>评论:<textarea name="commet" id="" cols="30" rows="10"><?php echo $commet;?></textarea></p>
<p>性别
<label><input type="radio" name="gender" value="female" <?php if(isset($gender) && $gender=="female") echo 'checked'; ?>/>女性</label>
<label><input type="radio" name="gender" value="male" <?php if(isset($gender) && $gender == 'male') echo 'checked'?>/>男性</label>
<span class="err">* <?php echo $genderErr; ?></span>
</p>
<button>提交</button>
</form>
<hr />
<?php echo $name;?>
<br />
<?php echo $email;?>
<br />
<?php echo $website;?>
<br />
<?php echo $commet;?>
<br />
<?php echo $gender;?>
</body>
</html>
<?php ?>
php之form表单的更多相关文章
- form表单验证-Javascript
Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...
- Form 表单提交参数
今天因为要额外提交参数数组性的参数给form传到后台而苦恼了半天,结果发现,只需要在form表单对应的字段html空间中定义name = 后台参数名 的属性就ok了. 后台本来是只有模型参数的,但是后 ...
- form表单 ----在路上(15)
form 表单就是将用户的信息提交到服务器,服务器会将信息存储活着根据信息查询数据进行增删改查,再将其返回给用户. 基本格式: <form action="" method ...
- form表单的字符串进行utf-8编码
<form>表单有assept-charset属性.该属性规定字符的编码方式,默认是"unknown",与文档的字符集相同. 该属性除了Internet explore ...
- 细说 Form (表单)
细说 Form (表单) Form(表单)对于每个WEB开发人员来说,应该是再熟悉不过的东西了,可它却是页面与WEB服务器交互过程中最重要的信息来源. 虽然Asp.net WebForms框架为了帮助 ...
- 通过form表单的形式下载文件。
在项目中遇到问题,要求动态拼接uri下载文件.但是由于项目的安全拦截导致window.location.href 和 window.open等新建窗口的方法都不行. 无意间百度到了通过form表单来下 ...
- form 表单跨域提交
<!DOCTYPE html><html> <head> <title>form 表单上传文件</title> <script src ...
- form表单的属性标签
form表单的常用标签 表单: <form id="" name="" method="post/get" action=" ...
- form表单的属性标签和练习
form表单的标签 做一个如下图的form表单: 我们的代码如下: <body leftmargin="400px" topmargin="200px"& ...
- Django基础,Day5 - form表单投票详解
投票URL polls/urls.py: # ex: /polls/5/vote/ url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, ...
随机推荐
- 归并排序 空间复杂度为O(1)的做法
#include <iostream> #include <cstdlib> using namespace std; void print(int *arr, int sta ...
- PHP学习——数据类型
PHP的数据是存在类型的概念的,弱类型指的是变量可以存储任何类型!一共8种,分别是:整型.浮点型.布尔型.字符串(标量类型) 数组.对象(符合类型) null.资源(特殊类型) 分成三大类: 标量类型 ...
- 越狱Season 1-Episode 21: Go
Season 1, Episode 21: Go -Michael: I need you to let me get us out of here. 我需要你帮我出去 -Patoshik: If y ...
- makefile基础实例讲解 分类: C/C++ 2015-03-16 10:11 66人阅读 评论(0) 收藏
一.makefile简介 定义:makefile定义了软件开发过程中,项目工程编译链.接接的方法和规则. 产生:由IDE自动生成或者开发者手动书写. 作用:Unix(MAC OS.Solars)和Li ...
- 【转】iOS10项目打包上传被拒关于隐私权限问题
原文网址:http://blog.csdn.net/yidu_blog/article/details/53064987 今天项目打包提交.收到了苹果的邮件.主要内容: This app attemp ...
- Optimize Managed Code For Multi-Core Machines
Parallel Performance Optimize Managed Code For Multi-Core Machines Daan Leijen and Judd Hall This ar ...
- ES
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-service-win.html https://www.e ...
- NGUI Font
---------------------------------------------------------------------------------------------------- ...
- Choosing proper innodb_log_file_size
If you’re doing significant amount of writes to Innodb tables decent size of innodb_log_file_size is ...
- Python列表操作——模拟实现栈和队列
1.实现栈: stack=[] def pushit(): stack.append(raw_input('Enter New String:').strip()) def popit(): if l ...