Get check box value if checked

后端 未结 3 1550
执念已碎
执念已碎 2021-01-16 04:21

I\'m building a form using HTML with JQuery mobile so that the form can be used on mobile devices.

I have the form exporting to CSV via email. However the write to t

3条回答
  •  半阙折子戏
    2021-01-16 04:44

    Change your HTML and give a name attribute to all your checkboxes, like so:

    Multi select:

    Once the form has been submitted, the name attributes will be passed as array and they'll be accessible using the same variable. Now, you can use isset() to check if a particular item was set:

    if(isset($_POST['checkbox'])) {
      print_r($_POST); //print all checked elements
    }
    

    If you want to get the number of checkboxes that were checked, you can use count():

    $number = count($_POST['checkbox']);
    

    Note: currently, only the first element has a value attribute. You'll have to add it for the rest of the checkboxes for it to work properly.

    Hope this helps!

提交回复
热议问题