Closed
Description
When submit a form with a entity field type throws invalid input syntax for integer: ""
My Type:
namespace Prueba\PruebaBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PruebaType extends AbstractType {
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('nombre')
->add('apellido')
->add('tipoDocumento', 'entity', array(
'class' => 'PruebaBundle:TipoDocumento',
'required' => false
))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Prueba\PruebaBundle\Entity\Prueba'
));
}
/**
* @return string
*/
public function getName() {
return 'prueba_pruebabundle_prueba';
}
}
AND:
namespace Prueba\PruebaBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class TipoDocumentoType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('descripcion')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Prueba\PruebaBundle\Entity\TipoDocumento'
));
}
/**
* @return string
*/
public function getName()
{
return 'prueba_pruebabundle_tipodocumento';
}
}
My create action:
public function createAction(Request $request)
{
$entity = new Prueba();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('prueba_show', array('id' => $entity->getId())));
}
return $this->render('PruebaBundle:Prueba:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
Metadata
Metadata
Assignees
Labels
No labels