Reputation: 99
I have a form sending data via post to the page of itself. I want to refresh the page without sending form data again just like you go to the page initially.As far as I know I can use ajax to do so, but it is quite complicated. And, I am looking for simpler method to do so. I have searched overriding refresh but it is not possible. So, do you have any methods refreshing the page without sending form data again besides ajax?
my code of abc.php:
<html>
<body>
<?php
echo "<form action='abc.php' method='post'>";
if(isset($_POST["edit_u_name"])){
echo "<br><br>name: <input type='text' name='user_name' maxlength='20' value='" . $u_name . "'> <input type='submit' name='confirm_u_name' value='confirm'><input type='submit' name='cancel_u_name' value='cancel'>";
}
else
echo "<br><br>name: ". $u_name. " <input type='submit' name='edit_u_name' value='edit'>";
echo "</form>";
?>
</body>
</html>
When I press the edit button and then refresh, I want go to the page just like directly going to the page initially with sending data of edit button.
Upvotes: 0
Views: 1514
Reputation: 359
Here you go
<!DOCTYPE html>
<?php
if(isset($_POST["u_name"])){
$u_name = $_POST["u_name"];
} else {
$u_name = '';
}
?>
<html>
<body>
<form action='abc.php' method='post'>
<span id="in" style="display: none">
<br>
<br>name: <input type='text' name='u_name' maxlength='20' value='<?php echo $u_name; ?>'>
<input type='submit' name='confirm_u_name' value='confirm'>
<input type='reset' name='cancel_u_name' value='cancel'>
</span>
<span id="ed">
<br>
<br>name: <?php echo ($u_name =='')?'--':$u_name; ?><input type='button' value="Edit"
onclick="document.getElementById('ed').style.display = 'none';document.getElementById('in').style.display = 'block';">
</span>
</form>
</body>
</html>
Upvotes: 2