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
| class Default_Form_Contact extends Zend_Form
{
public function init()
{
$this->setDisableLoadDefaultDecorators(true);
$this->addDecorator('FormElements')
->addDecorator('Form')
->addDecorator('HtmlTag', array('tag'=>'div', 'class'=>'myform', 'id'=>'stylized'));
$this->setMethod('post');
$this->setAction('contact');
$this->setAttrib('id', 'login');
$this->setName('Contact');
$this->addElementPrefixPath('My_Decorator',APPLICATION_PATH.'/forms/Decorator/','decorator');
$translate = Zend_Registry::get('translate');
$username = $this->createElement('text', 'username');
$username->addValidator('alnum')
->addErrorMessage('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength', false, array(6, 20))
->setRequired(true)
->setLabel('username')
->setDescription('username description')
->addFilter('StringToLower');
// élément mot de passe :
$password = $this->createElement('password', 'password');
$password->addValidator('StringLength', false, array(6))
->setRequired(true)
->addErrorMessage('required')
->setLabel('password')
->setDescription('password description');
$category = new Zend_Form_Element_Select('category');
$category->setLabel('Category')
->setRequired(true);
$category->addMultiOption('dd','ff');
$model = new Default_Model_Contact();
$entries = $model->fetchAll();
foreach ($entries as $c) {
$category->addMultiOption($c->id, $c->name);
}
$submit = $this->createElement('submit', 'envoyer')
->setLabel('')
->setValue('username');
// Ajout des éléments au formulaire
$this->addElement($username)
->addElement($password)
->addElement($category)
->addElement($submit);
$this->setElementDecorators(array('Composite'));
}
} |
Partager