3

I am using DOMCrawler in PHP. I have the HTML below. I need to be able to select the option "Text1", and submit the form. I have the following code but I can't seem to make it work... What am I doing wrong?

use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'http://myURL');
$form = $crawler->selectButton('Text1')->form();   
$crawler2 = $client->submit($form);

This is the HTML:

<form action="something.php" name="frmOpcion" id="frmOpcion" method="post" enctype="multipart/form-data">

<select name="cmbOpcion" id="cmbOpcion" class="textoCmb">
<option value="a">Text1</option>
<option selected="selected" value="b">Text2</option>
</select>

<input type="image" name="imgOpcion" id="imgOpcion" alt="Send" title="Send" src="goTo.gif">

</form>
Prem
  • 65
  • 3
  • 7

1 Answers1

1

The documentation gives this example:

// Select an option or a radio
$form['country']->select('France');

To adapt the example to your situation, first select the form. Note that selectButton() is for buttons and inputs, not select controls:

$form = $crawler->selectButton('imgOpcion');

Next, set the value of the select:

$form->select('Text1');

Finally, submit the form:

$client->submit($form)
George Cummins
  • 28,485
  • 8
  • 71
  • 90