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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
<?php
class Application_Form_UserRegister extends Zend_Form
{
public function init()
{
$this->setName('UserRegister');
$this->setAction('user/register');
$email = new Application_Form_EText ( 'email', 'Email : ' );
$email ->addValidator ( 'EmailAddress' )
->addValidator(new Zend_Validate_Db_NoRecordExists('users','email'));
$password = new Zend_Form_Element_Password ( 'password' );
$password->setLabel ( 'Mot de passe : ')->setAttrib('maxlength', 10)->addFilter ( 'StripTags' )->addFilter ( 'StringTrim' )->setRequired ( true );
$password2 = new Zend_Form_Element_Password ( 'password2' );
$password2->setLabel('Vérification du mot de passe : ')->setAttrib('maxlength', 10)->addFilter ( 'StripTags' )->addFilter ( 'StringTrim' );
$nom = new Application_Form_EText( 'nom', 'Nom : ' );
$nom->addValidator('StringLength', false, array(6, 20));
$prenom = new Application_Form_EText( 'prenom', 'Prenom : ' );
$adresse = new Application_Form_EText( 'adresse', 'Adresse : ' );
$codePostale = new Application_Form_EText( 'codePostale', 'Code Postale : ' );
$codePostale->addValidator(new Zend_Validate_Regex('#[0-9]{2} ?[0-9]{3}#'));
$ville = new Application_Form_EText( 'ville', 'Ville : ' );
$telMobile = new Application_Form_EText( 'telMobile', 'Numéro de téléphone mobile : ' );
$telMobile->setRequired(false)->addValidator('Digits')->addValidator(new Zend_Validate_StringLength(10));
$telFixe = new Application_Form_EText( 'telFixe', 'Numéro de téléphone fixe : ' );
$telFixe->setRequired(false)->addValidator('Digits')->addValidator(new Zend_Validate_StringLength(10));
$newsletter = new Zend_Form_Element_Checkbox('newsletter');
$newsletter->setLabel('je m\'abonne à la newsletter');
$contrat = new Zend_Form_Element_Checkbox('contrat');
$contrat ->setLabel('j\'accepte les termes de contrat')->setRequired(true);
$submit = new Zend_Form_Element_Submit ( 'submit' );
$submit->setAttrib ( 'class', 'submitbutton' )->setLabel ( 'Continuer' )->setAttrib('class', 'submit');
$elements = array( $email, $password, $password2, $nom, $prenom, $adresse, $codePostale, $ville, $contrat , $submit);
$this->addElements( $elements );
}
public function isValid($data) {
$this->getElement('password')->addValidator(new App_Validate_PasswordMatch($data['password2']));
if ($this->getElement('email')->getValue() == $data['email']) {
$this->getElement('email')->removeValidator ( "Zend_Validate_Db_NoRecordExists" );
}
return parent::isValid($data);
}
}
class App_Validate_PasswordMatch extends Zend_Validate_Abstract
{
const PASSWORD_MISMATCH = 'passwordMismatch';
protected $_compare;
protected $_messageTemplates = array(
self::PASSWORD_MISMATCH => "PASSWORD_MISMATCH"
);
public function __construct($compare) {
$this->_compare = $compare;
}
public function isValid($value) {
$this->_setValue((string) $value);
if ($value !== $this->_compare) {
$this->_error(self::PASSWORD_MISMATCH);
return false;
}
return true;
}
} |
Partager