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 * FormField is the abstract class for all form fields.
17 * @author Fabien Potencier <fabien@symfony.com>
19 abstract class FormField
49 * @param \DOMElement $node The node associated with this field
51 public function __construct(\DOMElement $node)
54 $this->name = $node->getAttribute('name');
55 $this->xpath = new \DOMXPath($node->ownerDocument);
61 * Returns the label tag associated to the field or null if none.
63 * @return \DOMElement|null
65 public function getLabel()
67 $xpath = new \DOMXPath($this->node->ownerDocument);
69 if ($this->node->hasAttribute('id')) {
70 $labels = $xpath->query(sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
71 if ($labels->length > 0) {
72 return $labels->item(0);
76 $labels = $xpath->query('ancestor::label[1]', $this->node);
77 if ($labels->length > 0) {
78 return $labels->item(0);
85 * Returns the name of the field.
87 * @return string The name of the field
89 public function getName()
95 * Gets the value of the field.
97 * @return string|array The value of the field
99 public function getValue()
105 * Sets the value of the field.
107 * @param string $value The value of the field
109 public function setValue($value)
111 $this->value = (string) $value;
115 * Returns true if the field should be included in the submitted values.
117 * @return bool true if the field should be included in the submitted values, false otherwise
119 public function hasValue()
125 * Check if the current field is disabled.
129 public function isDisabled()
131 return $this->node->hasAttribute('disabled');
135 * Initializes the form field.
137 abstract protected function initialize();