Да Symfony поддерживает формы, не связанные с объектами, следующий фрагмент показывает, как вы не можете создать контактную форму, которая не привязана к объекту.
public function indexAction(Request $request)
{
$form = $this->createFormBuilder()
->setAction($this->generateUrl('contact_route'))
->setMethod('POST')
->add('name', 'text')
->add('email', 'email')
->add('phone', 'text')
->add('message', 'textarea')
->add('submit', 'submit', array('label' => 'SUBMIT'))
->getForm()
;
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$message = \Swift_Message::newInstance()
->setSubject(''.$form->get('name')->getData() ." ". $form->get('phone')->getData())
->setFrom($form->get('email')->getData())
->setTo('[email protected]')
->setBody(''.$form->get('email')->getData().' '.$form->get('message')->getData());
$this->addFlash('notice','Thank you, we will contact you soon!');
$this->get('mailer')->send($message);
return $this->redirect($this->generateUrl('contact_route'));
}
return $this->render('BundleName:Contact:index.html.twig',array('form' => $form->createView(),));
}
[нечто похожее на это?] (Http://stackoverflow.com/questions/22754526/symfony2-create-form-without-entity-class) –
Вы можете использовать массив вместо объекта/объекта. – Cerad