-2

我对 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"/>&nbsp;</td>
</tr>
<tr>
<td>Email</td>
<td width="200"><input type="text" Name="Email" />&nbsp;</td>
</tr>
<tr>
<td>Phone Number</td>
<td width="200"><input type="text" Name="Phone_Number" />&nbsp;</td>
</tr>
<tr>

<td width="0">&nbsp;</td>
</tr>
<tr>
<td>Chairpersons Name</td>
<td width="200"><input type="text" Name="Chairpersons_Name" />&nbsp;</td>
</tr>

<tr>
<td>Chair persons Email</td>
<td width="200"><input type="text" Name="Chairpersons_Email" />&nbsp;</td>
</tr>
<tr>
<td>Number of Trustees on your board</td>
<td width="200"><input type="text" Name="Number_of_Trustees" />&nbsp;</td>
</tr>
<tr>
<td>Number of Students</td>
<td width="200"><input type="text" Name="Number_of_students" />&nbsp;</td>
</tr>
</table>
<br /><br />

<TABLE width="71">
<TR>
<TD><input type="submit" name="submit" value="Submit"  /></TD>
</TR>
</TABLE>
</form>
4

1 回答 1

0

您需要修复所有正则表达式类。如果你想-在一个类中允许一个字面量,它必须是 . 之后的第一个字符[。否则,将其视为字符范围内的分隔符。例如,

$Name_exp = "^[a-z .'-]=$";

应该:

$Name_exp = "^[-a-z .']=$";

此外,这个正则表达式只允许 2 个字符的名称,而第二个必须是=. 我怀疑这是一个错字+,所以应该是:

$Name_exp = "^[-a-z .']+$";

你所有的其他正则表达式也有类似的问题,我不会去解决所有的问题并为你修复它们。

于 2012-10-30T00:19:26.840 回答