[英]Contact form returning error, specifically with 'email' field
I have a contact form field that uses AJAX to submit the form, and PHP. 我有一个使用AJAX提交表单和PHP的联系表单字段。
I have a small problem. 我有一个小问题。 I keep receiving an error that states,"
the request was successful, but the form was not filled out correctly.
" This applies to the ' email
' field. 我不断收到一条错误消息,指出“
the request was successful, but the form was not filled out correctly.
”这适用于“ email
”字段。 The form does not get submitted, and a user has to refill out the form. 表单未提交,用户必须重新填写表单。
Somehow, any email address entered is not valid. 不知何故,输入的任何电子邮件地址均无效。
Does anyone know why that could be? 有谁知道为什么会这样吗?
/* Email Variables */
$emailSubject = 'You have received an inquiry from your website';
$webMaster = 'info@3elementsreview.com';
/* Data Variables */
$first = Trim(stripslashes($_POST['First']));
$last = Trim(stripslashes($_POST['Last']));
$email = Trim(stripslashes($_POST['E-Mail']));
$message = Trim(stripslashes($_POST['Message']));
$tempt = $_POST['tempt'];
$tempt2 = $_POST['tempt2'];
if ($tempt == 'http://' && empty($tempt2)) {
$error_message = '';
$reg_exp = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/";
if(!preg_match($reg_exp, $email)) {
$error_message .= "<p>A valid email address is required.</p>";
}
if (empty($first)) {
$error_message .= "<p>Please provide your first name.</p>";
}
if (empty($last)) {
$error_message .= "<p>Please provide your last name.</p>";
}
if (empty($message)) {
$error_message .= "<p>Comments box cannot be left empty.</p>";
}
if (!empty($error_message)) {
$return['error'] = true;
$return['msg'] = "<h3> The request was successful, but the form is not filled out correctly.</h3>".$error_message;
echo json_encode($return);
exit();
} else {
$return['error'] = false;
$return['msg'] = "<p>Thank you for contacting us. We definitely value your feedback," .$first .".</p>";
echo json_encode($return);
}
} else {
$return['error'] = true;
$return['msg'] = "<h3>There was a problem while sending this form. Try it again.</h3>";
echo json_encode($return);
}
HTML 的HTML
<form class="contact-me" action="mail/mailform.php" method="post" name="contact-me">
<div id="response"><!-----------------CONTAINS FORM ERROR MESSAGE--------------></div>
<input name="First" class="required" title="Your First Name is Required" id="first" autofocus placeholder="First Name" type="text" maxlength="15"></input><br>
<input name="Last" title="Your Last Name is Required" id="last" placeholder="Last Name" type="text" maxlength="15"></input><br>
<input name="E-mail" title="E-Mail Address is Required" id="email" placeholder="Email Address" type="email" maxlength="50"></input><br>
<textarea name="Message" title="Comments are Required" placeholder="Comments" rows="1" cols="50" id="message" onKeyDown="textCounter(this.form.comments,this.form.countDisplay);"onKeyUp="textCounter(this.form.message,this.form.countDisplay);"></textarea><br>
<input type="hidden" name="tempt" id="tempt" value="http://" />
<input type="hidden" name="tempt2" id="tempt2" class="clear" value="" />
<input name="countDisplay" type="text" id="countdisplay" value="2000" size="4" maxlength="4" readonly></input><br>
<button class="button" ontouchstart="('touchstart');">SEND</button>
</form>
The problem is your email input name attribute. 问题是您的电子邮件输入名称属性。
Your input is: 您的输入是:
<input name="E-mail" title="E-Mail Address is Required" id="email" placeholder="Email Address" type="email" maxlength="50">
and you're accessing it using $_POST['E-Mail']
(uppercase M
). 并且您正在使用
$_POST['E-Mail']
(大写M
)访问它。 Note that array index are case sensitive. 请注意,数组索引区分大小写。
Change that line to match your input's name as follows: 更改该行以匹配您的输入名称,如下所示:
$email = Trim(stripslashes($_POST['E-mail']));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.