Exemplo n.º 1
0
<?php

$site = file_get_contents('http://www.gmail.com');
$dom = new DOMDocument();
$dom->loadHTML($site);
$xpath = new DOMXpath($dom);
$form = new RemoteForm($xpath->query('//form[@name="gaia_loginform"]')->item(0));
$form->setAttributeByName('Email', '*****@*****.**');
$form->setAttributeByName('Passwd', 'mypass');
var_dump($form->getParameters());
Exemplo n.º 2
0
 /**
  * Submits the given form.
  *
  * If $submitButtonName is given, that name is also submitted as a POST/GET value
  * This is available since some forms act differently based on which submit button
  * you press
  * @param RemoteForm $form The form to submit
  * @param String $submitButtonName The submit button to click
  * @return Browser Returns this browser object for chaining
  */
 public function submitForm(RemoteForm $form, $submitButtonName = '')
 {
     // Find the button, and set the given attribute if we're pressing a button
     if (!empty($submitButtonName)) {
         $button = $this->_navigator->query("//input[@type='submit'][@name='" . str_replace("'", "\\'", $submitButtonName) . "']");
         if ($button->length === 1) {
             $form->setAttributeByName($submitButtonName, $button->item(0)->getAttribute('value'));
         }
     }
     // Handle get/post
     switch (strtolower($form->getMethod())) {
         case 'get':
             /**
              * If we're dealing with GET, we build the query based on the
              * parameters that RemoteForm finds, and then navigate to
              * that URL
              */
             $questionAt = strpos($form->getAction(), '?');
             if ($questionAt === false) {
                 $questionAt = strlen($form->getAction());
             }
             $url = substr($form->getAction(), 0, $questionAt);
             $url = $this->_resolveUrl($url);
             $url .= '?' . http_build_query($form->getParameters());
             $this->navigate($url);
             break;
         case 'post':
             /**
              * If we're posting, we simply build a query string, and
              * pass that as the post data to the Curl HTTP client's
              * post handler method. Then we handle the response.
              */
             $this->_handleResponse($this->_curl->send_post_data($this->_resolveUrl($form->getAction()), $form->getParameters()), $form->getAction());
             break;
     }
     // Chain
     return $this;
 }