Skip to content
Advertisement

Checking which form field value has changed Symfony 3

I need to check inside the FormType which field has changed. Is there any method to do it? I’ve searched for a while, then tried to get edited entities field in few ways (with form events too) to catch the edited fields, but no simple result.

Is there any way to do it easy, or I need to be more creative in making such thing? The best it would be, if I can get an example with entity type, but any clue would be great.

P.S. I cant do it on client-side – I must do it on server side for particular reason.

Advertisement

Answer

Done with this: https://stackoverflow.com/a/33923626/8732955

Suppose we want to check the “status” field in our ImportantObject, code needs to look like that

if($form->isSubmitted() && $form->isValid())
{
        $uow = $em->getUnitOfWork();
        $uow->computeChangeSets();
        $changeSet = $uow->getEntityChangeSet($importantObject);

        if(isset($changeSet['status'])){
          //do something with that knowledge
        }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement