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 7158013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T12:59:25+00:00 2026-05-28T12:59:25+00:00

In my form I have field of type entity . How to disable validation

  • 0

In my form I have field of type entity. How to disable validation of that entity when the form is submitted? This entity is already persisted in database, so there is no point for validator to validate this entity from my point of view.

EDIT:

Code looks like this:

class SearchRequest
{
    /**
     * @ORM\ManyToOne(targetEntity="ArticlePattern")
     * @ORM\JoinColumn(name="article_pattern_id", onDelete="CASCADE")
     * @Assert\NotBlank
     */
    private $articlePattern;
}

form field:

$builder
    ->add('articlePattern', 'entity', array('class' => 'LonbitItssBundle:ArticlePattern')

Validation groups won’t work because what I want to accomplish is for validator to check the constraint @Assert\NotBlank on $articlePattern field, but I don’t want him to check the constraints defined in class ArticlePattern. So in other words, I want prevent validator from descending inside the $articlePattern object, but I want the constraint placed on $articlePattern field itself to be validated.

Any idea how to do that?

EDIT2:

Validation groups will work. So the final solution is to add groups={"search_request"} constraint option (name of the group is arbitrary) to every field assertion in SearchRequest class, like this:

/**
 * @Assert\NotBlank(groups={"search_request"})
 */
private $articlePattern;

That way, validation won’t descend to associated objects (assuming they don’t belong to – in this case – “search_request” group).

  • 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-28T12:59:26+00:00Added an answer on May 28, 2026 at 12:59 pm

    1) If you want to disable this field, just don’t use it in your class form ! (and remove it from the template)

    public function buildForm(FormBuilder $builder, array $options)
    {
            $builder
                ->add('content')
                ->add('username')
                //->add('yourEntity')
            ; 
    }
    

    2) Or better, use validation groups. You create a validation_group which don’t call your validator entity and then you use this group in your class form:

    public function getDefaultOptions(array $options)
    {
            return array(
                'data_class' => 'Sybio\BuzzBundle\Entity\SearchRequest',
                'csrf_protection' => true,
                'csrf_field_name' => '_token',
                'intention'       => '865c0c0b4ab0e063e5caa3387c1a8741',
                'validation_groups' => array('without_article_pattern_ckecking'),
            );
    }
    

    In your Entity class:

    /**
     * @ORM\ManyToOne(targetEntity="ArticlePattern")
     * @ORM\JoinColumn(name="article_pattern_id", onDelete="CASCADE")
     * @Assert\NotBlank(
     *  groups={"without_article_pattern_ckecking"}
     * )
     */
     private $articlePattern;
    

    Your form will only validate validators that refer to without_article_pattern_ckecking group, so it should not test validators inside your ArticlePattern entity if they don’t have this validation group.

    I hope this helps you !

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

Sidebar

Related Questions

I have form with checkboxes loaded from database (I use entity field type). Checkboxes
I have an entity type form field in my Symfony2 project. $builder = $this->createFormBuilder();
I have a form and one of the fields is a check-all-that-applies type field
I have this field in one form : <input type=text name=promocode id=promoCode value= style=width:24%
I have an Entity with the field url , this entity is being persisted
I have a form with a collection type field, rendered like that: <div id=beneficiosTab
I have the following situation: a form field type date a validation pattern like
I have a field in a CCK node form that is hidden, and has
How get name of field type file in beforeSave()? I have form with many
I have a field of type image in my database which is mapped as

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.