Page 273 - Beginning PHP 5.3
P. 273

Chapter 9: Handling HTML Forms with PHP
                         data is not sent to the server. Sometimes the field is sent as an empty string; sometimes no field name is
                         sent at all. The following table illustrates the behavior of various form controls when they ’ re not filled in
                         or selected:


                               Form Control        What Happens When It ’ s Not Filled In Or Selected

                              Text input field         The field name is sent, along with an empty value.
                              Password field         The field name is sent, along with an empty value.
                              Checkbox field         Nothing is sent at all.

                              Radio button field         Nothing is sent at all.
                              Submit button         Nothing is sent at all if the button isn ’ t clicked. This can happen if the user
                                               presses Enter/Return to submit a form. However, if there ’ s only one submit
                                               button in the form, most browsers will still send the button ’ s field name
                                               and value.

                              Reset button         Nothing is ever sent.
                              File select field         The field name is sent, along with an empty value.
                              Hidden field         The field name is sent, along with an empty value.

                              Image field          Same behavior as a submit button.
                              Push button          Nothing is ever sent.
                                Pull - down menu         Impossible to select no option, so a value is always sent.

                              List box             Nothing is sent at all.
                              Multi - select box      Nothing is sent at all.

                              Text area field         The field name is sent, along with an empty value.


                            Why is this important? Well, when nothing is sent at all for a field, PHP doesn ’ t create an element for the
                          field in the   $_POST ,  $_GET , or  $_REQUEST  array. So if you attempt to access the element, you ’ ll generate
                         a PHP notice along the lines of:
                             PHP Notice:  Undefined index:  gender in process_registration.php on line 18

                           This notice might appear in your server ’ s error log, or in the browser window, depending on your error
                         reporting settings. Such notices won ’ t interfere with the running of your script; for example, in the case
                         just shown, all that happens is that an empty string is passed to the   echo()  statement:

                                   <dt>Gender</dt><dd><?php echo $_POST[“gender”]?></dd>





                                                                                                         235





                                                                                                      9/21/09   7:23:38 PM
          c09.indd   235                                                                              9/21/09   7:23:38 PM
          c09.indd   235
   268   269   270   271   272   273   274   275   276   277   278