0

I've got form class where I'm defining some inputs, something liek this:

class User extends AbstractType
{

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('mail', 'text', array('label' => 'Mail'))
                ->add('password', 'text', array('label' => 'Hasło'))
                ->add('description', 'textarea', array('label' => 'Opis'));
    }
}

I want to change mail and password input type to readonly and set them some values. Now, I use form this way:

$form = $this->createForm(new User($this->get('database_connection')));

I tried many things, but Symfony2 has so many Form classes and I've lost in that. I want to simply add some atributes to existing, added inputs. I don't use Doctrine2 ORM, I use Doctrine DBAL, if it does matter.

Thanks in advance.

pamil
  • 980
  • 2
  • 10
  • 20
  • You should not display a password anyway and store it encrypted in your database. – fdomig Jul 09 '12 at 08:47
  • @fdomig This is admin panel to script, whose login at other site so I must store it unhashed, encryption here is overkill ;) – pamil Jul 09 '12 at 09:00

1 Answers1

4

your can set default value with 'data' parameter and readonly with attr parameter

$builder
    ->add('mail', 'text', array('label' => 'Mail', 'data' => 'Default value'
           attr => array('readonly=>'readonly')));
Anil Gupta
  • 2,329
  • 4
  • 24
  • 30