0

I trying to validate the Symfony2 form. But nor of these ways not works:

{{ form_errors(form) }}

and

{{ form_errors(form.field1) }}
{{ form_errors(form.field2) }}

Where can be my problem ? I try to find solution but i didnt ge any results. Help please.

Related posts, here :

Link 1

Link 2

1 Answer 1

1

This is what worked for me.

Inside your bundle your bundle name/Resource/config/validation.yml you need to add the error message you want displayed for example this is what my contact form validation.yml looks like

    properties:
        name:
          - NotBlank: {message: "Please provide your name"}
        email:
          - NotBlank: {message: "Please provide youe email"}
          - Email:
                      message: '"{{ value }}" is not valid.'
        comment:
          - NotBlank: {message: "Please enter your comment"}

Then inside your twig to display a message for lets say the name field,

{% if(form_errors(form.name)) %}
{{ form_errors(form.name) }}
{% endif %}

Inside your controller you need to place a check

if ($form->isValid()) {....your processing code here }

Finally in your app/config/config.yml enable validation

framework:
    validation:      { enabled: true, enable_annotations: false }
Sign up to request clarification or add additional context in comments.

1 Comment

hello, thanks but it didn help for me... i dont know where is the problem, in logs i see the errors messages, but {{ form_errors(..)}} return empty string...