How to receive check box information in PHP development

Source: Internet
Author: User
Tags array explode return
check box PHP receives multiple checkbox information that is not automatically converted to an array as an ASP, which is inconvenient to use. But there is a solution, is to use JavaScript to do the preprocessing. Multiple check boxes with the same name exist in JavaScript or as an array, so you can use JavaScript to synthesize an array of characters in a check box to a hidden element in the form, and then parse the array with the EXPLODE function in PHP, before submitting the form. This enables the delivery of check box information. The following examples illustrate.

Suppose there is such a form:

1

2

3

4


This form has four names that are item check boxes, and when the user clicks the Submit button, the checker function is invoked, and if the checker returns true the form is submitted, the return false form will not be submitted. Here the checker function is the preprocessing function we want to write. Add the following JavaScript to the header portion of the HTML:


This allows you to combine the value of all selected check boxes into an array of strings, using such statements in myphp.php:

$items = Explode ("", $HTTP _post_vars["items"));


You can separate these options into arrays. Note that value in the option cannot contain a delimiter (here is a space).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.