westdc-zf1/application/models/CommentForm.php

60 lines
2.1 KiB
PHP
Raw Normal View History

2009-03-06 03:20:46 +00:00
<?php
class CommentForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('comment');
$author = new Zend_Form_Element_Text('author');
$author->setLabel('姓名')->setRequired(true)
->addFilter('StripTags') ->addFilter('StringTrim')
->addValidator('StringLength',false,array(3,50));
$email = new Zend_Form_Element_Text('email');
$email->setRequired(true)->setLabel('Email')
->addFilter('StringTrim')
->addValidator('NotEmpty')->addValidator('EmailAddress');
$url = new Zend_Form_Element_Text('url');
$url->addFilter('StringTrim')->setLabel('Website');
$content = new Zend_Form_Element_Textarea('content');
$content->addFilter('StringTrim')->setAttrib('cols',50)->setAttrib('rows',4)->addValidator('NotEmpty');
$spam=new element_bcSpamBlock('spam');
$spam->addPrefixPath('Validator','validator/','validate')
->addValidator('SpamBlock');
$id = new Zend_Form_Element_Hidden('id');
$uuid = new Zend_Form_Element_Hidden('uuid');
$redirect=new Zend_Form_Element_Hidden('redirect');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('评论');
$submit->setAttrib('id', 'commentbutton');
$this->addElements(array($author,$email, $url, $spam, $content, $submit,$id, $uuid));
$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')),
));
}
}