hgmme@wa Posted April 4, 2008 Share Posted April 4, 2008 How would you process a form like this checkbox example form, if multiple checkboxs are selected and all of them have the same name?I experimented (see below) and it doesn't seem to make an array with that name so what do you do? <form action="test.php" method="get"> <?php//I'll actually end up using the 'post' method. if ( isset($_GET['test']) ) { $n = 1; foreach ( $_GET['test'] as $test ) { echo "Value " . $n . ":" . $test; $n++; } } ?> <input type="checkbox" value="value1" name="test" /> <input type="checkbox" value="value2" name="test" /> <input type="checkbox" value="value3" name="test" /> <input type="submit" name="submit" /></form> Link to comment Share on other sites More sharing options...
Lulzim Posted April 4, 2008 Share Posted April 4, 2008 you just have to add a [] at the name of the checkbox, like this:<input type="checkbox" value="value2" name="test[]" />because that way you will get the value of the last checkbox onlyhere is the complete code <form action="test.php" method="get"> <?php//I'll actually end up using the 'post' method. if ( isset($_GET['test']) ) { $n = 1; foreach ( $_GET['test'] as $test ) { echo "Value " . $n . ":" . $test."<br>"; $n++; } } ?> <input type="checkbox" value="value1" name="test[]" /> <input type="checkbox" value="value2" name="test[]" /> <input type="checkbox" value="value3" name="test[]" /> <input type="submit" name="submit" /></form> Link to comment Share on other sites More sharing options...
hgmme@wa Posted April 4, 2008 Author Share Posted April 4, 2008 Hmm, ok. Thanks Lulsim. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.