0

I have created a new custom field in the UserEntity and therefore an Assert-Validation with a error message. This Message can be displayed with {{ form_errors(form) }} globally but I haven´t found a way to display the error-message linked to the field without overriding the whole form_theme.

{{ form_errors(form.field_name) }} does not work either

2
  • have you overriden the form class as well ? Commented Nov 26, 2018 at 17:27
  • No, only extended Commented Nov 26, 2018 at 18:16

1 Answer 1

1

The FOSUserBundle mapps the errors by himself.

My Problem was a typo in the field name in the FormType. It should exactly match the variable name in the Entity

Entity

/**
 * Some Comment
 *
 * @ORM\Column(name="field_name", type="array", nullable=true)
 * @Assert\NotBlank(message = "Please select at least one field_name")
 */
protected $fieldName; // Entity variable name

FormType

    $builder->add(
        'fieldName', // Needs to match Entity variable name
        ChoiceType::class,
        array(
            'choices' => array(
                'Some Choice' => '1',
                'Other Choice' => '2',
                '3rd Choice' => '3',
            ),
            'label' => 'form.register.fieldname',
            'translation_domain' => 'user',
            'multiple' => true,
            'expanded' => true,
            'required' => true,
        )
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.