FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Use form submission, HTML elements use visibility:hidden;The Form object cannot get the element value #391

Open popfaker opened 4 years ago

popfaker commented 4 years ago
<form action="test.php" method="post">
   <p><input type="text" name="name" value=""  /></p>
   <p><input type="text" name="passwd" value=""  /></p>
   <p style="visibility:hidden;"><input type="text" name="area" value="-1"  /></p>
  <p><input type="image" id="btn" src="" /></p>
</form>
  $crawler = $client->request('GET', 'http://xxxx.com/');
  $form = $crawler->selectButton('btn')->form();
  dd($form->get('area')->getValue());

The expected results

print -1

The actual results

print NULL

The solution

        $crawler = $client->request('GET', 'http://xxxx.com/');
        $form = $crawler->selectButton('btn')->form();
        $form->disableValidation();
        $form->get('area')->setValue('-1');
        dd($form->get('area')->getValue());