0

私はGoutte、https://github.com/fabpot/goutteを使用しており、次のコードがあります。

$client = new Client();

$crawler = $client->request('GET', \Config::get('Eload2::url'));

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

// add extra fields here

$client->submit($form);

フォームを送信する前に非表示の入力フィールドをフォームに追加するにはどうすればよいですか?

私は次のコードを試しました、

$domdocument = new \DOMDocument;

$formfield = new InputFormField ($domdocument->createElement('__EVENTTARGET', 'ctl00$ContentPlaceHolder1$DDLTelco'));

$formfield2 = new InputFormField ($domdocument->createElement('__EVENTARGUMENT',''));

$form->set($formfield); 

$form->set($formfield2);

しかし、次のエラー メッセージが返されます。

InputFormField は、入力タグまたはボタン タグ (__EVENTTARGET が指定されている) からのみ作成できます。

4

1 に答える 1

4

作成しているのは次のとおりです。

<__EVENTTARGET>ctl00$ContentPlaceHolder1$DDLTelco</__EVENTTARGET>
<__EVENTARGUMENT />

あなたが望む間:

<input name="__EVENTTARGET" value="ctl00$ContentPlaceHolder1$DDLTelco" />
<input name="__EVENTARGUMENT" value="" />

これを試して:

$ff = $domdocument->createElement('input');
$ff->setAttribute('name', '__EVENTTARGET');
$ff->setAttribute('value', 'ctl00$ContentPlaceHolder1$DDLTelco');
$formfield = new InputFormField($ff);

$ff = $domdocument->createElement('input');
$ff->setAttribute('name', '__EVENTTARGET');
$ff->setAttribute('value', '');
$formfield2 = new InputFormField($ff);
于 2014-09-16T13:12:41.110 に答える