I\'m creating a form in Symfony2. The form only contains one book
field which allows the user to choose between a list of Books
entities. I need to c
Well, I'm not that familier with the Form/Validation component, but you can use a Hidden field with the name/id of the author and check if it's the same:
class MyFormType extends AbstractType
{
protected $author;
public function __construct(Author $author) {
$this->author = $author;
}
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('book', 'entity', array('class' => 'AcmeDemoBundle:Book', 'field' => 'title');
->add('author_name', 'hidden', array(
'data' => $this->author->getId(),
))
;
}
// ...
}