Page 267 - Beginning PHP 5.3
P. 267

Chapter 9: Handling HTML Forms with PHP
                         Try filling in a few of the fields, then clicking the Submit Form button. Because the action attribute in
                          the <form> tag is an empty string, the browser sends the form data back to the same URL (web_form.
                         html). Obviously web_form.html can’t do anything with the form data because it’s simply an HTML
                          Web page, but shortly you’ll be writing PHP scripts that can handle data sent from a form.

                          Notice that, once you submit your form, you can see all of the form data in your browser’s address bar,
                          as shown in Figure 9-2. This is because your form used the get method, which sends the form data in
                         the URL. You can see that the form data is preceded by a ? character, and that the data for each form
                         field is sent as a name/value pair:
                             http://localhost/web_form.html?textField=Hello&passwordField=secret& ...
                         The get method is limited in the amount of data it can send, because a URL can only contain a small
                         number of characters (1,024 characters is a safe upper limit). If you need to send larger amounts of data
                         from a form, use the post method instead:

                             <form action=”myscript.php” method=”post”>
                         The post method sends the data within the HTTP headers of the request that’s sent to the server, rather
                         than embedding the data in the URL. This allows a lot more data to be sent. If the users try to refresh the
                         page after sending a form via the post method, their browser usually pops up a dialog box asking them
                          if they want to resend their form data.
                             You can find out more about HTTP headers in Chapter 16.

































                          Figure 9-2




                                                                                                         229





                                                                                                      9/21/09   7:23:35 PM
          c09.indd   229
          c09.indd   229                                                                              9/21/09   7:23:35 PM
   262   263   264   265   266   267   268   269   270   271   272