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

Open Source Technologies



                   Notes         ACTION argument points to a file called listing 2.php, which processes the form information.
                                 The method of this form is POST, so the variables are stored in the $_POST superglobal.
                                 Listing 2 creates the code that receives our users’ input.

                                 Listing 2 Reading Input from the Form in Listing 1
                                    1.  <html>

                                    2.  <head>
                                    3.  <title>Listing 2 Reading input from the form in Listing  1</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>”;
                                    9.  ?>

                                   10.  </body>
                                   11.  </html>

                                 Put these lines into a text file called listing 2.php, and place that file in your Web server document
                                 root.

                                 9.2 Creating the Form

                                 In Listing 3, you see the basic HTML for creating a simple feedback form. This form has an
                                 action of listing12.php, which we create in the next section. The fields are very simple: Line 7
                                 contains a name field, line 8 contains the return email address field, and line 10 contains the
                                 text area for the user’s message.
                                 Listing 3 Creating a Simple Feedback Form

                                    1.  <HTML>
                                    2.  <HEAD>
                                   3.  <TITLE>E-Mail Form</TITLE>
                                    4.  </HEAD>

                                    5.  <BODY>
                                    6.  <FORM action=”listing12.php” method=”POST”>

                                    7.  Your Name: <INPUT type=”text” name=”name”><br><br>
                                    8.  Your E-Mail Address: <INPUT type=”text” name=”email”><br><br>
                                    9.  Message:<br>
                                   10.  <textarea name=”message” cols=30 rows=5></textarea><br><br>

                                   11.  <INPUT type=”submit” value=”Send Form”>



        150                               LOVELY PROFESSIONAL UNIVERSITY
   150   151   152   153   154   155   156   157   158   159   160