url validation and http:// prefixes

So, since I am a new member I can’t post on the forum or something in that sense, whenever I try to post something the whole forum fails on me (see screenshot) saying that i can’t post urls or something…

anyway,

I’m looking to find a way to change the url validation so that it automatically prepends htt(and)p:// on values that don’t have it before doing the validation.

the issue i have (obviously could do it vi model->beforeValidate) is that this way I have to edit all models which is too messy for my linkings. So I’m looking for a cleaner way to do it globaly. I don’t care if it is going to be server or client side, I’m comfortable with both, I think I would prefer client side even though I think it would be quite a hack to do, register custom js and all…

So, I’m happy to hear some ideas as I said, all solutions are welcome.

cheers, k

extend CUrlValidator and then tell the rules to use yours, like this:


CValidator::$builtInValidators['url']='MyUrlValidator' 




class MyUrlValidator extends CUrlValidator

{

	public $defaultScheme = 'http';

}



That’s all you need to override.

CUrlValidator::$defaultScheme

So, I did implement what everybody told me here but never actually came back to affirm that.

so, thanks guys. both answers are very helpful!

greetings, k

By the way… you don’t really need to extend the validator.

All you have to do is this:


array('url', 'url', 'defaultScheme' => 'http')

Thanks a lot. this is the easiest solution…

it works …