0

I have a feedback section at the bottom of my site but when I press submit it opens a new page, I want it to stay on the same page. https://voxet.net

<?php
    if(isset($_POST['submit'])){
        $feedback_desc = $_POST['feedback_desc'];
        $cvsData = "$feedback_desc\n";
        $fp = fopen("feedback.csv","a");
        if($fp){
            fwrite($fp,$cvsData);
            fclose($fp);
        }
    }
?>
Burhan Ali
  • 2,258
  • 1
  • 28
  • 38

2 Answers2

0
<form action="form.php" method="post">

When your form submits, it is processed on form.php. That is why there is a redirection to form.php upon form submission. You've got three options:

1) Move the server-side form code from form.php to your page with the form. You can then remove the action attribute and there will be no redirect. This will cause the page to refresh though - to avoid this, you need to use AJAX.

2) Add Header('Location: index.php'); to the end of your form.php page. This will redirect back to the home page after submitting the form.

if(isset($_POST['submit'])) {
    // code
    Header('Location: index.php');
}

3) Use AJAX to send the form POST data to form.php upon form submission. See Form submit with AJAX passing form data to PHP without page refresh

The Codesee
  • 3,714
  • 5
  • 38
  • 78
0
if(isset($_POST['submit'])){
    ..... Code
    header('Location:https://voxet.net')
}

Add header function after if statement

Encang Cutbray
  • 382
  • 1
  • 2
  • 9