Page 156 - Open Soource Technologies 304.indd
P. 156
Unit 9: Working with Forms
12. </FORM> Notes
13. </BODY>
14. </HTML>
Put these lines into a text file called listing3.php, and place this file in your Web server document
root. Now access the script with your Web browser, and you should see something like Figure 9.1.
Figure 9.1: Form Created in Listing 3
In the next section, you create the script that sends this form to a recipient.
Create simple feedback form.
9.3 Accessing Form Input with User-Defined Arrays
The examples so far enable us to gather information from HTML elements that submit a single
value per element name. This leaves us with a problem when working with SELECT elements.
These elements make it possible for the user to choose multiple items. If we name the SELECT
element with a plain name, like so <select name=”products” multiple> the script that receives
this data has access to only a single value corresponding to this name. We can change this
behavior by renaming an element of this kind so that its name ends with an empty set of square
brackets. We do this in Listing 4.
Listing 4 An HTML Form Including a SELECT Element
1. <html>
2. <head>
3. <title>Listing 4 An HTML form including a SELECT element</title>
4. </head>
5. <body>
6. <form action=”listing5.php” method=”POST”>
LOVELY PROFESSIONAL UNIVERSITY 151