Guest User

Untitled

a guest
Oct 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public function buildForm(FormBuilderInterface $builder, array $options)
  2. {
  3.  
  4. $builder
  5. ->add('contacts', ChoiceType::class, [
  6. 'label' => 'Contact',
  7. 'placeholder' => 'Choose a contact',
  8. 'choices' => $this->getContacts(),
  9. 'mapped' => false,
  10. ])
  11. ->setMethod('POST')
  12. ;
  13.  
  14. $builder->get('contacts')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  15.  
  16. $contactId = $event->getData();
  17. $parentForm = $event->getForm()->getParent();
  18.  
  19. $contactEntity = $exampleEm->getrepository(Contact::class)->find($contactId);
  20. $firstName = $contactEntity->getFirstName();
  21.  
  22. // where can I set the 'contactFirstname' data ?
  23.  
  24. $parentForm
  25. ->add('contactFirstname', TextType::class, [
  26. 'label' => 'First name',
  27. ]);
  28. })
  29. ;
  30. }
Add Comment
Please, Sign In to add comment