简体   繁体   English

自我提交表单重定向

[英]Self-submiting form redirect

I have a php from that includes the external process.php , which handles all my validation and sending the mail function and submits to it self by setting 我有一个PHP包括外部process.php ,它处理我的所有验证和发送mail功能,并通过设置提交给它自己
action="<?php echo $_SERVER['PHP_SELF'] ?>"
Everything works great, it validates properly and mails the form to my email, but when I try to include the header("location: thanks.html") to redirect after submit, it doesn't redirect. 一切都很好,它正确验证并将表单邮寄到我的电子邮件,但当我尝试在提交后包含header("location: thanks.html")重定向时,它不会重定向。 Am I doing this incorrectly or is it an issue with self-submitting the form? 我这样做是错误的还是自我提交表单的问题? I'm also using Jquery and Jquery Mobile. 我也在使用Jquery和Jquery Mobile。 Any help is appreciated 任何帮助表示赞赏

Heres my php 继承人我的PHP

<?php 
if(($_SERVER['REQUEST_METHOD'] =='POST') && (!empty ($_POST['action']))):

if (isset ($_POST['myname'])){$myname=$_POST['myname'];}
if (isset ($_POST['myphone'])){$myphone=$_POST['myphone'];}
if (isset ($_POST['myemail'])){$myemail=$_POST['myemail'];}
if (isset ($_POST['job'])){$job=$_POST['job'];}
if (isset ($_POST['comments'])){
    $comments= filter_var($_POST['comments'], FILTER_SANITIZE_STRING);}

$formerrors = false;



      if($myname === '') :
      $err_myname = '<div class="error"> Sorry, your name is rquired</div>';
      $formerrors=true;
      endif;    

      if($myphone === ''):
      $err_myphone = '<div class="error"> Sorry, your phone number is rquired</div>';
      $formerrors=true;
      endif;    

      if($myemail === ''):
      $err_myemaile =  '<div class="error"> Sorry, your email is rquired</div>';
      $formerrors=true;
      endif;    

      if($job === ''):
      $err_job =  '<div class="error"> Sorry, your business is rquired</div>';
      $formerrors=true;
      endif;    



if (!($formerrors)) :
$to = "myemail@emial.com";
$subject = " Request from $myname --Show and Tell";

$message = "A new show and tell request from:\n
            $myname \n
            $myemail\n
            $myphone\n
            $job\n
            $comments\n";
$replyto = "From: $myemail";


if(mail($to, $subject, $message)):
    $msg ="Thanks for filling out our form";
    header('location: http://localhost/thanks.html');
    else:
    $msg = "There was a problem sending the message";
    endif; //mail data

endif; //check errors

endif; //form submitted

?>

And my html 而我的HTML

<div data-role="content">
<?php if (isset($msg)) { echo '<div id="formmessage"><p>', $msg, '</p> </div>';}?>
<form id="form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
  <li data-role="fieldcontain">
    <label for="myname">Your Name*:</label><br>
    <input type="text" name="myname" id="myname" placeholder="John Smith" value="<?php if (isset($myname)) {echo $myname;}  ?>" required/>
    <?php  if (isset($err_myname)) {echo $err_myname;} ?>
  </li>

    <li data-role="fieldcontain">
    <label for="myemail">Email*:</label><br>
    <input type="email" name="myemail" id="myemail" placeholder="jsmith@email.com" value="<?php if (isset($myemail)) {echo $myemail;}  ?>"  />
    <?php  if (isset($err_myemail)) {echo $err_myemail;} ?>
    <?php  if (isset($err_wrong)) {echo $err_wrong;} ?>
  </li>

    <li data-role="fieldcontain">
    <label for="myphone">Phone number*:</label><br>
    <input onblur="formatPhone(this);" type="tel" name="myphone" id="myphone" placeholder="1234567890"   value="<?php if (isset($myphone)) {echo $myphone;}  ?>"  required/>
    <?php  if (isset($err_myphone)) {echo $err_myphone;} ?>
  </li>

      <li data-role="fieldcontain">
    <label for="job">Name of Business*:</label><br>
    <input  type="text" name="job" id="job" placeholder="Where do you work?"   value="<?php if (isset($job)) {echo $job;}  ?>"  required/>
    <?php  if (isset($err_job)) {echo $err_job;} ?>
  </li>


    <li data-role="fieldcontain">
      <label for="comments">Comments:</label><br>
      <textarea cols="40" rows="8" name="comments" id="comments" placeholder="Questions or Comments?">
      <?php if (isset($comments)) {echo $comments;}?>
      </textarea>

    </li>

<div data-inline="true" data-type="horizontal">
<input name="Reset" type="reset" value="Reset" data-role="button" data-inline="true" />

<input type="submit" value="Submit" data-role="button" 
data-inline="true" name="action" />


</div>


</form>



</div>

1/ Simple test, are you sure you don't have a whitespace or any other character sent before the header() 1 /简单测试,你确定你没有在header()之前发送空格或任何其他字符

2/ Did you check you got the http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering option on ? 2 /您是否检查过您的http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering选项? (Else you have to explicitly start output buffering) (否则你必须明确地开始输出缓冲)

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

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