Forum Moderators: open
The data they have sent then gets written into a special log file for me to review later.
Is this possible? And if so, how do I progress from what I have below?
<form action="" method="post">
<input name="" type="text"><input type="submit" value="Submit">
</form>
Many thanks!
Just one solution of many, I'm sure.
cEM
I have a reservation however, with submitting to the same page, since the user will then be brought back up to the top of the page, which could prove to be very confusing.
I've been writing down some ideas on some paper, and I think I might have an idea:
Can a form submit to a target on the page but not showing, then that loaded page would read and write the variables, then load the 'Thanks'.
I don't know, maybe that would make for some sloppy code?
Kaled.
Basically, you call a Javascript function that generates a new HTTP request in the background. You can use server-side code (PHP, JSP, ...) to evaluate the request, log your info and deliver whatever response code you need. Then, the client-side Javascript can evaluate the response and dynamically change the page accordingly.
The effect is that you have a proper HTTP request-response-cycle going without the browser refreshing (since it's running in the background).
The Javascript you need for that is surprisingly simple:
function retrieveURL(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}
}
function processStateChange(status) {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
// insert response in page
document.getElementById("someElement").value = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}
For further reading, check Wikipedia for Ajax and continue from there.