And what is proper image url?
image34534534534534
image.php?gen=23423423423
/image/7234273642734
image.jpg -> rewrite hack.pl
I'm using Zend_Filter_Input to validate some input, and one of the textboxes allows you to enter a URL in. I need to validate the URL to make sure it is in the proper Website.com format. In fact, it's supposed to point to an image, so I'm hoping I can override the validator (if one already exists) so it checks for a proper image url.
And what is proper image url?
image34534534534534
image.php?gen=23423423423
/image/7234273642734
image.jpg -> rewrite hack.pl
I figured it out, thanks anyway.
Hi Bulletproof
I'm also trying to validate a URL. How did you do it?
I need to validate URLs like:
I've tried using Hostname, but it fails on any URLs with a directory.Code:http://www.websites.com http://subdomain.websites.com http://www.websites.com/directory/ http://www.websites.com/index.php?whatever=xyz
Thanks
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
nice! that works pretty well. thanks
How about just passing a REGEX to the validator as an alternative:
Zend Framework: Documentation