Guest User

Untitled

a guest
Jan 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. // ContactsController.php
  2. $addresses = $this->get('app.cotnacts_model')->getAddresses($clientid);
  3.  
  4. $addresschoices = [];
  5. $i = 0;
  6. foreach ($addresses as $t) {
  7. $addresschoices[$t['address']] = $i;
  8. $i = $i + 1;
  9. }
  10.  
  11. $form = $this
  12. ->createForm(AddContactpersonForm::class, [
  13. 'adreskeuzes' => [$addresschoices]
  14. ])
  15. ->handleRequest($request);
  16.  
  17. [street <nr>, <postalcode> <city> => 0
  18. [street <nr>, <postalcode> <city> => 1
  19. etc...
  20.  
  21. // AddContactpersonForm.php
  22. class AddContactpersonForm extends AbstractType
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function buildForm(FormBuilderInterface $builder, array $options)
  28. {
  29. $builder
  30. ->add('persoonlijk', PersoonlijkType::class)
  31. ->add('zakelijk', ZakelijkType::class)
  32. ->add('OPSLAAN', SubmitType::class, [
  33. 'label' => 'OPSLAAN',
  34. 'attr' => [
  35. 'class' => 'button'
  36. ]
  37. ])
  38. ->add('ANNULEREN', SubmitType::class, [
  39. 'label' => 'ANNULEREN',
  40. 'attr' => [
  41. 'class' => 'button-outline'
  42. ]
  43. ]);
  44. }
  45. public function configureOptions(OptionsResolver $resolver)
  46. {
  47. $resolver->setDefaults([
  48. ]);
  49. }
  50. }
  51.  
  52. class PersoonlijkType extends AbstractType
  53. {
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function buildForm(FormBuilderInterface $builder, array $options)
  58. {
  59. // first part of form
  60. }
  61.  
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getBlockPrefix()
  66. {
  67. return 'appbundle_form_addcontactpersoonlijkform';
  68. }
  69. }
  70.  
  71. class ZakelijkType extends AbstractType
  72. {
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function buildForm(FormBuilderInterface $builder, array $options)
  77. {
  78. $builder
  79. // some fields
  80. ->add('adres2', ChoiceType::class, [
  81. 'choices' => $options['addresschoices'],
  82. 'expanded' => false,
  83. 'required' => false,
  84. 'label' => 'Address',
  85. 'attr' => [
  86. 'class' => 'form-control'
  87. ]
  88. ])
  89. // some other fields
  90. }
  91.  
  92. public function configureOptions(OptionsResolver $resolver)
  93. {
  94. $resolver->setDefaults([
  95. 'addresschoices' => null
  96. ]);
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. public function getBlockPrefix()
  102. {
  103. return 'appbundle_form_addcontactzakelijkform';
  104. }
  105. }
Add Comment
Please, Sign In to add comment