I have a problem regarding the validation of form children. I have a type that contains several types of another type. This subtype requires one field, one of which is not required. But both of them are empty, the form is verified. Here are my classes
class PassengerList { protected $passengers; protected $passengers_child; protected $passengers_baby; }
passengerListType
class PassengerListType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder->add('passengers','collection', array( 'type' => new PassengerType(), 'allow_add' => false, 'required'=> true, 'allow_delete' => false)); $builder->add('passengers_child','collection', array( 'type' => new PassengerChildType(), 'allow_add' => true, 'allow_delete' => false)); $builder->add('passengers_baby','collection', array( 'type' => new PassengerBabyType(), 'allow_add' => true, 'allow_delete' => false)); } function getName() { return 'passenger_list'; } }
PassengerType
class PassengerType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $date_params = array("widget"=>"single_text","input"=>"datetime",'format' => 'dd-MM-yyyy',); $builder ->add('civility', 'choice', array("choices"=>Passenger::getCivilityList())) ->add('birthdate','date',$date_params) ->add('last_name','text',array('required'=>true)) ->add('first_name','text',array('required'=>false)) ->add('type','hidden'); } function getName() { return 'passenger'; } public function getDefaultOptions(array $options) { return array( 'data_class' => 'Travelyo\CoreBundle\Entity\Passenger', ); } }
which give me this form:
But when validating a form with $ form-> isValid (), the return value is true, although I leave both fields blank.
I have the feeling that the problem is that nothing is being tested on chidlren types.
Do you have any sheets that can help me?