![]() |
|
|||
|
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.
|
|
|||
|
Hi Bulletproof
I'm also trying to validate a URL. How did you do it? I need to validate URLs like: 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 |
|
|||
|
How about just passing a REGEX to the validator as an alternative:
Zend Framework: Documentation |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |