开发者

Zend Form Element Notes

I have built a zend form element for html content开发者_JAVA百科 (general notes).

class Sistema_Form_Note extends Zend_Form_Element_Xhtml {

    public $helper = 'formNote';

    public function isValid($value){
        return true;
    }

}

It's working fine however it goes as a field and when I go to insert the post data on my database, the index note element appears.

POST array('name' => 'John'
  'note1' => ...); 

How could I remove it without using the removeElement() method on the controller? Is there any way to tell on the class it shouldn't be a "db field"?

Thanks


I figured out, looking how submit button is removed, It can be solved overring contruct method and passing ignore option as true.

class Sistema_Form_Note extends Zend_Form_Element_Xhtml {

    public $helper = 'formNote';

    public function __construct($spec, $options = null)
    {
       if (is_string($spec) && ((null !== $options) && is_string($options))) {
            $options = array('label' => $options);
       }

       if (!isset($options['ignore'])) {
            $options['ignore'] = true;
       }

       parent::__construct($spec, $options);
    }

    public function isValid($value){
       return true;
    }

}


I've created a similar element with the same requirements. I know you've already answered this but mine contains a solution that prevents the value from being overridden by post data (if you use the $_value property).

class My_Form_Element_Note extends Zend_Form_Element_Xhtml
{
    public $helper = 'formNote';

    protected $_ignore = true;

    public function setValue($value)
    {
        if (null === $this->_value) {
            parent::setValue($value);
        }
        return $this;
    }
}


For me just it has helped:

class App_Form_Element_Note extends Zend_Form_Element_Xhtml {

public $helper = 'formHtml';

public function __construct($spec, $options = null) {

     parent::__construct($spec, $options);
     $this->setIgnore(true);
}

public function isValid($value){
      return true;
}

}

The overwride of 'IsValid' function made the note appears when the validator acts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜