【发布时间】:2012-06-16 10:30:06
【问题描述】:
我正在开发一个网络应用程序。我有应该从网络上创建和编辑的实体(非常经典,不是吗)。
所以我想使用 Symfony 提供的表单生成(带有类型和处理程序),但我不只是想以标准方式打印它们。我想从 jquery 中调用这些表单,以便我可以在 jQuery 插件(例如 jEditable)中使用验证等。
因此,我认为最好的方法是将表单作为 json 发送到 jquery 函数,该函数会将其放入我的 HTML 元素中。
我做了什么:
jQuery:
$.get("getorganisationform/"+curOId, function(data){
if(data.responseCode==200 ){
$( "#innerModal" ).append(data.form);
}
});
控制器:
$form = $this->createForm(new OrganisationType, $organisation);
$formHandler = new OrganisationHandler($form, $this->get('request'), $this->getDoctrine()->getEntityManager());
if( $formHandler->process() )
{
return $this->redirect( $this->generateUrl('adminpanel') );
}
return new Response(json_encode($form), 200);
json_encode() 实际上不发送任何东西,因为 $form 是一个对象。现在我有几个问题:
- 有没有办法获取表单的html元素?
- 那么有必要使用json吗?
- 有没有更好的方法在 jquery 中重用表单生成? (我在这里考虑 jeditable)
提前致谢!
【问题讨论】: