Retaining form data value after postingMany times we have to show the visitors posted data in a form and show them the form again. This happens due to several reasons and one of the main reason is failure of entered data of the visitor matching to the required standard or specification. In an example say the visitor has entered all the details in a signup form but the user id entered by the member is already used by some one else. Such a situation can be checked only after the visitor enters his or her choice of id. In such a case we have to show one error message and ask the user to try one more user id. ( you can see how the signup form works with to total login script etc here ) Here if the user has already entered all other details like email, address, gender etc then it is not a good idea to ask the visitor to enter them again. We can retain the entered date in respective fields and ask for necessary change in selection of user id. So the main question is how to retain the value of the entered data in different components of the form. If some one has selected female as gender then the form should retain that value and by default should show female as selected. Same way all input text box, drop down list box and check box should retain the value already entered by the user.
There are different ways to post back the entered data of a form, we can use database also. But here we will get the value back in the form through query string and use the variable to store the data in PHP. There are some other methods which uses session and some other store in cache or cookies. Using query string is a better option as it list dependant on the client side conditions like cookies not accepting, cache full etc.
We will discuss post back of data of each component of a form. We will start with a simple text box and move to other form components like period button, drop down list, text area and check box. We will focus one component in one tutorial and at the end we will create one form using all the components using all our learning.
This article is written by plus2net.com team.
| ▼ Web Forms & handling data in PHP