0

嗨,我正在尝试制作带有验证的表单。

我有这个表格:

<form  class="formulario" id="modificarmedico" action="{{ path('medico_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
    <div id="mio_miobundle_medicotype">
    {{ form_row(edit_form.username) }}
    {{ form_row(edit_form.dni) }}
    {{ form_row(edit_form.nombre) }}
    {{ form_row(edit_form.apellido1) }}
    {{ form_row(edit_form.apellido2) }}
    {{ form_row(edit_form.localidad) }}
    {{ form_row(edit_form.provincia) }}
    {{ form_row(edit_form.direccion) }}
    {{ form_row(edit_form.email) }}
    {{ form_row(edit_form.telefono) }}
    {{ form_row(edit_form.movil) }}
    {{ form_row(edit_form.titulacion)}}
    {{ form_row(edit_form.numero)}}
    {{ form_row(edit_form.fechaalta)}}
    {{ form_row(edit_form.idioma)}}
    {{ form_row(edit_form.tema)}}
    {{ form_row(edit_form.color)}}
    {% if is_granted('ROLE_A') %}
        {% if entity.id == app.user.id %}
        {{ form_row(edit_form.password) }}
         {{ form_errors(form.password) }}
            <div class="empoculto"> 
                {{ form_row(edit_form.activo) }}
                {{ form_row(edit_form.generar) }}
            </div>
        {% else %}
        {{ form_row(edit_form.generar) }}
        {{ form_row(edit_form.activo) }}
        <div class="empoculto">
            {{ form_row(edit_form.password) }}
        </div>
        {% endif %}
    {% else %}
         {{ form_row(edit_form.password) }}
         {{ form_row(edit_form.password) }}
        <div class="empoculto">
        {{ form_row(edit_form.generar) }}
        {{ form_row(edit_form.activo) }}
        </div>
        {% endif %}

但密码错误显示我在 div 之外。其他领域则不然:

<div>
   <label for="mio_miobundle_medicotype_movil" class=" required">Móvil</label>
   <ul>
      <li>El campo debe tener 9 números.</li>
      <li>El campo debe tener sólo números.</li>
   </ul>
   <input type="text" id="mio_miobundle_medicotype_movil" name="mio_miobundle_medicotype[movil]" required="required" maxlength="9" value="fgadfg" />
</div>
<div><label for="mio_miobundle_medicotype_color" class=" required">Color*</label><input type="text" id="mio_miobundle_medicotype_color" name="mio_miobundle_medicotype[color]" required="required" value="#1153ed" /></div>
<ul>
   <li>Las contraseñas deben ser iguales.</li>
</ul>
<div><label for="mio_miobundle_medicotype_password_Nueva contraseña" class=" required">Nueva contraseña</label><input type="password" id="mio_miobundle_medicotype_password_Nueva contraseña" name="mio_miobundle_medicotype[password][Nueva contraseña]" required="required" /></div>
<div><label for="mio_miobundle_medicotype_password_Repite contraseña" class=" required">Repite contraseña</label><input type="password" id="mio_miobundle_medicotype_password_Repite contraseña" name="mio_miobundle_medicotype[password][Repite contraseña]" required="required" /></div>

我尝试了 form_bubbling symfony2 但没有解决我的问题。谢谢。

4

1 回答 1

0

您的 if 语句在一种情况下将错误放在 div 中,在另一种情况下将错误放在 div 之外(实际上无法确定,因为您没有发布整个表单。)

    {% if entity.id == app.user.id %}
    {{ form_row(edit_form.password) }}
     {{ form_errors(form.password) }}          {# part of only one condition #}
        <div class="empoculto">                {# specifically handled here #}
            {{ form_row(edit_form.activo) }}
            {{ form_row(edit_form.generar) }}
        </div>
    {% else %}
    {{ form_row(edit_form.generar) }}
    {{ form_row(edit_form.activo) }}
    <div class="empoculto">                   {# how to handle errors #}
        {{ form_row(edit_form.password) }}    {# not specified here #}
    </div>                                    {# probably handled by #}
    {% endif %}                               {# form default #}

{{ form_errors(form.password) }} 

应该是

{{ form_errors(edit_form.password) }} 
于 2013-03-18T18:57:24.483 回答