English 中文(简体)
Zend表单:错误不会显示
原标题:Zend form: errors don t show up

Zend talk。我在我的web应用程序中构建了一个自定义的Zend_form。问题是我无法显示错误(当我提交没有任何文本的表单时)。我是否遗漏了一些明显的内容?

class Commentform extends Zend_Form
{
 public function init()
 {  

  $this->setMethod( post );
  $this->setAction(  );
  $text=new Zend_Form_Element_Textarea( text );
  $text->setRequired(true)
  ->addFilter( StringTrim )
  ->addFilter( StripTags )
  ->setDescription( bla bla );

 $submit=new Zend_Form_Element_Submit( commenta );

 $this->addElements(array($text,$submit));
 $this->setElementDecorators(array(
  ViewHelper ,
 array( Description ,array(
        tag => span , class => medium , placement => PREPEND )),
 ));

$this->setDecorators(array(
 FormElements ,
  FormErrors ,
 Form ,array( Description ,array( tag => h2 , placement => prepend )),
 array( HtmlTag , array( tag  =>  div , class => write_comment )),
));

$this->setDescription( zend zend );
}
}

谢谢

卢卡

最佳回答

在表单上使用的正确装饰器是FormErrors,例如

$this->setDecorators(array(
 FormElements ,
 FormErrors ,
 Form ,array( Description ,array( tag => h2 , placement => prepend )),
 array( HtmlTag , array( tag  =>  div , class => write_comment )),
));

Errors装饰器用于元素。

问题回答

您必须在表单元素中放置一个“错误”装饰器Zend_Form_Element默认加载此“错误”装饰器,如您在Zend-Form_Element源代码中所见:

public function loadDefaultDecorators()
{
    ...
    $this->addDecorator( ViewHelper )
        ->addDecorator( Errors )
        ->addDecorator( Description , array( tag  =>  p ,  class  =>  description ))
        ->addDecorator( HtmlTag , array( tag  =>  dd ,  id   => array( callback  => $getId)))
        ->addDecorator( Label , array( tag  =>  dt ));
    ...
}

因为您在不提供“错误”装饰器的情况下重写此行为,所以不会显示元素级错误。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签