mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Fix set_checkbox() and set_radio() default checked. Fixes #3228
This commit is contained in:
parent
bbf57413a4
commit
3cccf2146a
@ -843,7 +843,7 @@ if (! function_exists('set_checkbox'))
|
||||
}
|
||||
|
||||
// Unchecked checkbox and radio inputs are not even submitted by browsers ...
|
||||
if (intval($input) === 0 || ! empty($request->getPost()) || ! empty(old($field)))
|
||||
if ((string) $input === '0' || ! empty($request->getPost()) || ! empty(old($field)))
|
||||
{
|
||||
return ($input === $value) ? ' checked="checked"' : '';
|
||||
}
|
||||
@ -895,7 +895,7 @@ if (! function_exists('set_radio'))
|
||||
|
||||
// Unchecked checkbox and radio inputs are not even submitted by browsers ...
|
||||
$result = '';
|
||||
if (intval($input) === 0 || ! empty($input = $request->getPost($field)) || ! empty($input = old($field)))
|
||||
if ((string) $input === '0' || ! empty($input = $request->getPost($field)) || ! empty($input = old($field)))
|
||||
{
|
||||
$result = ($input === $value) ? ' checked="checked"' : '';
|
||||
}
|
||||
|
@ -745,6 +745,9 @@ EOH;
|
||||
|
||||
$_SESSION = [];
|
||||
$this->assertEquals('', set_checkbox('foo', 'bar'));
|
||||
|
||||
$_SESSION = [];
|
||||
$this->assertEquals(' checked="checked"', set_checkbox('foo', 'bar', true));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -772,6 +775,9 @@ EOH;
|
||||
|
||||
$_SESSION = [];
|
||||
$this->assertEquals('', set_checkbox('foo', 'bar'));
|
||||
|
||||
$_SESSION = [];
|
||||
$this->assertEquals(' checked="checked"', set_checkbox('foo', '0', true));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -803,6 +809,7 @@ EOH;
|
||||
$_POST['bar'] = 'baz';
|
||||
$this->assertEquals(' checked="checked"', set_radio('bar', 'baz'));
|
||||
$this->assertEquals('', set_radio('bar', 'boop'));
|
||||
$this->assertEquals(' checked="checked"', set_radio('bar', 'boop', true));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -814,6 +821,9 @@ EOH;
|
||||
$_POST['bar'] = 0;
|
||||
$this->assertEquals(' checked="checked"', set_radio('bar', '0'));
|
||||
$this->assertEquals('', set_radio('bar', 'boop'));
|
||||
|
||||
$_POST = [];
|
||||
$this->assertEquals(' checked="checked"', set_radio('bar', '0', true));
|
||||
}
|
||||
|
||||
public function testSetRadioFromPostArray()
|
||||
|
Loading…
x
Reference in New Issue
Block a user