在我的引导程序中,我没有一个类,它只是一个简单的php文件:
我在这里添加了:
$loader = Zend_Loader_Autoloader::getInstance ();
$loader->setFallbackAutoloader ( true );
$loader->suppressNotFoundWarnings ( false );
//resource Loader
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => '',
));
$resourceLoader->addResourceType('validate', 'validators/', 'My_Validate_');
$loader->pushAutoloader($resourceLoader);然后,在应用程序/验证器中,我有:
class My_Validate_Spam extends Zend_Validate_Abstract {
const SPAM = 'spam';
protected $_messageTemplates = array(
self::SPAM => "Spammer"
);
public function isValid($value, $context=null)
{
$value = (string)$value;
$this->_setValue($value);
if(is_string($value) and $value == ''){
return true;
}
$this->_error(self::SPAM);
return false;
}
}在我的表单构造函数中,我有:
$this->addElement(
'text',
'honeypot',
array(
'label' => 'Honeypot',
'required' => false,
'class' => 'honeypot',
'decorators' => array('ViewHelper'),
'validators' => array(
array(
'validator' => 'Spam'
)
)
)
); 最后,在我看来,我有:
<dt><label for="honeypot">Honeypot Test:</label></dt>
<dd><?php echo $this->form->honeypot;?></dd>尽管如此,我还是通过填充或不填充该文本字段来接收表单数据。这里我漏掉了什么?
在此之前非常感谢。
发布于 2011-06-23 01:12:25
这是预期的行为。$honeypot是一个表单元素。现在,假设您有一个表单$hp_form,其中$honeypot是分配的元素之一。
现在,在您的控制器中,只需使用如下内容:
if ($hp_form->isValid($this->getRequest()->getPost())) {
// do something meaningful with your data here
} 如果您是第一次显示表单,或者用户是否提交了表单,您可能还想检查:
if ($this->getRequest()->isPost() &&
false !== $this->getRequest()->getPost('submit_button', false)) {
if ($hp_form->isValid($this->getRequest()->getPost())) {
// do something meaningful with your data here
}
}提交按钮的id为‘...assuming _ button’。
希望这能有所帮助
再见,克里斯蒂安
发布于 2011-06-23 01:12:35
替换:
if (is_string($value) and $value == ''){
return true;
}出自:
if (strlen($value) > 0)
{
return true;
}https://stackoverflow.com/questions/6442852
复制相似问题