Take the 2-minute tour ×

i have created a custom validator but when I want to use it, it seems that it is never executed!

the validator :

class sfTestUrlValidator extends sfValidatorUrl {

    public function initialize($context, $parameters = null) {

        // Initialize parent

    public function execute(&$value, &$error) {

        if($value == "http://www.librosweb.es/")
            //$error = "noooooooooooooo";
            return true;

        else            return false;



in the configure method of a form, i do like that :

public function configure() { 
 'url' => new sfTestUrlValidator(),  
share|improve this question
it seems you missed a space between "sfTestUrlValidator" and "extends". Make sure you use copy/paste and don't rewrite everthing by hand when you share some code. –  greg0ire Sep 12 '11 at 8:16
done! thanks !! –  ProXamer Sep 12 '11 at 8:21

1 Answer 1

up vote 0 down vote accepted

You need to override sfValidatorBase::doClean method and not some not-existent execute method and throw exception intead of returning true/false. Have a look at any validator class, e.g. sfValidatorString. However in your case, I would simply use sfValidatorChoice with one choice

public function configure() 
 'url' => new sfValidatorChoice(array('choices' => array(
share|improve this answer
if i use the doClean() method, i will not use the sfValidatorUrl functionality, for example in this case(with doClean) if i answer a "non url" string, it will be accepted! which is WRONG, You see? –  ProXamer Sep 12 '11 at 8:47
and for the choicevalidator , the code i listed is just an example, my url test will be executed on several servers and then if it doesn't exist on any of them, it wont allow to insert it(cause later it will fire exceptions) –  ProXamer Sep 12 '11 at 8:52
I used the doClean method and added the protected function doClean($value) { $value = parent::doClean($value); .... –  ProXamer Sep 12 '11 at 9:15

Your Answer


