当我点击提交按钮时,我得到一个无法发布.php文件错误。
我不知道我哪里出错了。我无法在本地计算机上测试它,因为我没有wamp服务器。我将代码推送到暂存环境。我不确定是否安装了wamp服务器。
以下是我的代码:
.php文件:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "redacted@gmail.com";
$email_subject = "Case Study Request";
function died($error) {
// your error code can go here
echo "We are very 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['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$query = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($query) < 2) {
$error_message .= 'Error in Case Study Request.<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_from)."\n";
$email_message .= "Case Study requested: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header("Location:http://roambee.com");
?>
<!-- place your own success html below -->
header("Location:http://roambee.com");
<?php
}
die();
?>
html文件:
<form action="html_form_send.php" method="post" id="contactform" name="contactform" class="no-margin-bottom" onSubmit="return validate()">
<fieldset class="img-center">
<div class="invite-input-container text-center">
<input type="text" tabindex="1" placeholder="* Full Name" name="name" id="name" class="span4"/>
</div>
<div class="invite-input-container text-center">
<input type="email" tabindex="2" placeholder="* Email Address" name="email" id="email" class="span4"/>
</div>
<div class="invite-input-container text-center margin-top15 padding-top15">
<input type="submit" name="submit" tabindex="3" value="Request Case Study"id="submit" class="btn btn-u btn-u-blue get-started-btn"/>
<input type="hidden" tabindex="4" value="message" name="message" id="message">
</div>
</fieldset>
</form>
<script type="text/javascript">
// pass the value of the plan chosen to the modal
$(document).on("click", ".get-started-btn", function () {
var message = $(this).attr("id");
$(".modal-body #message").val(message);
//console.debug("inside trial modal: selected price = ", priceId);
});
</script>
validate()函数:
<SCRIPT language=javascript>
function validate()
{
if(document.contactform.name.value=="")
{
alert("Please enter your name.");
document.contactform.name.focus();
return false;
}
else if ((document.contactform.email.value.length < 6) || ((document.contactform.email.value).indexOf("@") == -1 ) || ((document.contactform.email.value).indexOf(".") == -1 ) )
{
alert ("Please enter a valid e-mail address.");
document.contactform.email.focus();
document.contactform.email.select();
return false;
}
return true;
}
</SCRIPT>
验证代码工作正常。但是当我点击提交按钮时,我收到了无法POST .php文件错误。
答案 0 :(得分:-1)
我认为你的php文件的第2行应该是;
if(isset($_POST['submit'])) {