You should use jQuery to this. You can use its ajax()
function. Visit the link below and read the full description of it with the functions list to help you out.
Here is a sample code for you:
<hmtl>
<head>
<script type="http://code.jquery.com/jquery-1.5.1.min.js"></script>
</head>
<body>
<div class="my-fake-form">
<input id="posting-value-1" type="text" />
<a id="submit-form-link" href="#submit">Submit this Div!</a>
</div>
</body>
</html>
Ajax code:
function fake_form_submit ()
{
var post = $('input#posting-value-1').val();
$.ajax({
'url': 'your-php-file.php',
'type': 'POST',
'dataType': 'json',
'data': {post: post},
'success': function(data)
{
if(data.finish)
{
$("div.my-fake-form").attr("innerHTML","Form Submited!");
}
else
{
$("div.my-fake-form").attr("innerHTML","Form Not Submited!");
}
},
beforeSend: function()
{
$(document).ready(function () {
$("div.my-fake-form").attr("innerHTML","Loading....");
});
},
'error': function(data)
{
$(document).ready(function () {
$("div.my-fake-form").attr("innerHTML","ERROR OCCURRED!");
});
}
});
}
$(document).ready(function () {
$('a#submit-form-link').click(function (e) {
e.preventDefault();
fake_form_submit();
});
});
PHP:
<?php
$post = $_POST['post'];
//Do Something with the value!
//On Succes return json encode array!
echo json_encode(array("finish" => true));
?>
AJAX documentation
AJAX function documentation
AJAX tutorial