You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <ug...@apache.org> on 2005/06/08 18:33:35 UTC

[CForms] URL Validator

I'm in need of a simple URL validator for CForms. It should test 
whether a string value represents a well-formed URL and if it doesn't, 
prepend "http://" and try again.

I think this would nicely cover the use case where you need to specify 
a website address in a form but don't want to force users to specify 
the protocol.

Has anybody come up with something similar before?

Also, I would like the field value to be a well-formed URL in any case, 
so it should always contain a protocol part. Is it allowed for a 
validator to change the value of its widget? Would it be better instead 
to define a new "url" datatype and corresponding convertor? It looks 
cleaner, but it also seems overkill to define a validator, a datatype 
and a convertor (plus factory classes) just to cover this simple use 
case.

	WDYT?

		Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/

Re: [CForms] URL Validator

Posted by Sylvain Wallez <sy...@apache.org>.
Ugo Cei wrote:

> I'm in need of a simple URL validator for CForms. It should test 
> whether a string value represents a well-formed URL and if it doesn't, 
> prepend "http://" and try again.
>
> I think this would nicely cover the use case where you need to specify 
> a website address in a form but don't want to force users to specify 
> the protocol.
>
> Has anybody come up with something similar before?
>
> Also, I would like the field value to be a well-formed URL in any 
> case, so it should always contain a protocol part. Is it allowed for a 
> validator to change the value of its widget?


Hmm... not good as the validation expects the form to be in a stable 
state throughout the whole validation phase. We should even add checks 
to ensure widgets don't change within the validation phase :-)

> Would it be better instead to define a new "url" datatype and 
> corresponding convertor? It looks cleaner, but it also seems overkill 
> to define a validator, a datatype and a convertor (plus factory 
> classes) just to cover this simple use case.
>
>     WDYT?


What about a simple value-changed listener that adds the protocol when 
it's not there? It will be called before the validator, which can then 
check the absolute URL with its protocol.

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://apache.org/~sylvain            http://anyware-tech.com
Apache Software Foundation Member     Research & Technology Director