symfony creating custom form types

Solutions on MaxInterview for symfony creating custom form types by the best coders in the world

showing results for - "symfony creating custom form types"
Joris
02 Mar 2018
1// src/Form/Type/OrderType.php
2namespace App\Form\Type;
3
4use App\Form\Type\ShippingType;
5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\FormBuilderInterface;
7
8class OrderType extends AbstractType
9{
10    public function buildForm(FormBuilderInterface $builder, array $options)
11    {
12        $builder
13            // ...
14            ->add('shipping', ShippingType::class)
15        ;
16    }
17
18    // ...
19}
20
Josué
20 Feb 2020
1// src/Form/Type/ShippingType.php
2namespace App\Form\Type;
3
4use Symfony\Component\Form\AbstractType;
5use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
6use Symfony\Component\OptionsResolver\OptionsResolver;
7
8class ShippingType extends AbstractType
9{
10    public function configureOptions(OptionsResolver $resolver)
11    {
12        $resolver->setDefaults([
13            'choices' => [
14                'Standard Shipping' => 'standard',
15                'Expedited Shipping' => 'expedited',
16                'Priority Shipping' => 'priority',
17            ],
18        ]);
19    }
20
21    public function getParent()
22    {
23        return ChoiceType::class;
24    }
25}
26