Could someone help me figure out why my Callback validation method is not being called.
Basically what I need to do is a custom validation with following logic: - in the form I have 5 fields that if all empty, the form should be valid, - however if any of the is not empty all of them need to not be empty (they are used to build a real address on a user profile)
I have followed the doc from: http://symfony.com/doc/2.3/reference/constraints/Callback.html
I have the following code:
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="UserRepository");
* @UniqueEntity("email")
* @ORM\HasLifecycleCallbacks
* @Assert\Callback(methods={"isAddressValid"})
*/
class User extends WebserviceUser implements UserInterface, EquatableInterface
{
...
public function isAddressValid(ExecutionContextInterface $context)
{
//die("I GOT HERE");
$context->addViolationAt('sna4', 'Frikin validation'!', array(), null);
}
}
The property sna4 is found in the class being extended.
Thank you in advance.
use
statement for theExecutionContextInterface
class – Matteocode
if ($form->isSubmitted() && $form->isValid())code
– Valentin Maior