how to remember input data in the forms even after refresh page?
on the page where your form is submitting do something like this
session_start();
$_SESSION['data'] = $_POST['data'];
$_SESSION['data_another'] = $_POST['data_another'];
and than you can access those session variables any where like this
session_start(); // this should be at the top of the page before any html load
<input type="text" name="name" value="<?php echo $_SESSION['data'];?>"/>
refresh your page on success call like this
$.ajax({
type: "POST",
url: "yourfile.php",
data: 'data='+ data,
success: function(){
location.reload();
}
});
Keep input value after refresh page
EDIT: Keep value of more inputs
HTML:
<input type="text" id="txt_1" onkeyup='saveValue(this);'/>
<input type="text" id="txt_2" onkeyup='saveValue(this);'/>
Javascript:
<script type="text/javascript">
document.getElementById("txt_1").value = getSavedValue("txt_1"); // set the value to this input
document.getElementById("txt_2").value = getSavedValue("txt_2"); // set the value to this input
/* Here you can add more inputs to set value. if it's saved */
//Save the value function - save it to localStorage as (ID, VALUE)
function saveValue(e){
var id = e.id; // get the sender's id to save it .
var val = e.value; // get the value.
localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override .
}
//get the saved value function - return the value of "v" from localStorage.
function getSavedValue (v){
if (!localStorage.getItem(v)) {
return "";// You can change this to your defualt value.
}
return localStorage.getItem(v);
}
</script>
PHP form validation, keep field values after refresh
A quick way to do this and avoid lots of code and errors are as such:
<input type='text' name='first_name' value='<?php echo isset($_POST['first_name']) ? $_POST['first_name'] : ''; ?>' />
Related Topics
Laravel - HTMLspecialchars() Expects Parameter 1 to Be String, Object Given
PHP Get File Listing Including Sub Directories
How to Find the Date of a Day of the Week from a Date Using PHP
How to Set the Env Variable for PHP
How to Concatenate Multiple Ternary Operator in PHP
Executing a Shell Script from a PHP Script
Post and Get at the Same Time in PHP
How to Generate Random Date Between Two Dates Using PHP
Calling C/C++ Library Function from PHP
How to Handle Error for Duplicate Entries
How to Convert Output of Number_Format Back to Numbers in PHP
Convert Flat Array to the Multi-Dimensional
What Does ${ } Mean in PHP Syntax