/*Concidering $definitions = array("$form->add('email', 'text', array(
'constraints' => new Assert\Email()
));");
*/
$form = $app['form.factory']->createBuilder('form');
foreach($definitions as $definition){
eval($definition);
}
$form->getForm();
I would not recommend you use eval like so... You'd better store the parameters to pass to the function to make it work... You could also create a function or class to handle typical elements such as your email, so you would only need to reference the kind of input in the database, a bit like so:
function addFormElement(&$form,$type){
switch($type){
case 'email':$form->add('email', 'text', array(
'constraints' => new Assert\Email()
));
break;
}
}
/*Concidering $definitions = array("email");
*/
$form = $app['form.factory']->createBuilder('form');
foreach($definitions as $definition){
addFormElement($form,$definition);
}
$form->getForm();