1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
<?php
class Application_Form_Login extends Zend_Form
{
private $display_captcha = false;
public function showCaptcha() {
$this->display_captcha = true;
}
public function hideCaptcha() {
$this->display_captcha = false;
}
public function isCaptchaVisible() {
return $this->display_captcha;
}
public function init()
{
$htmlpurifier = new Form_Filter_HTMLPurifier();
$this->setAttrib('title', 'Formulaire d\'authentification');
$this->setAttrib('id','login-form');
$login = new Zend_Form_Element_Text('login');
$login->setLabel('Login')
->setRequired(true)
->addFilter($htmlpurifier)
->addValidator('NotEmpty', true)
->addValidator('stringLength', false, array(3, 15));
$login->setOrder(1);
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Mot de passe')
->setRequired(true)
->addFilter($htmlpurifier)
->addValidator('NotEmpty', true);
$password->setOrder(2);
$submit = new Zend_Form_Element_Submit('Connexion');
$submit->setAttrib('id', 'submitbutton')
->setAttrib('class', 'button');
$submit->setOrder(4);
$this->addElements(array($login, $password, $submit));
}
public function build() {
if($this->isCaptchaVisible()) {
$captcha = $this->createElement('captcha', 'captcha',
array('required' => true,
'captcha' => array('captcha' => 'Image',
'font' => 'font/a_song_for_jennifer.ttf',
'fontSize' => '24',
'wordLen' => '6',
'height' => '50',
'width' => '150',
'imgDir' => 'captcha',
'imgUrl' => 'captcha',
'gcFreq'=>'10',
'dotNoiseLevel' => '10',
'lineNoiseLevel' => '2')));
$captcha->setLabel('Captcha');
$captcha->setOrder(3);
$this->addElement($captcha);
}
}
} |
Partager