简体   繁体   English

无法发布php文件

[英]Cannot POST php file

When I click on the submit button, I get a cannot post .php file error. 单击提交按钮时,出现无法发布.php文件的错误。

I don't know where I'm going wrong. 我不知道我要去哪里错了。 I cannot test it on my local machine as I don't have a wamp server. 我没有本地服务器,因此无法在本地计算机上对其进行测试。 I push the code to staging environment. 我将代码推送到暂存环境。 I'm not sure if that has wamp server installed. 我不确定是否安装了wamp服务器。

Below is my code: 下面是我的代码:

.php file: .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 file: 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() function: 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>

The validate code works fine.But when I click on submit button, I get the Cannot POST .php file error. 验证代码工作正常。但是,当我单击“提交”按钮时,出现“无法发布.php文件”错误。

我认为您的php文件的第2行应该是;

   if(isset($_POST['submit'])) { 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM