PHP表单form问题

WBOY
Release: 2016-06-23 13:26:30
Original
931 people have browsed it

脚本

function formone(){var name=jQuery("#name").val();var url=jQuery("#url").val();var tel=jQuery("#tel").val();var telreg=/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;var zw=/^[\u4e00-\u9fa5]/;var ask=jQuery("#ask").val();var des=jQuery("#des").val();if(name==""){alert("请输入您的姓名!");jQuery("#name").focus();return false;}else if(!zw.test(name)){alert("请输入正确的姓名!");jQuery("#name").focus();return false;}else if(tel==""){alert("请输入您的联系电话!");jQuery("#tel").focus();return false;}else if(!telreg.test(tel)){alert("请输入正确的联系电话!");jQuery("#tel").focus();return false;}else if(ask==""){alert("请输入您的问题!");jQuery("#ask").focus();return false;}else if(!zw.test(ask)){alert("请输入正确的问题!");jQuery("#ask").focus();return false;}else if(des==""){alert("请输入您的问题描述!");jQuery("#des").focus();return false;}else if(!zw.test(des)){alert("请输入正确的问题描述!");jQuery("#des").focus();return false;}else{jQuery.ajax({url:'submit.php',data:{name:jQuery("#name").val(),tel:jQuery("#tel").val(),ask:jQuery("#ask").val(),des:jQuery("#des").val(),url:jQuery("#url").val()},type:'post',dataType:'text',success:function(msg){if(parseInt(msg)!=0){alert("您的问题提交成功,正在审核中...");jQuery("#name").val("");jQuery("#tel").val("");jQuery("#ask").val("");jQuery("#des").val("");}else{alert("您的问题提交失败,请直接在线咨询或者拨打400-600-4936官方电话!");}}})}}
Copy after login

PHP代码
<?php/** * @处理表单提交数据*/define('INCLUDE_CHECK',1);require_once('connect.php');$name=stripslashes($_POST['name']);$tel=stripslashes($_POST['tel']);$ask=stripslashes($_POST['ask']);$des=stripslashes($_POST['des']);$time=date('Y年m月d日H时i分s秒',time());$url=stripslashes($_POST['url']);if(isset($_POST['name']) && !empty($_POST['name'])){$query=mysql_query("insert into say(name,tel,ask,des,time,url)values('$name','$tel','$ask','$des','$time','$url')");}?>
Copy after login

请问怎样将脚本的验证写入到PHP中去验证字段


回复讨论(解决方案)

将脚本的验证写入到PHP中去验证字段,意思是让JS的验证变成在submit.php里验证?

将脚本的验证写入到PHP中去验证字段,意思是让JS的验证变成在submit.php里验证?


是的 这个能实现么

你用的ajax 本来就是丢到php里进行了操作了

$name = stripslashes($_POST['name']);$tel = stripslashes($_POST['tel']);$ask = stripslashes($_POST['ask']);$des = stripslashes($_POST['des']);$time = date('Y年m月d日H时i分s秒',time());$url = stripslashes($_POST['url']);$telreg='/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/';$zw='/^[\u4e00-\u9fa5]/';if($_POST){	if(empty($name)){		echo 1;	}elseif(!preg_match($zw, $name)){		echo 2;	}elseif(empty($tel)){		echo 3;	}elseif(!preg_match($telreg, $tel)){		echo 4;	}elseif(empty($ask)){		echo 5;	}elseif(!preg_match($zw, $ask)){		echo 6;	}elseif(empty($des)){		echo 7;	}elseif(!preg_match($zw, $des)){		echo 8;	}else{		echo 9;	}}else{	echo 0;}
Copy after login


    success:function(msg){        switch(msg){            case 1:                alert('请输入您的姓名!');break;            case 2:                alert('请输入正确的姓名!');break;            case 3:                alert('请输入您的联系电话');break;            case 4:                alert('请输入正确的联系电话!');break;            case 5:                alert('请输入您的问题!');break;            case 6:                alert('请输入正确的问题!');break;            case 7:                alert('请输入您的问题描述');break;            case 8:                alert('请输入正确的问题描述!');break;            case 9:                alert('您的问题提交成功,正在审核中...');break;            case 0:                alert('您的问题提交失败,请直接在线咨询或者拨打400-600-4936官方电话!');        }    }
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template