Keep html page open and not load php page after button press

HI
I have a button on a form on a html page and the action of the button is to go to a php script which processes the variables of the form. This is working fine but the php page loads straight after I press the button. I don’t want this . I want the original page to stay visible.
Can anyone help?

Here is an example of the button on the form:

<form action="form.php" method="post">
  <input type="hidden" name="var3" value="hidden value3"><br>
  <button type="submit" formaction="form.php">Submit hidden values in var 3</button>
</form>

as you can see the form.php gets run and it opens a new blank page.

Here is the script in form.php:

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$var1 = $_POST["var1"];
$var2 = $_POST["var2"];
$var3 = $_POST["var3"];
$fp = fopen("formdata.txt", "a");
$savestring = $name . "," . $email . "," . $var1 . "," . $var2 . $var3 . "\n";
fwrite($fp, $savestring);
fclose($fp);
//echo "<h1>from form.php Your data should be saved in formdata! $name $email $var1 $var2 $var3</h1>";
?>

Just have a look at AJAX.

So, your options are AJAX as @chorn said, or to let the page go to the processor and get returned back. But you need to prevent the form submission when you go the Ajax route.

Sponsor our Newsletter | Privacy Policy | Terms of Service