tailieunhanh - Professional Information Technology-Programming Book part 74
Tham khảo tài liệu 'professional information technology-programming book part 74', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Processing a Form with PHP Now let s look at how each type of item in a form is handled by PHP after the submit button is clicked. Accessing Form Values Form values are made available in PHP by using some special array structures. The arrays _GET and _POST contain values submitted using the GET and POST methods respectively. A hybrid array _REQUEST contains the contents of both of these arrays as well as the values from _COOKIE which you will use in Lesson 14 Cookies and Sessions. Super-globals The system-generated arrays that have names beginning with an underscore character are known as super-globals because they can be referenced from anywhere in a PHP script regardless of scope. For instance you do not need to explicitly declare _POST as global to access its elements within a function. Accessing the values from form items is fairly intuitive The form item names become the element keys in _GET or _POST and each value in the array is the value of the corresponding element when it was submitted. For example the email address submitted by comments . html will be _POST email and the comments text will be _POST comments . For CHECKBOX and RADIO input types the VALUE attribute determines the value seen by PHP. If the check box named may_contact is checked then the array element _POST may_contact has the value Y. If it is not checked this element simply does not exist in the array you should use is set to check whether a check box is checked. Default Check Box Values If you do not specify a VALUE attribute for a check box item its value in PHP when checked is on. The radio group gender causes _POST gender to contain the value m or f depending on which value is selected and as with a check box if no value is selected the array element does not exist. The simplest way to see all the submitted data from a form is to use a call to print_r to dump out the contents of _POST as follows echo PRE print_r _PO ST echo PRE This is a useful debugging technique if you want to see .
đang nạp các trang xem trước