diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 62fa0bb8e0..c4807313d9 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.12 under development -------------------------- +- Bug #7946 Fixed a bug when the `form` attribute was not propagated to the hidden input of the checkbox (Kolyunya) - Bug #13087: Fixed getting active validators for safe attribute (developeruz) - Bug #13571: Fix `yii\db\mssql\QueryBuilder::checkIntegrity` for all tables (boboldehampsink) - Bug #11230: Include `defaultRoles` in `yii\rbac\DbManager->getRolesByUser()` results (developeruz) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index 6e6a9c27df..4702aff4e1 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -60,6 +60,7 @@ class BaseHtml 'href', 'src', 'srcset', + 'form', 'action', 'method', @@ -742,7 +743,11 @@ class BaseHtml $value = array_key_exists('value', $options) ? $options['value'] : '1'; if (isset($options['uncheck'])) { // add a hidden field so that if the checkbox is not selected, it still submits a value - $hidden = static::hiddenInput($name, $options['uncheck']); + $hiddenOptions = []; + if (isset($options['form'])) { + $hiddenOptions['form'] = $options['form']; + } + $hidden = static::hiddenInput($name, $options['uncheck'], $hiddenOptions); unset($options['uncheck']); } else { $hidden = ''; diff --git a/tests/framework/helpers/HtmlTest.php b/tests/framework/helpers/HtmlTest.php index be457c6835..55e74ec00b 100644 --- a/tests/framework/helpers/HtmlTest.php +++ b/tests/framework/helpers/HtmlTest.php @@ -378,6 +378,13 @@ class HtmlTest extends TestCase 'label' => 'ccc', 'value' => 2, ])); + $this->assertEquals('', Html::checkbox('test', true, [ + 'class' => 'a', + 'uncheck' => '0', + 'label' => 'ccc', + 'value' => 2, + 'form' => 'test-form', + ])); } public function testDropDownList()