4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DomCrawler\Field;
15 * InputFormField represents an input form field (an HTML input tag).
17 * For inputs with type of file, checkbox, or radio, there are other more
18 * specialized classes (cf. FileFormField and ChoiceFormField).
20 * @author Fabien Potencier <fabien@symfony.com>
22 class InputFormField extends FormField
25 * Initializes the form field.
27 * @throws \LogicException When node type is incorrect
29 protected function initialize()
31 if ('input' !== $this->node->nodeName && 'button' !== $this->node->nodeName) {
32 throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
35 $type = strtolower($this->node->getAttribute('type'));
36 if ('checkbox' === $type) {
37 throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
40 if ('file' === $type) {
41 throw new \LogicException('File inputs should be instances of FileFormField.');
44 $this->value = $this->node->getAttribute('value');