jayjay76 Posted October 11, 2007 Share Posted October 11, 2007 I am trying to figure out how to detect a <Form> check box being checked in a PHP script. Likewise, I am trying to figure out how to detect which option was chosen in a <option> list of drop-down items in a form. For example, a simplistic form would be something like: <Form Method="Post" Action="./php/test.php"> <Center> <Table Width='333' border='0' CellPadding='0' CellSpacing='0' bgcolor='#53B5FD'> <TR> <TD><B>Order Type: </td> <TD><div align='right'> <select name='type'> <option value='test1' selected>Test 1</option> <option value='test2'>Test 2</option> <option value='test3'>Test 3</option> </select></div></td> </tr> <TR> <TD><input type='checkbox' name='checktest1' value='On'>Check Me 1</td> <TD><input type='checkbox' name='checktest2' value='On'>Check Me 2</td> <TD><input type='checkbox' name='checktest3' value='On'>Check Me 3</td> </tr> </table> <Center><input type=submit value='Test'>         <input type=reset value='Clear'></center> </form> and the associated test.php file . . . <?php $optiontype = $_POST['type']; $checktype1 = $_POST['checktest1']; $checktype2 = $_POST['checktest2']; $checktype3 = $_POST['checktest3']; Option: $optiontype \n Check: $ \n ?> In this, I am assuming I need to test for "on" or "off" properties of each checktype on the form, and then only set 'Check' to which ones the person actually checked? This is confusing me greatly Quote Link to comment https://forums.phpfreaks.com/topic/72787-solved-detecting-checkboxes-and-option-lists/ Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 checkboxes are not posted if they aren't checked... therefor if (isset($_POST["checkbox1"])) is sufficient to see if its checked and for <selects> $optiontype = $_POST['type']; will indeed return the XXXX in <option value='XXXX'> ... tdw Quote Link to comment https://forums.phpfreaks.com/topic/72787-solved-detecting-checkboxes-and-option-lists/#findComment-367088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.