@@ -769,12 +769,11 @@ function set_checkbox($field, $value = '', $default = FALSE)
769769 {
770770 return $ CI ->form_validation ->set_checkbox ($ field , $ value , $ default );
771771 }
772- elseif (($ input = $ CI ->input ->post ($ field , FALSE )) === NULL )
773- {
774- return ($ default === TRUE ) ? ' checked="checked" ' : '' ;
775- }
776772
773+ // Form inputs are always strings ...
777774 $ value = (string ) $ value ;
775+ $ input = $ CI ->input ->post ($ field , FALSE );
776+
778777 if (is_array ($ input ))
779778 {
780779 // Note: in_array('', array(0)) returns TRUE, do not use it
@@ -789,7 +788,13 @@ function set_checkbox($field, $value = '', $default = FALSE)
789788 return '' ;
790789 }
791790
792- return ($ input === $ value ) ? ' checked="checked" ' : '' ;
791+ // Unchecked checkbox and radio inputs are not even submitted by browsers ...
792+ if ($ CI ->input ->method () === 'post ' )
793+ {
794+ return ($ input === 'value ' ) ? ' checked="checked" ' : '' ;
795+ }
796+
797+ return ($ default === TRUE ) ? ' checked="checked" ' : '' ;
793798 }
794799}
795800
@@ -816,12 +821,32 @@ function set_radio($field, $value = '', $default = FALSE)
816821 {
817822 return $ CI ->form_validation ->set_radio ($ field , $ value , $ default );
818823 }
819- elseif (($ input = $ CI ->input ->post ($ field , FALSE )) === NULL )
824+
825+ // Form inputs are always strings ...
826+ $ value = (string ) $ value ;
827+ $ input = $ CI ->input ->post ($ field , FALSE );
828+
829+ if (is_array ($ input ))
830+ {
831+ // Note: in_array('', array(0)) returns TRUE, do not use it
832+ foreach ($ input as &$ v )
833+ {
834+ if ($ value === $ v )
835+ {
836+ return ' checked="checked" ' ;
837+ }
838+ }
839+
840+ return '' ;
841+ }
842+
843+ // Unchecked checkbox and radio inputs are not even submitted by browsers ...
844+ if ($ CI ->input ->method () === 'post ' )
820845 {
821- return ($ default === TRUE ) ? ' checked="checked" ' : '' ;
846+ return ($ input === ' value ' ) ? ' checked="checked" ' : '' ;
822847 }
823848
824- return ($ input === ( string ) $ value ) ? ' checked="checked" ' : '' ;
849+ return ($ default === TRUE ) ? ' checked="checked" ' : '' ;
825850 }
826851}
827852
0 commit comments