symfony/symfony — pull request #11712 by pylebecq (2014-08-19 22:15:33+00:00)
Title: [WIP][DomCrawler] Allow missing fields creation

This is an attempt to fix #3824

I know it is not implemented the way Fabien meant but I wanted to know what you think about this little experiment.

I basically implemented it as I did the disable validation feature. You have a new `Form::createMissingFields()` method that you can call and it will be able to create the field you want instead of throwing an exception when accessing it.
The created field is in fact an `UnresolvedFormField` (to be renamed I think) for now because at this point, I don't know what kind of field you want.

This class implements the methods that other fields implements and will put in the form a field corresponding to the type you are trying to use. If it does not make sense to you, here is an exemple that may be able to help:

```php
$form = $crawler->selectButton('submit')->form();
$form->createMissingFields(); // Allow the creation of missing fields

$field = $form['foo']; // $field is an instance of UnresolvedFormField. Nothing has been added in the form yet.
$field = 'test'; // an InputFormField is added to the form, containing the value 'test'.
// or
$field->setValue('test'); // same as above

$form['bar']->select('test'); // creates a ChoiceFormField corresponding to a multiple select, with validation disabled (in case you want to select more than one value)
$form['baz']->tick(); // creates a ChoiceFormField corresponding to a ticked checkbox
$form['myfile']->upload('/tmp/upload.zip'); // creates a FileFormField uploading the given file
```

I wanted to know what you guys think about that, or if you prefer to go for what Fabien said which is to write some convenient methods to add nodes to the crawler to be used prior to the call to `->form()`.
And I don't know if it's just me but this implementation feels kind of "wrong" to me because I think maybe some code is not as the right place but I don't want to over-complicate the DomCrawler component.

And I know, phpdoc is missing, more unit tests maybe, etc.

Well I don't know, just tell me what you think about all of this.