Reputation: 602
I have an html file/page where there will be multiple input fields in a form. This form action field is linked to another .php file where all the inputted data is written to a database. But once when i click submit the form i get directed to the .php file which is not what i want.Is there any way by which i could write the data into the database ,but remain in the same html file?
Upvotes: 0
Views: 4615
Reputation: 3715
You could make the submit button send the form data to a div tag on the same page using ajax. The code from Dynamic Drive should work if you read through it.
Dynamic Drive - Dynamic Ajax Content
Upvotes: 0
Reputation: 1318
You have 2 options:
1 - Submit you form using AJAX. With this approach the page will stay "refresh" and the user will be on the same page
2 - After the submit, redirect the user back to the previous page.
Upvotes: 0
Reputation: 15629
If you want to do this, you have to use javascript and ajax.
your form:
<form id="yourform">...</form>
javascript:
$(function() {
$('#yourform').on('submit', function(e) {
var data = $("#yourform :input").serialize();
$.ajax({
type: "POST",
url: "script.php",
data: data,
});
e.preventDefault();
});
});
Upvotes: 2
Reputation: 948
of course. use ajax. do some web searches on ajax combined with html and you will find the answers you are looking for. jquery is one possible javascript/ajax platform that could simplify this process for you.
Upvotes: 0