Hi MrRSMan,
Have a look at the following code
File 1:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> </title>
<style type="text/css">
</style>
<script type="text/javascript">
function redirect(){
location.href = "get.php?text=" + document.body.getElementsByTagName('div')[0].getAttribute('text');
}
function getTheValue(form){
var txt = document.createElement('input');
txt.type = 'text';
txt.value = document.body.getElementsByTagName('div')[0].getAttribute('text');
txt.name = 'text';
txt.style.display = 'none';
form.appendChild(txt);
return true;
}
</script>
</head>
<body>
<div text="your_text_value_goes_here"><a href="#" onclick="javascript: redirect();">Click To Load - GET METHOD</a> <div>
<br />
<form name="form1" action="get.php" method="post" onsubmit="return getTheValue(this);">
<input type="submit" name="submit" value="Submit POST" />
</form>
</body>
</html>
File 2:
PHP Code:
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET')
print "The value you've transferred from the HTML page through GET method is " . $_GET['text'];
else if($_SERVER['REQUEST_METHOD'] == 'POST')
print "The value you've transferred from the HTML page through POST method is " .$_POST['text'];
?>
1. Put both files inside your web publish folder.
2. Make sure that you name the PHP file as 'get.php'
3. Browse the HTML file and click either the hyper link or the button.
4. Hyper link will demonstrates a GET HTTP method in PHP
5. Button will demonstrates a POST HTTP method in PHP
Hope this help and please let me know if there is any confusion in the provided code.
Bookmarks