You need to use some sort of AJAX request to prevent the browser's default action.
HTML:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="path-to-scripts.js"></script>
</head>
<body>
<form id="myform" method="post" action="">
<fieldset>
<legend for="info">Some Info</legend>
<input type="text" id="info" name="info" placeholder="some info" />
</fieldset>
<filedset>
<input type="submit" value="Submit" />
</fieldset>
</form>
</body>
JavaScript:
(function($) {
$('#myform').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'post',
url: 'path-to-your-php-file.php',
data: $('#myform').serialize(),
timeout: 50000
}).done(function(responseData) {
// Do something with the response data.
}).fail(function(error) {
// Not good.
});
});
})(jQuery);
Now, let's say you want to call a php function with the responseData.
You will also need to think about how to return responseData. Is it an object? This could determine how you handle making the next request.
Depending on how you have things set up, you could do it as easily as:
JavaScript:
...
}).done(function(responseData) {
if (responseData)
{
$.ajax({
type: 'post',
data: responseData,
url: 'path-to-your-next-php-file.php',
timeout: 50000
}).done(function(responseData) {
// Do something with the response data.
}).fail(function(error) {
// Not good.
});
}
}).fail(function(error) {
...
However, doing it this way, you are going to start getting into a lot of nested ajax calls which can result in "callback hell". You might want to look at
Using a promise to make your life a lot easier.