mATOK Posted October 13, 2006 Share Posted October 13, 2006 Hey there, I have a form full of checkboxes that sends its input to an array.I know that if a box is checked then the array reads 'on', otherwise I assume it will containe 'off'I'd like to know how I can convert all of the on's to 1's and the off's to 0'swould I use strcmp for this or is there a built in php function? Quote Link to comment Share on other sites More sharing options...
craygo Posted October 13, 2006 Share Posted October 13, 2006 if the box is checked it will give whatever value you tell it to give<input type=checkbox name=check1 value=heyheyhey>also realize if a box is not checked it will not pass anything. So if you try to echo out a checkbox than was not checked you will get an error.Ray Quote Link to comment Share on other sites More sharing options...
mATOK Posted October 13, 2006 Author Share Posted October 13, 2006 thank you, I did not realize that you could set the value of a check boxso could I then use<input type="checkbox" name="0" value="0" checked> Quote Link to comment Share on other sites More sharing options...
craygo Posted October 13, 2006 Share Posted October 13, 2006 no problem. Also I forgot to add, you can suppress the error by adding an @ in front of the variable. Here is a quick example.[code]<?phpif(isset($_POST['submit'])){echo @$_POST['check1']."---".@$_POST['check2'];} else {?><form name=form method=POST action=""> <input type=checkbox name=check1 value=3><br> <input type=checkbox name=check2 value=1><br> <input type=submit name=submit value=submit></form><?php}?>[/code]Now if you only check one box you will just get a blank for the box that was not checked. If you take away the "@" in front of the $_POST variables you will get an error for the box that was not checked.Just a little FYI for yaRay Quote Link to comment 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.