我对PHP很新,并且在发布验证数据(表单)时遇到了一些麻烦
不断弹出的错误
(对不起,但是您提交的表单中发现了错误。这些错误显示在下方
您输入的名称似乎无效
您输入的电子邮件似乎无效
您输入的电话号码似乎无效
您输入的主席名称似乎无效
您输入的主席电子邮件似乎无效
您输入的受托人数似乎无效
您输入的学生人数似乎无效
请返回并修正这些错误。)
如果你想看看自己http://wwsta.org.nz/Membership%20Application%20Full%20Board.html
PHP代码......
<?php
if(isset($_POST['email'])) {
$email_to = "me@myemail.com";
$email_subject = "Membership Application";
}
function died($error) {
echo " sorry, but there were error(s) found with the form you submitted. " ;
echo "these errors appear below.<br /><br />";
echo $error. "<br /><br />";
echo "please go back and fix these errors. <br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Phone_Number']) ||
!isset($_POST['Chairpersons_Name']) ||
!isset($_POST['Chairpersons_Email']) ||
!isset($_POST['Number_of_Trustees']) ||
!isset($_POST['Number_of_students'])) {
died ('we are sorry, but these appears to be a problem with the form you submitted.');
}
$Name = $_POST['Name']; //required
$Email = $_POST['Email']; //required
$Phone_Number = $_POST['Phone_Number']; //required
$Chairpersons_Name = $_POST['Chairpersons_Name']; //required
$Chairpersons_Email = $_POST['Chairpersons_Email']; //required
$Number_of_Trustees = $_POST['Number_of_Trustees']; //required
$Number_of_students = $_POST['Number_of_students']; //required
$error_message ="";
$Name_exp = "^[a-z .'-]=$";
if(!eregi($Name_exp,$Name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';
}
$Email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+/.[A-Z]{2,4}$";
if(!eregi($Email_exp,$Email)) {
$error_message .= 'The Email you entered does not appear to be valid.<br />';
}
$Phonenumber_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+/.[A-Z]{2,4}$";
if(!eregi($Phonenumber_exp,$Phone_Number)) {
$error_message .= 'The Phone Number you entered does not appear to be valid.<br />';
}
$ChairpersonsName_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+/.[A-Z]{2,4}$";
if(!eregi($ChairpersonsName_exp,$Chairpersons_Name)) {
$error_message .= 'The Chairpersons name you entered does not appear to be valid.<br />';
}
$ChairpersonsEmail_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+/.[A-Z]{2,4}$";
if(!eregi($ChairpersonsEmail_exp,$Chairpersons_Email)) {
$error_message .= 'The Chairpersons Email you entered does not appear to be valid.<br />';
}
$Numberoftrustees_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+/.[A-Z]{2,4}$";
if(!eregi($Numberoftrustees_exp,$Number_of_Trustees)) {
$error_message .= 'The Number of trustees you entered does not appear to be valid.<br />';
}
$Numberofstudents_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+/.[A-Z]{2,4}$";
if(!eregi($Numberofstudents_exp,$Number_of_students)) {
$error_message .= 'The Number of students you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below./n/n";
function clean_string($string) {
$bad = array("content-type","bcc;","to;","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .="Name: ".clean_string ($Name)."/n";
$email_message .="Email: ".clean_string ($Email)."/n";
$email_message .="Phone_Number: ".clean_string ($Phone_Number)."/n";
$email_message .="Chairpersons_Name: ".clean_string ($Chairpersons_Name)."/n";
$email_message .="Chairpersons_Email: ".clean_string ($Chairpersons_Email)."/n";
$email_message .="Number_of_Trustees: ".clean_string ($Number_of_Trustees)."/n";
$email_message .="Number_of_students: ".clean_string ($Number_of_students)."/n";
//create email headers
$Headers = 'from: '.$email_from."/r/n".
'Reply-To: '.$email."/r/n".
'X-mailer: PHP/' . phpversion();
@mail ($email_to, $email_subject, $email_message, $headers);
?>
我要发布的表格
<form action="mailscript.php" method="post">
<table border="1">
<tr>
<td>Name of School</td>
<td width="204"><input type="text" width="200" Name="Name" value="name of school"/> </td>
</tr>
<tr>
<td>Email</td>
<td width="200"><input type="text" Name="Email" /> </td>
</tr>
<tr>
<td>Phone Number</td>
<td width="200"><input type="text" Name="Phone_Number" /> </td>
</tr>
<tr>
<td width="0"> </td>
</tr>
<tr>
<td>Chairpersons Name</td>
<td width="200"><input type="text" Name="Chairpersons_Name" /> </td>
</tr>
<tr>
<td>Chair persons Email</td>
<td width="200"><input type="text" Name="Chairpersons_Email" /> </td>
</tr>
<tr>
<td>Number of Trustees on your board</td>
<td width="200"><input type="text" Name="Number_of_Trustees" /> </td>
</tr>
<tr>
<td>Number of Students</td>
<td width="200"><input type="text" Name="Number_of_students" /> </td>
</tr>
</table>
<br /><br />
<TABLE width="71">
<TR>
<TD><input type="submit" name="submit" value="Submit" /></TD>
</TR>
</TABLE>
</form>
答案 0 :(得分:1)
您需要修复所有正则表达式类。如果要在类中允许文字-
,则它必须是[
之后的第一个字符。否则,它被视为字符范围中的分隔符。例如,
$Name_exp = "^[a-z .'-]=$";
应该是:
$Name_exp = "^[-a-z .']=$";
此外,此正则表达式仅允许使用2个字符的名称,第二个名称必须为=
。我怀疑这是+
的拼写错误,所以它应该是:
$Name_exp = "^[-a-z .']+$";
你所有的其他正则表都存在类似的问题,我不打算通过所有这些问题并为你修复它们。