<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP links</title>
<?php
echo '<div style="background-color:#ccc; padding:20px">' . $_POST['message'] . '</div>';
?>
<style type="text/javascript">
// prepare the form when the DOM is ready
$(document).ready(function() {
// bind form using ajaxForm
$('#htmlForm').ajaxForm({
// target identifies the element(s) to update with the server response
target: '#htmlExampleTarget',
// success identifies the function to invoke when the server response
// has been received; here we apply a fade-in effect to the new content
success: function() {
$('#htmlExampleTarget').fadeIn('slow');
}
});
});
</style>
</head>
<body>
<form id="htmlForm" action="html-echo.php" method="post">
Display List of Links <input type="text" name="message" value="Hello HTML" />
<input type="submit" value="Submit links" />
</form>
</body>
</html>
I am trying to get the results displayed on the same page without having to create a .php page and having the results displayed on a separate page. It's an application where a user can submit any type of link and have the results show up on the page.
Is there a way I could save the results for later reference? Keep the results displayed when the page is refreshed?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP links</title>
<?php
echo '<div style="background-color:#ccc; padding:20px">' . $_POST['message'] . '</div>';
?>
<script type="text/javascript">
$(document).ready(function() {
$('#formid form').submit(function(){
$.get('result.php', $(this).serialize(), function(data){
$('#result').html(data);
});
return false;
});
});
</script>
</head>
<body>
<div id="formid">
<form>
Display List of Links <input type="text" name="message" value="Hello HTML" />
<input type="submit" value="Submit links" />
</form>
</div>
<div id="result"></div>
</body>
</html>
try above format for display the form result on same page without load anotherone php file as new,but you should crerate result.php file for generate the result depend on the form inputs, you can get the values of form by using the $_REQUEST['']
on result.php, below is sample for result.php
<?php
$message=$_REQUEST['message'];
echo $message;
?>
your generated result of the result.php will shows on the index.php <div id="result"></div>
without reload or redirect the page