如何解决Symfony:如何检查表单发送的数据
当我使用 smyfony4 应用程序提交表单时,出现以下错误。
由于是整个表格的错误,无法查明原因。
我要调试提交表单的值。
我该怎么办?
我很抱歉像初学者一样提出问题。
错误
shop => Not a valid value.
{{ form_start(form) }}
{{ #The part that issued the error #}}
{{ form_errors(form) }}
<div class='formGroup'>
{{ form_label(form.tel,'TEL') }}
{{ form_widget(form.tel) }}
{{ form_errors(form.tel) }}
</div>
.
.
.
{{ form_end(form) }}
$form = $this->createForm(ShopType::class,$shop,array(
"method" => "PUT","action" => $this->generateUrl("app_shop_shop_update"),"em" => $this->getDoctrine()->getManager(),));
if ($request->isMethod('PUT')) {
if ($form->handleRequest($request)->isValid()) {
// save
$this->get("admin.shopService")->save($shop);
$this->get('session')->getFlashBag()->add('success','I saved my shop profile.');
return $this->redirect($this->generateUrl('ahi_sp_admin_shop_shop_edit'));
} else {
$this->get('session')->getFlashBag()->add('error','The shop profile could not be saved. Please check the input contents.');
}
}
解决方法
函数getData()
if ($form->isSubmitted() && $form->isValid()) {
dump ($form->getData());
}
,
Symfony 的开发者工具显示我在保存时传递的值,这是导致错误的原因。
保存店铺基础数据的时候,验证效果不好,再次尝试更新的时候,出现了表单中没有的基础数据的错误,所以表单项的每一个错误都会出现错误提示好像没有显示。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。