Gets the form node associated with this form.
public getFormNode ( ) : DOMElement | ||
return | DOMElement | A \DOMElement instance |
public function testGetFormNode() { $dom = new \DOMDocument(); $dom->loadHTML('<html><form><input type="submit" /></form></html>'); $form = new Form($dom->getElementsByTagName('input')->item(0)); $this->assertSame($dom->getElementsByTagName('form')->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form'); }
/** * @param Form $form * * @return ModuleList */ public static function createFromForm(Form $form) { $node = new Crawler($form->getFormNode()); // Example: <input type="checkbox" id="edit-modules-other-oxygen-enable" name="modules[Other][oxygen][enable]" value="1" class="form-checkbox" /> $inputs = $node->filter('input[type="checkbox"][id^="edit-modules-"]'); $modules = []; foreach ($inputs as $input) { /** @var \DOMElement $input */ if (!$input->hasAttribute('name')) { continue; } $enabled = $input->hasAttribute('checked'); $match = preg_match('{^modules\\[([^\\]]+)\\]\\[([^\\]]+)\\]\\[enable\\]$}', $input->getAttribute('name'), $matches); if (!$match) { continue; } list(, $package, $slug) = $matches; $modules[] = new ModuleListItem($package, $slug, $enabled); } return new self($modules); }
/** * @param Form $form * * @return Crawler */ protected function submitForm(Form $form) { $action = $form->getFormNode()->getAttribute('data-action'); $form->getFormNode()->setAttribute('action', $action); return $this->client->submit($form); }
public function testSubmitWithoutAFormButton() { $dom = new \DOMDocument(); $dom->loadHTML(' <html> <form> <input type="foo" /> </form> </html> '); $nodes = $dom->getElementsByTagName('form'); $form = new Form($nodes->item(0), 'http://example.com'); $this->assertSame($nodes->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form'); }
private function submit(Form $form) { $formId = $this->getFormNodeId($form->getFormNode()); if (isset($this->forms[$formId])) { $this->mergeForms($form, $this->forms[$formId]); } // remove empty file fields from request foreach ($form->getFiles() as $name => $field) { if (empty($field['name']) && empty($field['tmp_name'])) { $form->remove($name); } } foreach ($form->all() as $field) { // Add a fix for https://github.com/symfony/symfony/pull/10733 to support Symfony versions which are not fixed if ($field instanceof TextareaFormField && null === $field->getValue()) { $field->setValue(''); } } $this->client->submit($form); $this->forms = array(); }