cakestar Posted October 15, 2010 Share Posted October 15, 2010 Hello all, I would like to display a disabled checkbox with its value set from the database. I have tried the following: <?php echo $form->checkbox($post['Post']['flag'], array('disabled'=>'true'));?> <?php echo $form->checkbox(‘Post.flag.$post['Post']['flag'], array(‘value’ => $post['Post']['flag']));?> The first statement shows me a disabled checkbox and if I view the source I have a hidden checkbox as well but none are being passed the value of the field from the database. <input type="hidden" id="" disabled="disabled" value="0" name="data[]"> <input type="checkbox" id="" value="1" disabled="disabled" name="data[]"> The second statement shows this: <input type="checkbox" id="‘Postflag0" value="1" ‘value’="0" name="data[‘Postflag0]"> Now I've changed it slightly to: <?php echo $form->checkbox(Post.flag.$post['Post']['flag'], array(value => $post['Post']['flag']));?> These don't work either: <input type="hidden" name="data[Postflag0]" id="Postflag0_" value="0" /> <input type="checkbox" name="data[Postflag0]" value="1" id="Postflag0" /> I want to be able to show a disabled checkbox with a value of checked or not depending on it's value in the database. Any idea how I can get this to work? Link to comment https://forums.phpfreaks.com/topic/215923-disabled-checkbox-in-cakephp/ Share on other sites More sharing options...
Pikachu2000 Posted October 15, 2010 Share Posted October 15, 2010 If the checkbox is to be pre-checked, you need to insert checked="checked" in the tag. Link to comment https://forums.phpfreaks.com/topic/215923-disabled-checkbox-in-cakephp/#findComment-1122593 Share on other sites More sharing options...
cakestar Posted October 18, 2010 Author Share Posted October 18, 2010 Your dead right I would need that in the code somewhere, but more importantly I would need to pass a value to it whether or not it needed to be checked or not. thks for your reply tho Link to comment https://forums.phpfreaks.com/topic/215923-disabled-checkbox-in-cakephp/#findComment-1123585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.