私は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>