3

I'm creating a dynamic form in Silex that alters depending on need.

If $disabled = 'true'

How would I change:

$form = $app['form.factory']->createBuilder('form')

->add('email', 'email', array(
    'data' => $from
))

to

$form = $app['form.factory']->createBuilder('form')

->add('email', 'email', array(
    'disabled' => true,
    'data' => $from
))
1
  • 1
    Just a general comment - be careful with true as a boolean value and 'true' as a string. You seem to use both, which is a way to fail somewhere. And the answer below also compares potentially boolean value with string, which is wrong. Commented Apr 27, 2015 at 13:24

1 Answer 1

2

You could accomplish it like this:

$form = $app['form.factory']->createBuilder('form');

$options = array(
    'data' => $from
);

if($disabled == 'true'){
    $options['disabled'] = true;
}

$form->add('email', 'email', $options)
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.