3
我使用ajax調用表單,而不是在頁面中顯示它。Symfony2通過Ajax獲取表單
一切都在工作,除了一件奇怪的事情。
當我通過ajax調用表單並將其添加到頁面時,默認值不在字段中。
但是,如果我打電話通過正常的URL形式,默認值設置...
$builder
->add('email', null,array('data' => 'default value')
->add('type_form', null, array('data' => 'default value', 'property_path'=> false))
->add('list_choice', 'choice', array(
'choices' => $options['list'],
'expanded'=>true,
'multiple'=>true,
));
領域的電子郵件和type_form不會顯示在「默認值」的值,除非我通過打電話的形式他的網址,而不是通過ajax。
是否有通過ajax調用窗體的具體方法? 感謝您的回答。
在這裏,我在我的控制器
$this->container->get('templating')->render('MyappSiteBundle:Contributions:filter_themes_form.html.twig', array(
'form'=> $form->createView(),
'type'=> $type));
$response = new Response(json_encode(array('form'=> $response_form)));
$response->headers->set('Content-Type', 'application/json');
return $response;
然後我打電話的形式創建表單的方式......
您究竟如何用Ajax調用表單? –
我使用jquery,我調用我的控制器動作的路由,它創建窗體並將其返回到Json var中。那麼jquery會做一個innerHtml將表單添加到頁面中。 – Rmannn
我添加代碼以提供幫助 – Rmannn