Changes

PHP and HTML Forms

39 bytes added, 17:20, 13 May 2009
no edit summary
== Creating the Form ==
The first step involves creation on of an HTML page to contain our form. The form will be very simple in that it will contain only a text area for the user to enter data and a submit button with which to send it to the server. We will use the POST method of transmitting the data to the server and specify "subscribe.php" as the server side script to hanlde handle the data:
<pre>
== Processing Form Data Using PHP ==
Now that we have created a form we need to understand how to process the data enter entered by the user in our server side PHP script. There are two mechanisms for transmitted transmitting the data form from an HTML form to the server, GET and POST. In our example above we specified POST, but in either case the task of reading this data in our PHP script is equally simple.
Essentially PHP places the data from the form into an associative array (for information on PHP arrays see [[PHP Arrays]]) which can be accessed from within the server side PHP script. For POST and GET the array variable names are $_POST and $_GET respectively.
</pre>
Up until now we have only concerned ourselves with data which only holds one value (the text in a text field for example). Clearly, in this case there is the potential for multiple data values to be associated with a single form element. The way PHP handles this is to place the multiple selections in an array. Before that happens, however, we need to make a small modification to our declaration of the HTML Select element. All we need to do to turn this data into an array is to place [] after the element name:
<select name="carBrands[]" size=5 multiple>
This chapter has provided a detailed overview of handing HTML forms in PHP.
 
<google>BUY_PHP_BOTTOM</google>