Вопрос

I've been reading about Symfony2 forms (http://symfony.com/doc/current/book/forms.html) and I've been searching the net for ways to customize my form without any success.

my first problem is about creating arbitrary form fields in my form. Fields which are not based on my DB model/entity. I do not want to save the values in the form fields but I do not need them when processing the form.

e.g. I want 2 radio fields to appear on my approval page. "approve", "rejected". when I try to add the approved radio button on my form, I get an error that says "approve" doesn't have the get/set functions.

$em = $this->getDoctrine()->getEntityManager();
$application = $em
    ->getRepository('MyApp\GenericBundle\Entity\Application')
    ->find($applicationId);

$form = $this->createFormBuilder($application)
    ->setMethod('POST')
    ->add('approved', 'radio')
    ->getForm();

Thanks for the help

Это было полезно?

Решение

Use the mapped attribute that allows you to prevent the field from being persisted

$form = $this->createFormBuilder($application)
    ->setMethod('POST')
    ->add('approved', 'radio', array('mapped' => false))
    ->getForm();

Doc: http://symfony.com/doc/current/reference/forms/types/form.html#mapped

Другие советы

If you're trying to perform two actions on the form you could use alternate submit buttons; One for "Approve" one for "Reject"

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top