这是我的saveAction代码(表单传递数据的地方)
public function saveAction()
{
$user = OBUser();
$form = $this->createForm(new OBUserType(), $user);
if ($this->request->getMethod() == 'POST')
{
$form->bindRequest($this->request);
if ($form->isValid())
return $this->redirect($this->generateUrl('success_page'));
else
return $this->redirect($this->generateUrl('registration_form'));
} else
return new Response();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如果$form->isValid()返回,我如何得到错误false?
使用Symfony2.3.4和PHP5.6.3.
我需要THE TITLE.
看,我有这个模板
{#new.html.twig#}
{% extends 'GCBundle::layout.html.twig' %}
{% block title %}{{parent()}} | Create chart {%endblock title %}
{% block content -%}
{% if errors is defined %}
{#not sure if I need this#}
{% endif %}
<FORM class="form-horizontal" action="{{path('chart_create', { 'id' : entity.id })}}"
method="post" {{ form_enctype(form) }}>
<center><h3>Create chart</h3></center>
{{ form_widget(form) }}
<DIV class="form-actions">
<BUTTON name="submit" type="submit"
class="btn btn-primary"><I class="glyphicon-check"></I>
{{ 'Save'|trans }}</BUTTON>
<a class="btn" href="{{ path('chart') }}">
<I class="glyphicon-ban"></I> {{ 'Cancel'|trans }}</a>
</DIV>
</FORM> …Run Code Online (Sandbox Code Playgroud)