PHP & Input Text box with default value and Retaining text box value
Retain a text-box value
When validation fails, place the submitted text back into the field only after HTML escaping. This keeps the user's entry while preventing it from becoming markup.
Form is submitting the data by attribute action=pb-text2.php to pb-text2.php file, inside which we will keep this code to receive data and display the same.
We will use default attribute to keep some default data inside input textbox. Source of this data can be a variable or we can display by taking data from a database table.
When the page is loaded the data stored in PHP variable will be stored and displayed inside text box as default value. Here is one example
<?Php
$t1="My Data here ";
echo"<input type=text name='t1' value='$t1'>";
?>
Output is here
Redisplaying submitted data in the same form
For a normal validation error, you do not need to send the text through the address bar. Read it from POST, validate it, escape it for HTML, and reuse it in the form value.
You are asked to update your address, the site will collect your present address from a database table and show it to you as default data inside a textbox. You can change the data and submit to update the table with your new address.
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery,
and web development at plus2net. The tutorials focus on clear explanations, working
examples, and code that readers can test and adapt while learning.