SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Retaining text box value of a form after posting


Learn details on retaining post back values of a form here

Here is one text box inside a PHP code area. We will learn here how to retain the text box value after the form is submitted. In this text box we will keep one value option which will store the value entered by the user. This form is submitting to another page where the PHP code will check the value and if it is correct then it will redirect ( or back ) to main page with the value of data in query string. We will use PHP header redirect in the second page ( page to which form data will be submitted ) to post back the data to the main page having the form.

Here to take care of some characters like & we have used urlencode and urldecode to first encode the date before sending through the address bar and then after receiving at main page again we will decode it to get the original data entered by the visitor.

Here is the code of the form with decode script.

<?
$t1v=$_GET['t1v'];
$t1v=urldecode($t1v);

echo "
<form method=post action=pb-t.php>
<input type=text name=t1 value='$t1v'>
<input type=submit value=Submit>
";

?>

Now we will go to the second page were the form date is collected and posted back to main page. Here is the code of pb-text.php

<?
$t1=$_POST['t1'];

$t1=urlencode($t1);
header ("Location: pb-text.php?t1v=$t1");
?>

Here is the demo of the script. Enter your name below this text box.



Date will be posted back and you will see your name again here after redirection



Further readings
All form components validation with post back and data locking
Checkbox
How to retain form data if validation fails?
How to retain data of a text box after submitting
Retaining status of a check box
Updating checkbox value from & to a table record.
Retaining selected data of a period button of a form
Retaining selected data of a drop down list box of a form
Handling drop down list box with multiple selection options using array
Validating Date: Checking if date exist
Email address validation in a form
Email validation using Ajax & PHP
PHP Form Validation
is_numeric to check numeric numbers
ctype_alnum to check alphanumeric characters data
ctype_alpha to check alphabetic characters data
How to take care of form & query string variables if Register global is OFF?















Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
Form handling
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.