diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index bcc5088..51ad68e 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -420,11 +420,13 @@ class HtmlBuilder */ protected function attributeElement($key, $value) { - // For numeric keys we will assume that the key and the value are the same - // as this will convert HTML attributes such as "required" to a correct - // form like required="required" instead of using incorrect numerics. + // For numeric keys we will assume that the value is a boolean attribute + // where the presence of the attribute represents a true value and the + // absence represents a false value. + // This will convert HTML attributes such as "required" to a correct + // form instead of using incorrect numerics. if (is_numeric($key)) { - $key = $value; + return $value; } if (! is_null($value)) { diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index ee8ac49..24fa70b 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -11,6 +11,10 @@ use Mockery as m; class FormBuilderTest extends PHPUnit_Framework_TestCase { + /** + * @var FormBuilder + */ + private $formBuilder; /** * Setup the test environment. @@ -520,6 +524,15 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('', $form3); } + public function testBooleanAttributes() + { + $input = $this->formBuilder->text('test', null, ['disabled']); + $this->assertEquals('', $input); + + $input = $this->formBuilder->textarea('test', null, ['readonly']); + $this->assertEquals('', $input); + } + protected function setModel(array $data, $object = true) { if ($object) {