自我提交表单重定向

时间:2013-07-24 15:53:29

标签: php jquery html jquery-mobile

我有一个包含外部process.php的php,它处理我的所有验证并发送mail函数并通过设置action="<?php echo $_SERVER['PHP_SELF'] ?>" 一切都很好,它正确验证并将表单邮寄到我的电子邮件,但当我尝试在提交后包含header("location: thanks.html")重定向,它不会重定向。我这样做是错误的还是自我提交表单的问题?我也在使用Jquery和Jquery Mobile。任何帮助表示赞赏

继承我的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

?>

我的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 个答案:

答案 0 :(得分:2)

1 /简单测试,您确定在header()

之前没有发送空格或任何其他字符

2 /您是否检查过http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering选项? (否则你必须明确地开始输出缓冲)

相关问题