I'm using a form class in two separate contexts: both to create a new record and also to edit that record. I've set up a post-validator as follows to check that the URL field is unique.
$this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
new sfValidatorDoctrineUnique(array('model' => 'Page', 'column' => array('url')), array('invalid' => 'This URL already exists.'))
)));
The validator works great when I'm creating a new record. However, when editing an existing record, it throws an error because it detects itself as a duplicate. In other words, if I edit the record but make no changes to the URL, it throws a duplicate error.
This must be a common issue so I'm wondering what the Symfony way of dealing with this would be? Basically I'd like it to ignore itself when saving (no duplicate exists) but still run the post-validator to ensure no true duplicates exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With