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 回答