Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:47:57+00:00 2026-05-28T06:47:57+00:00

I would like to display error message in the field it is for. I

  • 0

I would like to display error message in the field it is for. I know how to put the error message into the field, but I want to find a dynamic way to check after re-submittion, if the inserted value is not the error message itself. I use doctrine annotations.
For example if the field is “title”, the error message would be “The title must be filled!”.
So the title field is not empty anymore, I click submit again, and it is valid now. I don’t want to check every single field like
if $entity->getTitle() == "The title must be filled" ...
I’ve managed to do this with not displayed error divs in the twig, and jquery, but I want to know if there is a better way to do this from the controller? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:47:57+00:00Added an answer on May 28, 2026 at 6:47 am

    You’re asking how to correctly do something the wrong way… If the input value is not the value you want processed, it should have never been the value to begin with. That being said, I’m sure you have your reasons…

    You need to listen to FormEvents::BIND_CLIENT_DATA and clear the form data if it matches your error string.

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('title');
        $builder->get('title')->addEventListener(
            FormEvents::BIND_CLIENT_DATA,
            function(FilterDataEvent $event)
            {
                if ('The title must be filled' == $event->getData()) {
                    $event->setData('');
                }
            },
        );
    

    If you want to apply this behavior globally you need to attach this listener using a form type extension that extends 'field'. You will also need to introspect all of the possible validation error messages for the current field using the validator and pass these through the translator, then compare the results with the event data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to display the error message in the input element itself instead
I would like to set up an error page which will diplay a message
I would like to display details of an xml error log to a user
I would like to display some smiley's inbetween text in my chatbox but when
I would like to check if a text field in the post form is
I would like display something more meaningful that animated gif while users upload file
I would like to display some memory statistics (working set, GCs etc.) on a
I would like to display multiple colors (and potentially shapes and sizes) of data
I would like to display the up time of the machine my code is
I would like to display the differences between versions of the same content. Initially

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.