Page 157 - Open Soource Technologies 304.indd
P. 157

Open Source Technologies



                   Notes            7.  Name: <br>
                                    8.  <input type=”text” name=”user”>

                                    9.  <br>
                                   10.  Address: <br>
                                   11.  <textarea name=”address” rows=”5” cols=”40”></textarea>

                                   12.  <br>
                                   13.  Pick Products: <br>
                                   14.  <select name=”products[]” multiple>

                                   15.  <option>Sonic Screwdriver</option>
                                   16.  <option>Tricorder</option>

                                   17.  <option>ORAC AI</option>
                                   18.  <option>HAL 2000</option>
                                   19.  </select>

                                   20.  <br><br>
                                   21.  <input type=”submit” value=”hit it!”>

                                   22.  </form>
                                   23.  </body>
                                   24.  </html>

                                 Put  these  lines  into  a  text  file  called  listing4.php,  and  place  that  file  in  your  Web  server
                                 document root. Next, in the script that processes the form input, we find that input from the
                                 “products[]” form element created on line 14 is available in an array called $_POST[products].
                                 Because products[] is a SELECT element, we offer the user multiple choices using the option
                                 elements on lines 15 through 18. We demonstrate that the user’s choices are made available in
                                 an array in Listing 5.
                                 Listing 5 Reading Input from the Form in Listing 4

                                    1.  <html>
                                    2.  <head>

                                    3.  <title>Listing 5 Reading input from the form in Listing 6</title>
                                    4.  </head>

                                    5.  <body>
                                    6.  <?php

                                    7.  print “Welcome <b>$_POST[user]</b><p>\n\n”;
                                    8.  print “Your address is:<p>\n\n<b>$_POST[address]</b><p>\n\n”;

                                    9.  print “Your product choices are:<p>\n\n”;
                                   10.  if (!empty($_POST[products])) {



        152                               LOVELY PROFESSIONAL UNIVERSITY
   152   153   154   155   156   157   158   159   160   161   162