Reputation: 2557
I trying to send Ajax request to my Controller, get form there, and if some data true, need to remove some part of form, but I dont know how i can get my form trought $request object. Help me please.
All code for now, I tell there is exist some way, to do something like this $request->getForm()
public funcion ajaxAction(Request $request)
{
if ($request->isXmlHttpRequest()) {
}
}
Upvotes: 0
Views: 137
Reputation: 10890
You should do something like this (I assume you're in your controller extending Symfony\Bundle\FrameworkBundle\Controller\Controller
):
public funcion ajaxAction(Request $request)
{
if ($request->isXmlHttpRequest()) {
$form = $this->createForm(new YourFormType());
$form->handleRequest($request);
}
}
after that you have $form
with data from requst bound. You can call methods like isValid()
or getData()
on this variable
Check documentation for more info
Upvotes: 1