View Single Post
  #5 (permalink)  
Old 02-10-2009, 12:06 AM
toque_101 toque_101 is offline
Junior Member
 
Join Date: Feb 2009
Posts: 1
Default Extend Zend_Validate_Abstract

You can validate a URI using Zend_Uri but it doesn't implement the Zend_Validate_Interface. So, you'll have to roll your own. Fortunately, it's pretty easy to do so:

[PHP]
class Url_Validator extends Zend_Validate_Abstract
{
const INVALID_URL = 'invalidUrl';

protected $_messageTemplates = array(
self::INVALID_URL => "'%value%' is not a valid URL.",
);

public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);

if (!Zend_Uri::check($value)) {
$this->_error(self::INVALID_URL);
return false;
}
return true;
}
}

// When creating the form:
$website = $form->createElement('text', 'website');
$website->addValidator(new Url_Validator);
[/PHP]

Hope that helps
-steve
Reply With Quote