エラーメッセージのデコレータを設定する例を次に示します。
に要素があります:
$title = $this->createElement('text', 'title');
$title->setRequired(true)
->setLabel('Title:')
->setDecorators(FormDecorators::$simpleElementDecorators)
->setAttrib('maxlength', $validationConfig->form->title->maxlength)
->addValidator('stringLength', false, array($validationConfig->form->title->minlength,
$validationConfig->form->title->maxlength,
'encoding' => 'UTF-8',
'messages' => array(
Zend_Validate_StringLength::INVALID =>
'Title must be between %min% and %max% characters',
Zend_Validate_StringLength::TOO_LONG =>
'Title cannot contain more than %max% characters',
Zend_Validate_StringLength::TOO_SHORT =>
'Title must contain more than %min% characters')));
$this->addElement($title);
これはフォームデコレータを使用したクラスです。そこで多くのことを実行できます。
class FormDecorators {
public static $simpleElementDecorators = array(
array('ViewHelper'),
array('Label', array('tag' => 'span', 'escape' => false, 'requiredPrefix' => '<span class="required">* </span>')),
array('Description', array('tag' => 'div', 'class' => 'desc-item')),
array('Errors', array('class' => 'errors')),
array('HtmlTag', array('tag' => 'div', 'class' => 'form-item'))
);
}