【问题标题】:I want to redirect the current page after submitting the form....it should return the page from where request is send using php我想在提交表单后重定向当前页面....它应该返回使用 php 发送请求的页面
【发布时间】:2017-11-14 14:00:41
【问题描述】:

我想在提交表单后重定向当前页面,因为相同的表单在多个页面中 (大约 25 页) 所以它应该返回使用 php 提交表单的页面

这是我的 HTML 代码:

<form method="post" action="submitEnquery.php">
  <input name="name" placeholder="Full Name" type="text" >
  <input name="email" placeholder="Email Address" type="email">
  <textarea name="message" placeholder="Type your message here....">/textarea>                          
  <button name="submit" type="submit">send</button>
</form>

这是我的 php 代码:

<?php
  if (isset($_POST['submit']))
  {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['msg'];
    $to = 'qwert01@exmple.com' . ', ';
    $to.= 'qwert003@exmple.com';
    $subject = "Enquery Form";
    $message = "
          <html>
          <head>
              <title>HTML email</title>
              <style>
              body{ background: #E6E4DE; }
              img{ width:200px; height:55px; display:block; text-align:center; 
              margin:0 auto; }
              h3{ text-align:center;margin:25px auto; }
              table { font-family: arial, sans-serif; border: 1px solid #ddd; 
              border-collapse: collapse; width: 70%; margin: 0 auto; }
              td, th { border: 1px solid #ddd; text-align: left; padding: 10px 
              15px; vertical-align: top; }
              </style>
          </head>
          <body>               
              <h3>Senders Detail down below</h3>
              <table rules='all' cellpadding='10'>
                  <tr style='background: #eee;'>
                      <th style='width:25%'>Name</th>
                      <th style='width:75%'>" . $name . "</th>
                  </tr>
                  <tr>
                      <td style='width:25%'>Email</td>
                      <td style='width:75%'>" . $email . "</td>
                  </tr>
                  <tr>
                      <td style='width:25%'>Message</td>
                      <td style='width:75%'>" . $msg . "</td>
                  </tr>
              </table>
          </body>
          </html>
      ";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers.= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers.= 'From: ' . $email . "\r\n";
    $headers.= 'Cc: qwert65494@exmple.com' . "\r\n";
    $headers.= 'Bcc: iqwert@exmple.com' . "\r\n";
    mail($to, $subject, $message, $headers);
    header('Refresh:0;');
  }

  echo '<h3>Sent Sccessfully...!</h3>';
?>

代码运行正常。 它发送邮件没有问题,但问题是如何重定向到提交 en-query(contact) 表单的页面。

【问题讨论】:

  • 更改您的header() 以反映您想去的地方。
  • 一种安全的方法是在每个包含表单的页面的开头设置一个 php 会话变量,以及它来自的文件名,然后在 submitEnquery.php 中检索它。我个人不相信可以不存在的服务器变量,也不相信可以修改的表单数据
  • 好的@Kaddath 我以后会试试这个.. ty

标签: javascript php html forms


【解决方案1】:
header("Location: " . $_SERVER['HTTP_REFERER']);

header("location:javascript://history.go(-1)");

【讨论】:

    猜你喜欢
    • 2014-05-26
    • 2020-02-13
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    相关资源
    最近更新 更多