Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ContactsController.php
- $addresses = $this->get('app.cotnacts_model')->getAddresses($clientid);
- $addresschoices = [];
- $i = 0;
- foreach ($addresses as $t) {
- $addresschoices[$t['address']] = $i;
- $i = $i + 1;
- }
- $form = $this
- ->createForm(AddContactpersonForm::class, [
- 'adreskeuzes' => [$addresschoices]
- ])
- ->handleRequest($request);
- [street <nr>, <postalcode> <city> => 0
- [street <nr>, <postalcode> <city> => 1
- etc...
- // AddContactpersonForm.php
- class AddContactpersonForm extends AbstractType
- {
- /**
- * {@inheritdoc}
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $builder
- ->add('persoonlijk', PersoonlijkType::class)
- ->add('zakelijk', ZakelijkType::class)
- ->add('OPSLAAN', SubmitType::class, [
- 'label' => 'OPSLAAN',
- 'attr' => [
- 'class' => 'button'
- ]
- ])
- ->add('ANNULEREN', SubmitType::class, [
- 'label' => 'ANNULEREN',
- 'attr' => [
- 'class' => 'button-outline'
- ]
- ]);
- }
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults([
- ]);
- }
- }
- class PersoonlijkType extends AbstractType
- {
- /**
- * {@inheritdoc}
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- // first part of form
- }
- /**
- * {@inheritdoc}
- */
- public function getBlockPrefix()
- {
- return 'appbundle_form_addcontactpersoonlijkform';
- }
- }
- class ZakelijkType extends AbstractType
- {
- /**
- * {@inheritdoc}
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $builder
- // some fields
- ->add('adres2', ChoiceType::class, [
- 'choices' => $options['addresschoices'],
- 'expanded' => false,
- 'required' => false,
- 'label' => 'Address',
- 'attr' => [
- 'class' => 'form-control'
- ]
- ])
- // some other fields
- }
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults([
- 'addresschoices' => null
- ]);
- }
- /**
- * {@inheritdoc}
- */
- public function getBlockPrefix()
- {
- return 'appbundle_form_addcontactzakelijkform';
- }
- }
Add Comment
Please, Sign In to add comment