开发者

how i can select multiple values from check box?

开发者 https://www.devze.com 2023-02-04 17:37 出处:网络
hi i have multiple option in check box and开发者_如何学JAVA when visitor or customer select multiple option then how i can get multiple values?plz explain with code thanksName the checkboxes with [] (

hi i have multiple option in check box and开发者_如何学JAVA when visitor or customer select multiple option then how i can get multiple values? plz explain with code thanks


Name the checkboxes with [] (or PHP will drop all but one of them (I don't recall if it is the first or last)).

<input type=checkbox name="foo[]" value="some value">

Then they will be accessible as an array in the $_GET or $_POST superglobal.

$_GET['foo'][]


Basically, set all the name tags to be the same for all your checkboxes (with []). Then in your script, the values will be available as an array

Html:

<input type="checkbox" name="tags[]" value="1" />
<input type="checkbox" name="tags[]" value="2" />
<input type="checkbox" name="tags[]" value="3" />
<input type="checkbox" name="tags[]" value="4" />

PHP:

print_r($_REQUEST['tags']);

Reference: http://www.kavoir.com/2009/01/php-checkbox-array-in-form-handling-multiple-checkbox-values-in-an-array.html


Like this

<input type="checkbox" name="foo[]" value="bar" />
<input type="checkbox" name="foo[]" value="baz" />
<input type="checkbox" name="foo[]" value="qux" />

<?php
    print_r($_POST['foo']);
0

精彩评论

暂无评论...
验证码 换一张
取 消