Click to See Complete Forum and Search --> : Simple use of "Post" in an HTML form
coldscooter
07-22-2008, 07:51 AM
Hi, I would simply like to submit information from a form on a webpage, to be displayed on another web page. What is this code that I should put in the receiving web page?
There's lots of documentation on how to send, but not how to recieve...
Here's the simple code i'm using to post the details:
<form method=POST action="test_newsletter.html">
test text
<input type="text" name="test_text">
<INPUT TYPE=submit>
</form>
Thanks
For html use GET. If you have server side language capabilities you can also use POST
send.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>send</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<form action="receive.htm" method="get" name="form1">
<div>
<input type="text" name="first">
<button type="submit" name="submit" value="button">submit</button>
</div>
</form>
</body>
</html>
receive.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>receive</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var data=location.search;
data=location.search.substring(1); // remove the '?'
data=data.split('&');
var pairs={};
for(var i=0; i<data.length; i++){
var tmp=data[i].split('=');
pairs[tmp[0]]=tmp[1];
}
for (var i in pairs) { // display name value
document.write(i+"="+pairs[i]+"<br>");
}
</script>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
coldscooter
07-22-2008, 08:47 AM
Thanks for your response, but is there a way of using the "POST" function so that all the information isn't displayed in the url?
Thanks
Not without using a server side language.
An alternative is to use cookies (http://www.quirksmode.org/js/cookies.html).
ray326
07-22-2008, 09:57 PM
A good web server won't even let you post to an HTML page.