jquery - การส่งแบบฟอร์ม PHP Ajax โดยไม่ต้องโต้ตอบกับผู้ใช้
ไม่แน่ใจว่ามีใครตอบคำถามนี้ได้บ้าง
ฉันเพิ่งสร้างฟอร์ม PHP Ajax บนเว็บไซต์ของฉันซึ่งตรวจสอบความถูกต้องด้วย jQuery ฟิลด์ทั้งหมดได้รับการตรวจสอบความถูกต้องเพื่อให้ต้องมีเนื้อหาในการส่งแบบฟอร์ม
ด้วยเหตุผลบางประการ ฉันยังคงได้รับอีเมลที่ส่งจากแบบฟอร์ม แต่ไม่มีข้อมูลในแบบฟอร์ม มีใครบ้างที่มีความคิดว่าทำไมสิ่งนี้ถึงเป็นเช่นนั้น? ดูโค้ดและภาพหน้าจอด้านล่าง (ฉันได้ลบโค้ดตรวจสอบความถูกต้องของ jQuery เพื่อประหยัดพื้นที่ แต่ได้ทดสอบแล้วและใช้งานได้) -
---HTML---
<div class="col-md-6">
<div class="thankyou-message">
<p class="hero">THANK YOU!!!</p>
<p>For submitting your registration.</p>
<p>We have received your information and will contact you in due course.</p>
</div>
<div class="registration-form my-5 my-md-0">
<div class="row">
<div class="col-sm-4">
<label for="ageteam">Age group and team</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="age-team" name="testage" required />
<span class="error age-team">Please tell us your age group</span>
</div>
</div>
<div class="row margin-top--20 margin-bottom--16 border-bottom--orange">
<div class="col-12">
PLAYER
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="name">Name</label>
</div>
<div class="col-sm-8">
<input class="w-100" class="w-100" type="text" id="name" name="name" required />
<span class="error name">Please tell us your name</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="address">Address</label>
</div>
<div class="col-sm-8">
<textarea class="w-100" id="address" name="address" rows="4" required></textarea>
<span class="error address">Please tell us your address</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="postcode">Postcode</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="postcode" name="postcode" required />
<span class="error postcode">Please tell us your postcode</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="dob">Date of birth</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="dob" name="dob" required />
<span class="error dob">Please tell us your date of birth</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="school">School</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="school" name="school" required />
<span class="error school">Please tell us the name of your school</span>
</div>
</div>
<div class="row margin-top--20 margin-bottom--16 border-bottom--orange">
<div class="col-12">
PARENT OR GUARDIAN
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="parent-name">Name</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="parent-name" name="parent-name" required />
<span class="error parent-name">Please tell us the name of your parent or guardian</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="parent-address">Address</label>
</div>
<div class="col-sm-8">
<textarea class="w-100" id="parent-address" name="parent-address" rows="4" required></textarea>
<span class="error parent-address">Please tell us your parent or guardians address</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="parent-postcode">Postcode</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="parent-postcode" name="parent-postcode" required />
<span class="error parent-postcode">Please tell us the postcode of your parent or guardian</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="phone">Phone</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="phone" name="phone" required />
<span class="error number">Please tell us your phone number</span>
<span class="error number2">Please enter a valid phone number</span>
</div>
</div>
<div class="row margin-bottom--8">
<div class="col-sm-4">
<label for="email">Email</label>
</div>
<div class="col-sm-8">
<input class="w-100" type="text" id="email" name="testemail" required />
<span class="error email">Please tell us your email address</span>
<span class="error email2">Please enter a valid email address</span>
</div>
</div>
<div class="submit-btn">
Submit registration
</div>
</div>
</div>
---jQuery Submission Code---
{-code- 2}
--- รหัสการประมวลผลแบบฟอร์ม PHP ---
<?php
$ageTeam = $_POST[\'ageTeam\'];
$name = $_POST[\'name\'];
$address = $_POST[\'address\'];
$postcode = $_POST[\'postcode\'];
$dob = $_POST[\'dob\'];
$school = $_POST[\'school\'];
$parentName = $_POST[\'parentName\'];
$parentAddress = $_POST[\'parentAddress\'];
$parentPostcode = $_POST[\'parentPostcode\'];
$number = $_POST[\'number\'];
$email = $_POST[\'email\'];
$email_thankyou = "
Hi".$name."
Thank you for registering.
We look forward to welcoming you to our team and will contact you in due course.
Thanks again
";
$email_alert = "
".$name."has completed a registration form.
Their details are listed below:
Age and team:".$ageTeam."
Players full name:".$name."
Players address:".$address."
Players postcode:".$postcode."
Players date of birth:".$dob."
Players school:".$school."
Parent/guardians name:".$parentName."
Parent/guardians address:".$parentAddress."
Parent/guardians postcode:".$parentPostcode."
Contact number:".$number."
Email Address:".$email."
";
$headers = "From: Test PHP Ajax Form";
// Notification email to client
mail($email, \'Thank you for registering\', $email_thankyou, $headers);
// Notification email to Matthiola
mail(\'testemail@email.com\', \'Player Registration\', $email_alert, $headers);
?>
--- อีเมลที่ได้รับ ---
อีเมลที่ได้รับแสดงแบบคงที่ เนื้อหา แต่ไม่มีข้อมูลที่ผู้ใช้ควรให้
Answer
วิธีแก้ไข:
สาเหตุส่วนใหญ่อาจเป็นเพราะบอทและโปรแกรมรวบรวมข้อมูลเว็บที่ทำงานผ่านไซต์ของคุณ คุณควรตรวจสอบอินพุตจากฝั่งเซิร์ฟเวอร์ (โดยใช้ PHP) ก่อนส่งอีเมล
if ($name != \'\' && $address != \'\'){
// Notification email to client
mail($email, \'Thank you for registering\', $email_thankyou, $headers);
// Notification email to Matthiola
mail(\'testemail@email.com\', \'Player Registration\', $email_alert, $headers);
}
Source