[英]Contact form validation in PHP redirects to blank page
when my form is submitted it goes to the 'action' page, however its blank.当我提交表单时,它会转到“操作”页面,但它是空白的。 And even though I have checks for email, name etc. It does not show any errors on that blank page.
即使我检查了 email、名称等,它也没有在该空白页上显示任何错误。 Been trying to get this to work for past 2 days.
过去 2 天一直在努力让它发挥作用。
Here is my php code:这是我的 php 代码:
<?php
if (isset($_POST['submit']) && !empty($_POST)) {
$myEmail = "xxxxxxxxxx"; //securyti XD
$timeStamp = date("dd/M/YY HH:i:s");
$body = "";
$fullName = $_POST['fullName'];
$customerEmail = $_POST['customerEmail'];
$chosenSubject = $_POST['subject'];
$message = $_POST['message'];
$nameRegularExpression = "/^[a-zA-Z]+$/";
$emailRegularExpression = "/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/";
$body .= "From: " . $fullName . " at $timeStamp" . "\r\n";
$body .= "Email: " . $customerEmail . "\r\n";
$body .= "Message: " . $message . "\r\n";
if (!preg_match($nameRegularExpression, $fullName) or empty($fullName)) {
echo "Your name is not filled out properly or not filled out at all";
}
if (!preg_match($emailRegularExpression, $customerEmail) or empty($customerEmail)) {
echo "Your mail is not valid or you forgot to fill it out";
}
if (empty($chosenSubject) or empty($message)) {
echo "Dont forget to choose subject or write a message";
}
else {
mail($myEmail, $chosenSubject, $body);
header("Location: mail_sent.php");
}
}
So I put a HTML as well hope it helps you to help me haha And this is my html:所以我也放了一个HTML希望它能帮助你帮助我哈哈这是我的html:
<form action="/public/contact_form.php" method="POST">
<label for="name">Full Name ✍🏻</label> <br />
<input
type="text"
id="fullName"
name="fullName"
placeholder="Full Name"
required
/>
<br />
<label for="yourEmail">Your Email 📧</label> <br />
<input
type="email"
id="customerEmail"
name="customerEmail"
placeholder="Your Email"
required
/>
<br />
<label for="subject"
>What is your reason for contacting us? 🧐</label
>
<br />
<select id="subject" name="subject">
<option value="basic">Pick a subject</option>
<option value="general">I have a question</option>
<option value="collaboration">
I want to offer a collaboration
</option>
<option value="other">
I have something else on my mind
</option>
</select>
<br />
<label for="message">Your message to us 👨🏻💻</label> <br />
<textarea
name="message"
id="message"
cols="40"
rows="6"
></textarea
><br />
<div class="form-buttons">
<button type="submit" class="send">SEND</button>
<button type="reset" class="messup">Wait, I messed up...</button>
</div>
</form>
Make sure error reporting is enabled.确保启用了错误报告。 You can add this code to the top of the page.
您可以将此代码添加到页面顶部。
ini_set('error_reporting', true);
error_reporting(E_ALL);
There is your problem:你的问题是:
<button type="submit" class="send">SEND</button>
If you want to checking submit you should add a name and value like this:如果你想检查提交,你应该像这样添加一个名称和值:
<button type="submit" name="submit" value="1" class="send">SEND</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.