westdc-zf1/application/models/RegisterForm.php

79 lines
3.2 KiB
PHP
Executable File

<?php
class RegisterForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('Register');
$username = new Zend_Form_Element_Text('username');
$username->setLabel('用户名')->setRequired(true)
->addFilter('StripTags') ->addFilter('StringTrim')
->addValidator('StringLength',false,array(3,50))
->addPrefixPath('Validator','validator/','validate')
->addValidator('NotInTable',false,array('username'));
$password=new Zend_Form_Element_Password('password');
$password->setLabel('密码')
->setRequired(true)
->setDescription('长度在6到20位字符之间')
->addValidator('StringLength',false,array(6,20));
$password_confirm=new Zend_Form_Element_Password('password_confirm');
$password_confirm->setLabel('确认密码')->addPrefixPath('Validator','validator/','validate')
->setRequired(true)->addValidator('Confirmation',false,array('password'));
$email=new Zend_Form_Element_Text('email');
$email->setLabel('E-Mail')
->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty')
->addValidator('EmailAddress');
$email_repeat=new Zend_Form_Element_Text('email_repeat');
$email_repeat->setLabel('确认E-Mail')
->setRequired(true)
->addPrefixPath('Validator','validator/','validate')
->addValidator('NotInTable',false,array('email'))
->addValidator('Confirmation',false,array('email'));
$realname=new Zend_Form_Element_Text('realname');
$realname->setLabel('真实姓名')->setRequired(false);
$phone=new Zend_Form_Element_Text('phone');
$phone->setLabel('电话')->setRequired(false);
$unit=new Zend_Form_Element_Text('unit');
$unit->setLabel('单位')->setRequired(false);
$address=new Zend_Form_Element_Text('address');
$address->setLabel('联系地址')->setRequired(false);
$project=new Zend_Form_Element_Textarea('project');
$project->setLabel('隶属西部项目')->setRequired(false)->setAttrib('rows',4);
$id = new Zend_Form_Element_Hidden('id');
$submit = new Zend_Form_Element_Submit('注册');
$submit->setAttrib('id', 'submitbutton');
$this->addElements(array($id, $username,$password,$password_confirm,$email,$email_repeat,$realname,$phone,$unit,$address,$project,$submit));
$this->clearDecorators();
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => '<ul>','class'=>'registerform'))
->addDecorator('Form');
$this->setElementDecorators(array(
array('ViewHelper'),
array('Errors'),
array('Description'),
array('Label', array('separator'=>' ')),
array('HtmlTag', array('tag' => 'li', 'class'=>'element-group')),
));
// buttons do not need labels
$submit->setDecorators(array(
array('ViewHelper'),
array('Description'),
array('HtmlTag', array('tag' => 'li', 'class'=>'submit-group')),
));
}
}