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.

2
  • You should not display a password anyway and store it encrypted in your database. Commented Jul 9, 2012 at 8:47
  • @fdomig This is admin panel to script, whose login at other site so I must store it unhashed, encryption here is overkill ;) Commented Jul 9, 2012 at 9:00

1 Answer 1

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')));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.