Hi José,

this is exactly what I was looking for.
Thank you!

best regards
Florian

On Aug 27, 2:36 am, José Nahuel Cuesta Luengo
<[email protected]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> mintao escribió:> I have an input field for an URL.
> > When the form is submittet I'm using sfValidatorDoctrineUnique for
> > this field. But BEFORE the validation I'd like to manipulate the url
> > (host name to lower case, cut off any query strings).
>
> > Imagine the url "http://www.test.com/mysite"; is already in the
> > database.
> > When a user tries to submit the following url "http://www.Test.com/
> > mysite/?q=foo" I'd like sfValitatorDoctrineUnique to recognize it as a
> > unique violation.
>
> > What can I do?
>
> You might:
>
>  a) use sfValidatorCallback instead of sfValidatorDoctrineUnique and in
> the callback function you could clean $value and then return whatsoever
> sfValidatorDoctrineUnique returns for that clean input.
>     Could be something like this:
>
>     [php]
>     // In your form's configure() method
>     // ...
>     $this->setValidator('url', new sfValidatorCallback(array(
>         'callback' => array($this, 'validateUrl'),
>         'required' => true
>       )));
>     //...
>
>     // Outside configure(), declare the callback method
>     public function validateUrl($validator, $value, $arguments)
>     {
>       // Clean $value
>       $clean_value = clean($value);
>
>       $v = new sfValidatorDoctrineUnique(array(
>           'model'  => 'MyModel',
>           'column' => 'url'
>         ));
>       return $v->clean($clean_value);
>     }
>     [/php]
>
>   b) Implement your own sfValidatorBase subclass for doing pretty much
> the same, but with the benefit of code reuse and modularization.
>
> Hope this helps.
>
> - --
> José Nahuel Cuesta Luengo
> Desarrollo | CeSPI - UNLP
> <[email protected]>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iEYEARECAAYFAkqV1QkACgkQ2jTpOyePgAFtMwCfdbql1LtUoHPOU6W20xOtlJWl
> mz4AoIquBTvQF3bve3uvstWLk8W+T+Na
> =DcGt
> -----END PGP SIGNATURE-----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to