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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:07:01+00:00 2026-06-04T05:07:01+00:00

I want to create a validator similar to the way GitHub handles deleting repositories.

  • 0

I want to create a validator similar to the way GitHub handles deleting repositories. To confirm the delete, I need to enter the repo name. Here I want to confirm delete by entering the entity property “name”. I will either need to pass the name to the constraint or access it in some way, how do I do that?

  • 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-06-04T05:07:04+00:00Added an answer on June 4, 2026 at 5:07 am

    you could indeed use a validator constraint to do that:

    1: Create a delete form (directy or using a type):

        return $this->createFormBuilder($objectToDelete)
            ->add('comparisonName', 'text')
            ->setAttribute('validation_groups', array('delete'))
            ->getForm()
        ;
    

    2: Add a public property comparisonName into your entity. (or use a proxy object), that will be mapped to the corresponding form field above.

    3: Define a class level, callback validator constraint to compare both values:

    /**
     * @Assert\Callback(methods={"isComparisonNameValid"}, groups={"delete"})
     */
    class Entity 
    {
        public $comparisonName;
        public $name;
    
        public function isComparisonNameValid(ExecutionContext $context)
        {
            if ($this->name !== $this->comparisonName) {
                $propertyPath = $context->getPropertyPath() . '.comparisonName';
                $context->addViolationAtPath(
                    $propertyPath,
                    'Invalid delete name', array(), null
                );
            }
        }
    }
    

    4: Display your form in your view:

    <form action="{{ path('entity_delete', {'id': entity.id }) }}">
       {{ form_rest(deleteForm) }}
       <input type="hidden" name="_method value="DELETE" />
       <input type="submit" value="delete" />
    </form>
    

    5: To verify that the delete query is valid, use this in your controller:

        $form    = $this->createDeleteForm($object);
        $request = $this->getRequest();
    
        $form->bindRequest($request);
        if ($form->isValid()) {
            $this->removeObject($object);
            $this->getSession()->setFlash('success',
                $this->getDeleteFlashMessage($object)
            );
        }
    
        return $this->redirect($this->getListRoute());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I in ZF2 create custom form element with custom validator? I want
I am using JSF2.0/primefaces I want to create a validator, the validator should validate
I want to create a custom form validator to check if my user is
I want to check HTML validate (validator.w3.org) and create site map from xml-sitemaps.com My
I want to create a custom Data annotation Validator to check whether all the
i want to create a validatior via code behind.But although i create it,it doesnt
I want to create a validation range in cell A1. This validation allow user
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that

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.