使用FormBuilder symfony更改表单名称

时间:2018-09-09 16:22:02

标签: symfony twig formbuilder

我有一个问题,我知道我可以使用FromFactoryInterface设置表单名称,但是如何使用FormBuilder做到这一点?这将获得类的名称并从中生成自动名称,我如何将其更改为我的指定名称?

表单类型:

    <?php

class ProfileAddPracownikType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder

            ->add('username', null, [
            'label_attr' => array('class' => 'bmd-label-floating'),
            'label' => 'Nazwa użytkownika',
            'mapped' => false,
            'attr' => ['class' => 'form-control']])     
            ->add('imie', null, [
            'label_attr' => array('class' => 'bmd-label-floating'),
            'label' => 'Imię',
            'mapped' => false,
            'data' => $options['imie'],
            'attr' => ['class' => 'form-control']])
            ->add('nazwisko', null, [
            'label_attr' => array('class' => 'bmd-label-floating'),
            'label' => 'Nazwisko',
            'mapped' => false,
            'data' => $options['nazwisko'],
            'attr' => ['class' => 'form-control']])
            ->add('telefon', null, [
            'label_attr' => array('class' => 'bmd-label-floating'),
            'label' => 'Numer telefonu',
            'mapped' => false,
            'data' => $options['telefon'],
            'attr' => ['class' => 'form-control']])
            ->add('email', null, [
            'label_attr' => array('class' => 'bmd-label-floating'),
            'label' => 'Adres e-mail',
            'mapped' => false,
            'data' => $options['email'],
            'attr' => ['class' => 'form-control']]) 
            ->add('password', RepeatedType::class, array(
                    'type' => PasswordType::class,
                    'invalid_message' => 'Hasła muszą być takie same.',
                    'options' => array('attr' => array('class' => 'password-field')),
                    'required' => false,
                    'first_options'  => array('label' => 'Hasło (jeżeli pozostawisz to pola puste hasło nie zmieni się)','attr' => ['class' => 'form-control'],'label_attr' => ['class' => 'bmd-label-floating']),
                    'second_options' => array('label' => 'Powtórz hasło','attr' => ['class' => 'form-control'],'label_attr' => ['class' => 'bmd-label-floating']),
                    'mapped' => false,


                ))          
            ->add('avatar', FileType::class, [
            'label_attr' => array('class' => 'bmd-label-floating'),
            'label' => 'Wgraj lub aktualizuj avatar (jeżeli nie wgrasz pliku pozostanie standardowy obrazek)',
            'mapped' => false,
            'required' => false,
            'data' => $options['avatar'],
            'attr' => ['class' => 'form-control']])         
            ->add('save', SubmitType::class, [
            'label' => 'Zapisz profil',
            'attr' => ['class' => 'btn btn-primary pull-right']])   

        ;
    }

}

在控制器内部建立表单:

$form_profile = $this->createForm(ProfileAddPracownikType::class, $request, array());

0 个答案:

没有答案