Page 261 - Computer Software Application TP - Volume 1
P. 261

COMPUTER SOFTWARE APPLICATION - CITS















           TASK 3: Getting input from forms

              1  Create a HTML form
                 •  Open the text editor
                 •  Write the following codes
                    <html >
                    <head>
                                 <title>Form Example</title>
                    </head>
                    <body>
                                 <form action=”process.php” method=”post”>
                                 <label for=”name”>Name:</label>
                                 <input type=”text” name=”name” id=”name” required>


                                 <label for=”email”>Email:</label>
                                 <input type=”email” name=”email” id=”email” required>

                                 <input type=”submit” value=”Submit”>
                                 </form>
                    </body>
                    </html>
                 •  Save the program in C:\Apache24\htdocs in a folder as index.html


              2  Create a PHP code for getting input from forms
                 •  Open the text editor
                 •  Write the following codes
                                 <html>

                                       <body>
                                    <?php

                                                  // Check if the form is submitted
                    if ($_SERVER[“REQUEST_METHOD”] == “POST”)

                    {
                                               // Retrieve form data using $_POST
                                               $name = $_POST[“name”];
                                               $email = $_POST[“email”];






                                                           246

                               CITS : IT & ITES - Computer Software Application - Exercise 53
   256   257   258   259   260   261   262   263   264   265   266