By using PHP it finally becomes easy to access and process data entered in an HTML form.
A popular technique used to handle and process the data a user has entered in a form is to use PHP to divide a HTML page into two sections:
When the page is loaded PHP is used to check if data has been entered and submitted with the form. If no data has been submitted the first section which contains the HTLM form will be displayed.
When the user submits the form, the data from the form is sent to the same page which detects that data has been entered and uses PHP to execute the second section of the PHP page to process the data.
Below is a the basic PHP skeleton used by a page named "page_name.php ". The PHP code detects if data has been entered in a form with a textbox named "Comment":
<?
$theComment=$_POST[Comment];
if("$theComment" == "") {
?>
<!-- Section 1: Display the form -->
<form action="page_name.php" method="POST">
...
</form>
<? } else {
<!-- Section 2: Process the data -->
... use PHP to process the entered data ....
?>
The special PHP variable array $_POST[formItemName] contains the values that has been entered and submitted in a form, and it can be used to retrieve the values from a form.
Replace formItemName in $_POST[formItemName] with the HTML name attribute of the field you want to access and assign it to a PHP variable as shown below:
$variable = $_POST[Name]
See:
Form Access Example
Form To File Example
This PHP code example is copyright © 2002-2003 Optima System. All rights reserved worldwide. Unauthorized distribution prohibited. SpinPHP™ User License.