相关疑难解决方法(0)

Symfony2:如何在将请求绑定到表单后获取表单验证错误

这是我的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

symfony

109
推荐指数
8
解决办法
20万
查看次数

在javascript块中遍历twig数组

使用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)

javascript arrays jquery symfony twig

5
推荐指数
1
解决办法
6582
查看次数

标签 统计

symfony ×2

arrays ×1

javascript ×1

jquery ×1

twig ×1