表格验证(重新审核) [英] Form Validation (revisited)

查看:73
本文介绍了表格验证(重新审核)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢Yang(这是你的名字吗?)和Andy的建议。


我99%的路在那里,但现在无法得到重置按钮工作。


我已经包含了我的整个代码,并且如果有人

可以解释我哪里出错了,我将不胜感激。


TIA


Roger


<?php

$ message =" ;" ;;

if(isset($ HTTP_POST_VARS [''submit'']))

{


$ re =

" ^ [_ a-z0-9 - ] +(\。[_ a-z0-9 - ] +)* @ [a-z0-9 - ] +(\。 [A-Z0-9 - ] +)*(\([AZ]){2,3})$" ;


if(eregi($ re,$ HTTP_POST_VARS [''emailAddress''])){

$ a = true;

$ message ="< font color = \" green\">< b> Hooray - 您输入的电子邮件地址

有效!< / b> ;< / font>" ;;

} else {

$ a = false;

$ message ="< font color = \" red \">< b>它糟透了! - 您输入的电子邮件地址

无效。请再试一次!< / b>< / font>" ;;

}

}其他{

$ HTTP_POST_VARS ['' emailAddress''] =" Enter Here";

$ HTTP_POST_VARS [''submit''] = false;

}

?> ;

<?xml version =" 1.0" encoding =" iso-8859-1"?>

<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.1 // EN"

http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

< html xmlns =" http://www.w3.org/1999 / xhtml">

<! - 创建日期:05/02/2004 - >

< head>

< meta http-equiv =" Content-Type"含量=" text / html的;字符集= ISO-8859-1" />

< title>< / title>

< meta name =" description"含量="" />

< meta name =" keywords"含量="" />

< meta name =" author" content ="犯罪学研究所" />

< meta name =" generator" content =" AceHTML 5 Pro" />

< / head>

< body>


<?php if($ message){

打印(" $ message< br /> \ n");

}其他{

打印(<< ;字体颜色= \" red \">< b>您没有输入任何内容。请再次尝试

!< / b>< / font>< ; br />");

}

?>


< form name =" myForm"行动= QUOT; email.php" method =" post">

< table cellpadding =" 5"边界=" 1 QUOT; class =" text-align:center">

< tr>

< td>输入您的电子邮件地址< / td>

< td>< input type =" text"名称= QUOT; EMAILADDRESS" value ="<?php echo

$ HTTP_POST_VARS [''emailAddress'']?>">< / td>

< / tr> ;

< tr>

< td colspan =" 2" align =" center">

< input type =" submit"命名= [提交" value =" SUBMIT">

& nbsp;

< input type =" reset"命名= QUOT;重置" value =" RESET">

< / td>

< / tr>

< / table>

< / form>

< / body>

< / html>

解决方案

message ="" ;;

if(isset(


HTTP_POST_VARS [''submit'']))

{


re =

" ^ [_ a-z0-9 - ] +(\ 。[_ A-Z0-9 - ] +)* @ [A-Z0-9 - ] +(\ [A-Z0-9 - ]。。+)*(\([AZ]){2,3 })

Thank you to Yang (Is that your first name?) and Andy for your suggestions.

I am 99% of the way there but now cannot get the "Reset" button to work.

I have included the whole of my code and would appreciate it if someone
could explain where I am going wrong.

TIA

Roger

<?php
$message="";
if (isset($HTTP_POST_VARS[''submit'']))
{

$re =
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,3})$" ;

if (eregi($re,$HTTP_POST_VARS[''emailAddress''])){
$a = true;
$message = "<font color=\"green\"><b>Hooray - The email address you entered
was valid!</b></font>";
}else{
$a = false;
$message = "<font color=\"red\"><b>It Sucks! - The email address you entered
was NOT valid. Please try again!</b></font>";
}
}else{
$HTTP_POST_VARS[''emailAddress'']="Enter Here";
$HTTP_POST_VARS[''submit'']= false;
}
?>
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Creation date: 05/02/2004 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Institute of Criminology" />
<meta name="generator" content="AceHTML 5 Pro" />
</head>
<body>

<?php if($message){
print ("$message <br />\n");
}else{
print("<font color=\"red\"><b>You didn''t enter anything. Please try
again!</b></font><br />");
}
?>

<form name="myForm" action="email.php" method="post">
<table cellpadding="5" border="1" class="text-align: center">
<tr>
<td>Enter your email address</td>
<td><input type="text" name="emailAddress" value="<?php echo
$HTTP_POST_VARS[''emailAddress'']?>"></td>
</tr>
<tr>
<td colspan="2" align = "center">
<input type="submit" name="submit" value="SUBMIT">
&nbsp;
<input type="reset" name="reset" value="RESET">
</td>
</tr>
</table>
</form>
</body>
</html>

解决方案

message="";
if (isset(


HTTP_POST_VARS[''submit'']))
{


re =
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,3})


这篇关于表格验证(重新审核)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆