[eluser]krif[/eluser]
It might be me using the function wrong but when I call the set_checkbox of the Form Helper library without having post variables yet, it always returns a 'checked="checked"'
As far as I see it, the problem is that the function checks if set_checkbox() has not yet been defined by the Form Validation library yet, then looks for the validation object and post field data but if all those return FALSE or 0 resp. then returns checked even if the third parameter was set to FALSE or not defined.
This is the original code:
Code:
if ( ! function_exists('set_checkbox'))
{
function set_checkbox($field = '', $value = '', $default = FALSE)
{
$OBJ =& _get_validation_object();
if ($OBJ === FALSE)
{
if ( ! isset($_POST[$field]))
{
if (count($_POST) === 0)
{
return ' checked="checked"';
}
return '';
}
but I guess it should be more something like see the added "$default === TRUE AND " in line 11, or line 687 of the Form Helper library in CI 1.7.0:
Code:
if ( ! function_exists('set_checkbox'))
{
function set_checkbox($field = '', $value = '', $default = FALSE)
{
$OBJ =& _get_validation_object();
if ($OBJ === FALSE)
{
if ( ! isset($_POST[$field]))
{
if ($default === TRUE AND count($_POST) === 0)
{
return ' checked="checked"';
}
return '';
}