westdc-zf1/application/models/ContactForm.php

60 lines
2.0 KiB
PHP
Raw Normal View History

2009-03-06 03:20:46 +00:00
<?php
class ContactForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('Contact');
$username = new Zend_Form_Element_Text('username');
2009-12-25 11:14:07 +00:00
$username->setLabel('姓名')->setRequired(true)
2009-03-06 03:20:46 +00:00
->addFilter('StripTags') ->addFilter('StringTrim')
->addValidator('StringLength',false,array(3,50));
$email=new Zend_Form_Element_Text('email');
2009-12-25 11:14:07 +00:00
$email->setLabel('邮件')
2009-03-06 03:20:46 +00:00
->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty')
->addValidator('EmailAddress');
$subject=new Zend_Form_Element_Text('subject');
$subject->setLabel('主题')->setRequired(true);
$body=new Zend_Form_Element_Textarea('body');
$body->setLabel('内容')->setRequired(true)->setAttrib('rows',4);
$id = new Zend_Form_Element_Hidden('id');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'submitbutton')->setLabel('发送');
$spam=new element_bcSpamBlock('spam');
$spam->addPrefixPath('Validator','validator/','validate')
->addValidator('SpamBlock');
$this->addElements(array($id, $spam,$username,$email,$subject,$body,$submit));
2009-12-25 11:14:07 +00:00
$this->clearDecorators();
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => '<ul>','class'=>'commentform'))
->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')),
));
2009-03-06 03:20:46 +00:00
}
}