1

I'm using Goutte, https://github.com/fabpot/goutte, and have the following code,

$client = new Client();

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

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

// add extra fields here

$client->submit($form);

how do I do to add hidden input fields to the form before it's submitted?

I tried the following code,

$domdocument = new \DOMDocument;

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

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

$form->set($formfield); 

$form->set($formfield2);

but the following error message is returned,

An InputFormField can only be created from an input or button tag (__EVENTTARGET given).

1 Answer 1

6

What you are creating is this:

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

While you want:

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

Try this:

$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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.