diff --git a/src/Symfony/Component/DomCrawler/Field/FormField.php b/src/Symfony/Component/DomCrawler/Field/FormField.php index c3a9286412..b21bb38ea8 100644 --- a/src/Symfony/Component/DomCrawler/Field/FormField.php +++ b/src/Symfony/Component/DomCrawler/Field/FormField.php @@ -23,6 +23,7 @@ abstract class FormField protected $value; protected $document; protected $xpath; + protected $disabled; /** * Constructor. @@ -86,6 +87,11 @@ abstract class FormField return true; } + public function isDisabled() + { + return $this->node->hasAttribute('disabled'); + } + /** * Initializes the form field. */ diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index d02345bf52..d81e072a6c 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -83,6 +83,10 @@ class Form extends Link implements \ArrayAccess { $values = array(); foreach ($this->fields as $name => $field) { + if ($field->isDisabled()) { + continue; + } + if (!$field instanceof Field\FileFormField && $field->hasValue()) { $values[$name] = $field->getValue(); } @@ -106,6 +110,10 @@ class Form extends Link implements \ArrayAccess $files = array(); foreach ($this->fields as $name => $field) { + if ($field->isDisabled()) { + continue; + } + if ($field instanceof Field\FileFormField) { $files[$name] = $field->getValue(); } diff --git a/tests/Symfony/Tests/Component/DomCrawler/FormTest.php b/tests/Symfony/Tests/Component/DomCrawler/FormTest.php index bd6964a7af..711489213c 100644 --- a/tests/Symfony/Tests/Component/DomCrawler/FormTest.php +++ b/tests/Symfony/Tests/Component/DomCrawler/FormTest.php @@ -73,10 +73,10 @@ class FormTest extends \PHPUnit_Framework_TestCase array(), ), array( - 'does not take into account disabled input fields', + 'takes into account disabled input fields', ' ', - array(), + array('foo' => array('Symfony\\Component\\DomCrawler\\Field\\InputFormField', 'foo')), ), array( 'appends the submitted button value', @@ -201,6 +201,9 @@ class FormTest extends \PHPUnit_Framework_TestCase $form = $this->createForm('
'); $this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include file input fields'); + + $form = $this->createForm('
'); + $this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include disabled fields'); } public function testSetValues() @@ -223,6 +226,9 @@ class FormTest extends \PHPUnit_Framework_TestCase $form = $this->createForm('
'); $this->assertEquals(array('foo[bar]' => array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0)), $form->getFiles(), '->getFiles() only returns file fields'); + + $form = $this->createForm('
'); + $this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include disabled file fields'); } public function testGetPhpFiles()