开发者

Form validation is not working in Zend Form

开发者 https://www.devze.com 2023-03-03 10:03 出处:网络
This is my zend form code <?php class Form_Bookmark extends Zend_Form{ function init(){ $url_address = $this->createElement(\"text\", \"url_address\");

This is my zend form code

<?php
class Form_Bookmark extends Zend_Form{
    function init(){            
        $url_address = $this->createElement("text", "url_address");
        $url_address->setLabel("Url");        
        $url_address->isRequired(TRUE);
        $bmk_title = $this->createElement("text", "bmk_title");
        $bmk_title->setLabel("Title");
        $bmk_title->isRequired(TRUE);
        $bmk_desc = $this->createElement("textarea", "bmk_desc");
        $bmk_desc->setLabel("Description");
        $bmk_ispublic = $this->createElement("checkbox", "bmk_ispublic");
        $bmk_ispublic->setLabel("IsPublic?");
        $bmk_ispublic->isRequired(TRUE);
        $submit = new Zend_Form_Element_Submit("submit");
        $submit->setValue("Submit");
        $this->addElement($url_address);
        $this->addElement($bmk_title);
        $this->addElement($bmk_desc);
        $this->addElement($bmk_ispublic);
        $this->addElement($submit);
    }
}
?>

This is my controller code

$f = Zend_Controller_Front::getInstance();
        $bookmark_form = new Form_Bookmark();

        $bookmark_form->setAction($f->getBaseUrl()."/user/index");
        $bookmark_form->setMethod("POST");
        if($this->getRequest()->isPost()){           
            if($bookmark_form->isValid($_POST)){

               开发者_运维百科 echo "FORM VALIDATED SUCCESSFULLY";
            }else{
                echo "FORM VALIDATION FAILED";
            }
        }

        $this->view->form = $bookmark_form;

The problem is this form validation does not work. it always displays "FORM VALIDATED SUCCESSFULLY" even if I submit the empty form though I have added $url_address->isRequired(TRUE); property "TRUE".


Correct method name is setRequired:

$bmk_title->setRequired(true);
0

精彩评论

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

关注公众号