PHP Solution (Ecommerce web host) 5-8: Getting data from check boxes

PHP Solution 5-8: Getting data from check boxes BRINGING FORMS TO LIFE Check boxes are similar to radio button groups, except that they permit multiple selections. This affects how you name a check box group and extract the selected values. 1. The following listing shows the code for the check boxes in contact.php. To save space, just the first two check boxes are shown. The name attribute and PHP sec tions of code are highlighted in bold.


Interests in Japan

checked=”checked” />

checked=”checked” />

. . .

The really important thing to note about this code is the empty pair of square brackets following the name attribute of each check box. This tells PHP to treat interests as an array. If you omit the brackets, $_POST[’interests’] contains the value of only the first check box selected; all others are ignored. The PHP code inside each check box element performs the same role as in the radio button group, wrapping the checked attribute in a conditional statement. The first two conditions are the same as for a radio button, but the third condition uses the in_array() function to check whether the value associated with that check box is in the $_POST[’interests’] subarray. If it is, it means the check box was selected. 145
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Leave a Reply