php表单提交判断
㈠ php如何判断 是否有表单提交事件
一楼没有废话. 大概的意思也就是那样的.
$action = isset($_REQUEST['action']) ? $_REQUEST['action']:'' ;
switch ($action){
case 'login':
$username = isset($_POST['username']) ? $_POST['username'] : '' ;
$password = isset($_POST['password']) ? $_POST['password'] : '' ;
if (empty($username) and empty($password)) {
show_message('用户名密码不能为空','');
}
$password = substr(md5($password),8,16);
if (login($username,$password)) {
Session_start();
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
header('Location:manage.php');
}
else {
show_message('用户名密码错误' . $sql . $row_num,'');
}
break;
case 'out':
session_start();
unset($_SESSION['username']);
unset($_SESSION['password']);
header('Location:login.php');
break;
default:
$smarty->assign("webname", Webname); //进行模板变量替换
//编译并显示位于./templates下的index.tpl模板
$smarty->display("admin/login.htm");
}
㈡ PHP表单提交做判断的问题
64行有误,语法错误:
if(form.yzbm.value.length != 6 && form.yzbm.value != ){
另外给你一个我自己做项目经常用的验证方法:
<!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>My Check Form</title>
</head>
<script type="text/javascript">
//主函数
function CheckForm(oForm) {
var err_ele = null;
var ele = oForm.elements;
var haserror = false;
//遍历所有表元素
for(var i=0;i<ele.length;i++) {
//过滤元素类型
if(ele.type != 'submit' && ele.type != 'hidden' && ele.type != 'button') {
//是否需要验证标签
var required = ele[i].getAttribute('required');
if(required!="undefined" && (required==""||required=="true"||required=="yes") ) {
if(!validate(ele[i])) {
if(err_ele==null)
err_ele = ele[i];
haserror = true;
break;
}
}
}
}
//判断是否有没有通过验证的项目
if(haserror) {
err_ele.focus();
return false;
} else {
return true;
}
}
//得到表单元素的值
function getvalue(ele) {
var type = ele.getAttribute('type');
switch(type) {
case 'text':
case 'hidden':
case 'password':
case 'file':
case "select-one":
case 'textarea':
return ele.value;
}
}
//检测函数
function validate(ele) {
//得到设定的检测函数
var fun = ele.getAttribute('fun');
//自定义提示语句
var custommsg = ele.getAttribute('msg');
if(fun!=null) {
var checkarr = executeFunc(fun,ele);
if(checkarr[2] == 'regxp') { //正则表达式处理
if(!regValidate(getvalue(ele),checkarr[0])) {
//如果有自定义提示语句则使用自定义提示语句
if(custommsg) {
alert(custommsg);
} else {
alert(checkarr[1]);
}
return false;
}
} else if(checkarr[2] == 'custom') { //函数自行逻辑处理
//如果验证通过
if(!checkarr[0]) {
//如果有自定义提示语句则使用自定义提示语句
if(custommsg) {
alert(custommsg);
} else {
alert(checkarr[1]);
}
return false;
}
}
}
return true;
}
//运行函数
function executeFunc(name,element) {
//匹配函数是否带有参数
if(name.match(/^[\w]+\([\w,\'\"]+\);?$/)) {
return eval(name.replace(/^([\w]+)\(([\w,\'\"]+)\);?$/,'$1($2,element)'));
} else {
return eval(name.match(/^[\w]+\(\)$/) ? name : name + '(element)');
}
}
//
//判定某个值与表达式是否相符
function regValidate(value,sReg) {
//字符串->正则表达式,不区分大小写
var reg = new RegExp(sReg ,"i");
if(reg.test(value)) {
return true;
} else {
return false;
}
}
//////////////////////////////////验证规则定义///////////////////////////////
// 正则类验证
function UserName() {
var rt = new Array();
rt[0] = '^([a-zA-Z0-9]|[._]){4,19}$';
rt[1] = "用户名必须为4-19个字母和数字组成";
rt[2] = 'regxp';
return rt;
}
function PassWord() {
var rt = new Array();
rt[0] = '^([a-zA-Z0-9]|[._]){6,19}$';
rt[1] = "密码必须为6-19个字母和数字组成";
rt[2] = 'regxp';
return rt;
}
function notBlank(){
var rt = new Array();
rt[0] = "^\\S+$";
rt[1] = "该项不能为空,且不能含有空格!";
rt[2] = 'regxp';
return rt;
}
function required(){
var rt = new Array();
rt[0] = "^\\S";
rt[1] = "该项不能为空!";
rt[2] = 'regxp';
return rt;
}
//判断email
function isEmail() {
var rt = new Array();
rt[0] = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
rt[1] = "该项填写的EMAIL格式不正确!";
rt[2] = 'regxp';
return rt;
}
//只能输入中文
function onlyZh() {
var rt = new Array();
rt[0] = "^[\u0391-\uFFE5]+$";
rt[1] = "该项只能输入中文!";
rt[2] = 'regxp';
return rt;
}
//只可输入英文
function onlyEn() {
var rt = new Array();
rt[0] = "^[A-Za-z]+$";
rt[1] = "该项只能输入英文!";
rt[2] = 'regxp';
return rt;
}
function enOrNum() {
var rt = new Array();
rt[0] = "^[A-Za-z0-9]+$";
rt[1] = "该项只能输入英文和数字,且不能有空格!";
rt[2] = 'regxp';
return rt;
}
function isPhone() {
var rt = new Array();
rt[0] = "^((\\(\\d{2,3}\\))|(\\d{3}\\-))?(\\(0\\d{2,3}\\)|0\\d{2,3}-)?[1-9]\\d{6,7}(\\-\\d{1,4})?$";
rt[1] = "应输入正确的电话号码格式!";
rt[2] = 'regxp';
return rt;
}
// 自定义类验证函数
function isIdCard(ele) {
var rt = new Array();
rt[0] = false;
rt[1] = "应输入正确身份证号!";
rt[2] = 'custom';
var Reg_15 = /^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{2})(\w)$/;
var Reg_18 = /^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/;
var num = ele.value;
var len = num.length;
if (len == 15) {
if (Reg_15.test(num))
rt[0] = true;
}
else if(len == 18) {
if (Reg_18.test(num))
rt[0] = true;
}
return rt;
}
function rePassword(ID,ele) {
var rt = new Array();
rt[0] = false;
rt[1] = "再次密码输入不一致!";
rt[2] = 'custom';
var password = document.getElementById(ID).value;
if(password != '' || ele.value != ''){
if(password == ele.value)
rt[0] = true;
}
return rt;
}
</script>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return CheckForm(this);">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="20%" align="right">用户名:</td>
<td><input type="text" name="username" id="username" required="true" fun="UserName" msg="自定义提示信息:用户名不正确,请重新输入!" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password" id="password" required="true" fun="PassWord" /></td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td><input type="password" name="repassword" id="repassword" required="true" fun="rePassword('password')" /></td>
</tr>
<tr>
<td align="right">电子邮件:</td>
<td><input type="text" name="email" id="email" required="true" fun="isEmail" /></td>
</tr>
<tr>
<td align="right">身份证号:</td>
<td><input type="text" name="idcard" id="idcard" required="true" fun="isIdCard" /></td>
</tr>
<tr>
<td align="right">全中文项:</td>
<td><input type="text" name="chinese" id="chinese" required="true" fun="onlyZh" /></td>
</tr>
<tr>
<td align="right">其它:</td>
<td><input type="text" name="notblank" id="notblank" required="true" fun="notblank" /></td>
</tr>
<tr>
<td align="right"></td>
<td><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>
㈢ PHP如何判断提交的表单中多个复选框是否选中
你name设置成select[],然后提交之后select[]是一个数组,提取里面的值就可以了。
然后在接收数据的页面,你可以打印一下比如var_mp($_POST['select']);
里面的值就是你复选框的value,根据value就可以判断你选中了那些
选择足球排球的输出
㈣ php 提交表单时怎么判断为哪个表单提交
form="post.php?sub=1"
form="post.php?sub=2"
form="post.php?sub=3"
<?php
if($_GET['sub']=='1'){echo"这是第一个表单";}
if($_GET['sub']=='2'){echo"这是第二个表单";}
if($_GET['sub']=='3'){echo"这是第三个表单";}
?>