Code: Select all
<html>
<body>
<form action="Welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>The output I get with the above code is something like: Hello ! and you are ! ... notice the problem. Even if I throw a print statement where the $_POST statement would be still the same outcome.
Also I got this slightly more complicated code that I am trying to get working and I believe that it is not working because of the post\get prob. Below is a simple example I pulled from another website as an example of the more complicated code I was talking about. The prototype.js is in the same dir and so is test.php
Code: Select all
<html>
<title>php-learn-it.com - php ajax form submit</title>
<head>
<script type="text/javascript" src="prototype.js"></script>
<script>
function sendRequest() {
new Ajax.Request("test.php",
{
method: 'post',
postBody: 'name='+ $F('name'),
onComplete: showResponse
});
}
function showResponse(req){
$('show').innerHTML= req.responseText;
}
</script>
</head>
<body>
<form id="test" onsubmit="return false;">
Name: <input type="text" name="name" id="name" >
<input type="submit" value="submit" onClick="sendRequest()">
</form>
<div id="show"></div>
<br/><br/>
</body>
</html>
test.php
<?php
if($_POST["name"] == "")
echo "name is empty";
else
echo "you typed ".$_POST["name"];
?>