/** * @return Form * * @throws UnexpectedElementException If the form attribute does not target a form. * @throws NoSuchElementException IF the element does not belong to a form. */ public function getForm() { $element = $this->element->getDomElement(); $document = $element->ownerDocument; if ($element->hasAttribute('form')) { $form = $document->getElementById($element->getAttribute('form')); if (!$form) { throw new NoSuchElementException('Element has a form attribute that targets an id that does not exist'); } if (strtolower($form->tagName) != 'form') { throw new UnexpectedElementException('Element has a form attribute that does not target a form'); } $form = new Element($form); } else { $form = $this->element->getParent('form'); } return Form::create($form); }
/** * @param Wrapper\Form $form * * @return static */ private function submitForm(Wrapper\Form $form) { $url = $this->httpClient->getAbsoluteUrl($form->getAction()); $headers = ['Referer' => $this->getUrl()]; if ($form->isPost()) { parse_str($form->getRawData(), $post); $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } else { $url = $this->removeQueryString($url) . '?' . $form->getRawData(); $post = []; } $request = $this->httpClient->createRequest($form->getMethod(), $url, $post, [], $headers); $this->request($request, true, true); return $this; }