Reputation: 4515
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
))
Upvotes: 3
Views: 65
Reputation: 3080
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)
Upvotes: 2