How to Interact with Web Forms. Part 2 | 3 | WebReference

How to Interact with Web Forms. Part 2 | 3

How to Interact with Web Forms.. Part 2

Writing All Form Data into a File

After a user fills out a form correctly, what do you do with the form data? A very intuitive approach that does not require too much setup on the server is to write the data into a file on the server.

The preceding code contains a very naïve approach: All data is stored in a file on the server.When the form is submitted, the file is read in and unserialized into an array.Then, the form data is appended to the array. Finally, the array is serialized again and written back to the file.

Figure 4.3 shows this file in a text editor.

Sending All Form Data Via Email

A more imminent notification of someone filling out a form can be implemented by sending form data via email. Of course, you can write a custom mail script for each and every form; however, the preceding code shows how this can be done universally.Via for, all form data is merged into a string. Special care is taken of form values that are arrays—this can occur with multiple selection lists.Then the form data is mailed to the webmaster—just don't forget to change the email address.

Created: March 27, 2003
Revised: January 23, 2006