Zend_Form_Element_Captcha仅显示带有数字的图像

时间:2014-07-17 09:33:53

标签: zend-framework zend-form captcha zend-form-element

我正在使用Zend_Form_Element_Captcha:

         $this->view->captcha = new Zend_Form_Element_Captcha('captcha', array(
            'label' => 'Codice di controllo:',
            'required' => true,
            'captcha' => array(
                'captcha' => 'Image',
                'font' => APPLICATION_PATH . '/../public/default/fonts/arial.ttf',
                'fontSize' => '22',
                'wordLen' => 6,
                'height' => '57',
                'width' => '135',
                'imgDir' => APPLICATION_PATH . '/../public/images/captcha',
                'imgUrl' => Zend_Registry::get('URL') . 'public/images/captcha',
                )
            ));

我需要我的验证码图像只显示小写字母,而不是大写字母。那可能吗?谢谢!

2 个答案:

答案 0 :(得分:1)

如果您不想要数字,可以试试这个:

$captcha = new Zend_Form_Element_Captcha(...);

$capcha_addapter = $captcha->getCaptcha();
$capcha_addapter->setUseNumbers(false); // No digit
$captcha->setCaptcha($capcha_addapter);

$this->view->captcha = $captcha;

答案 1 :(得分:0)

如果您不想使用数字,只需使用useNumbers选项

即可
$this->view->captcha = new Zend_Form_Element_Captcha('captcha', array(
    'label' => 'Codice di controllo:',
    'required' => true,
    'captcha' => array(
        'captcha'     => 'Image',
        'useNumbers'  => false,
        'font'        => APPLICATION_PATH . '/../public/default/fonts/arial.ttf',
        'fontSize'    => '22',
        'wordLen'     => 6,
        'height'      => '57',
        'width'       => '135',
        'imgDir'      => APPLICATION_PATH . '/../public/images/captcha',
        'imgUrl'      => Zend_Registry::get('URL') . 'public/images/captcha',
        )
    ));

作为设置用于生成Captcha的char列表的一般解决方案,将扩展Zend_Captcha_Image类并覆盖_generateWord受保护的方法。

希望有所帮助