Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提交表单后csv文件保存,我想重定向另一个网站_Php_Redirect_Export To Csv - Fatal编程技术网

Php 提交表单后csv文件保存,我想重定向另一个网站

Php 提交表单后csv文件保存,我想重定向另一个网站,php,redirect,export-to-csv,Php,Redirect,Export To Csv,我有一个表单设置和一个php文件(如下所示),我将数据保存在csv文件中以验证输入,然后重定向到另一个网站(index.html)。验证和csv导出工作得很好,但我不知道如何让表单重定向到想要的页面,而只是显示返回后的内容 <?php //index.php $error = ''; $name = ''; $email = ''; $phone = ''; $message = ''; function clean_text($string) { $string = trim($st

我有一个表单设置和一个php文件(如下所示),我将数据保存在csv文件中以验证输入,然后重定向到另一个网站(index.html)。验证和csv导出工作得很好,但我不知道如何让表单重定向到想要的页面,而只是显示返回后的内容

<?php
//index.php
$error = '';
$name = '';
$email = '';
$phone = '';
$message = '';

function clean_text($string)
{
 $string = trim($string);
 $string = stripslashes($string);
 $string = htmlspecialchars($string);
 return $string;
}

if(isset($_POST["submit"]))
{
 if(empty($_POST["name"]))
 {
  $error .= '<p><label class="text-danger">Please Enter your Name</label></p>';
 }
 else
 {
  $name = clean_text($_POST["name"]);
  if(!preg_match("/^[a-zA-Z ]*$/",$name))
  {
   $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
  }
 }
 if(empty($_POST["email"]))
 {
  $error .= '<p><label class="text-danger">Please Enter your Email</label></p>';
 }
 else
 {
  $email = clean_text($_POST["email"]);
  if(!filter_var($email, FILTER_VALIDATE_EMAIL))
  {
   $error .= '<p><label class="text-danger">Invalid email format</label></p>';
  }
 }
 if(empty($_POST["phone"]))
 {
  $error .= '<p><label class="text-danger">phone is required</label></p>';
 }
 else
 {
  $phone = clean_text($_POST["phone"]);
 } 

  if(empty($_POST["message"]))
 {
  $error .= '<p><label class="text-danger">Message is required</label></p>';
 }
 else
 {
  $message = clean_text($_POST["message"]);
 }
 if($error == '')
 {
  $file_open = fopen("enquiry_form_data.csv", "a");
  $no_rows = count(file("enquiry_form_data.csv"));
  if($no_rows > 1)
  {
   $no_rows = ($no_rows - 1) + 1;
  }
  $form_data = array(
   'sr_no'  => $no_rows,
   'name'  => $name,
   'email'  => $email,
   'phone'  => $phone,
   'message' => $message
  );
  fputcsv($file_open, $form_data);
  $error = '<label class="text-success">Thank you for contacting us</label>';
  $name = '';
  $email = '';
  $phone = '';
  $message = '';
 }
}

?>
<!DOCTYPE html>
<html>
<head>
<title>How to Store Form data in CSV File using PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br />
<div class="container"> <br />
  <div class="col-md-6" style="margin:0 auto; float:none;">
    <form method="post">
      <h3 align="center">Find your dream Holiday today!</h3>
      <br />
      <?php echo $error; ?>
      <div class="form-group">
        <label>Enter Name</label>
        <input type="text" name="name" placeholder="Enter Name" class="form-control" value="<?php echo $name; ?>" />
      </div>
      <div class="form-group">
        <label>Enter Email</label>
        <input type="text" name="email" class="form-control" placeholder="Enter Email" value="<?php echo $email; ?>" />
      </div>
      <div class="form-group">
        <label>Enter phone</label>
        <input type="text" name="phone" class="form-control" placeholder="Enter phone" value="<?php echo $phone; ?>" />
      </div>
      <div class="form-group">
        <label>Enter Message</label>
        <textarea name="message" class="form-control" placeholder="Enter Message"><?php echo $message; ?></textarea>
      </div>
      <div class="form-group" align="center">
        <input type="submit" name="submit" class="btn btn-info" value="Submit" />
      </div>
    </form>
  </div>
</div>
</body>
</html>
尝试以下代码:

<?php 
header('Location: http://www.example.com/');
?>

我想在提交按钮后弹出关闭和页面重定向。