Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Form does not validate input
    primarykey
    data
    text
    <p>Zend Form is not my friend today!</p> <p>This works :-</p> <p>Controller:-</p> <pre><code> public function indexAction() { $loginForm = new Application_Form_Login(); //is there a submitted form? if($this->getRequest()->isPost()){ //yes there is so process it. $formdata = $this->getRequest()->getPost(); if($loginForm->isValid($formdata)){ $user_logon = $loginForm->getValue('user_name'); $user_pw = $loginForm->getValue('user_pw'); if($this->authenticate($user_logon, $user_pw)){ $this->_redirect(); } } else { $this->view->errors = $loginForm->getMessages(); } } $this->view->loginForm = $loginForm; </code></pre> <p>Form</p> <pre><code> class Application_Form_Login extends Zend_Form { public function init() { /* Form Elements & Other Definitions Here ... */ $this ->setName('Login'); $this ->setAction('login') ->setMethod('post'); $name = new App_Form_Element_Text('user_name'); $name ->setLabel('User Name') ->setRequired(true); $pword = new Zend_Form_Element_Password('user_pw'); $pword ->setLabel('Password') ->setRequired(true) ->addValidator('Alnum'); $submit = new Zend_Form_Element_Submit('Submit'); $submit ->setAttrib('id', 'Submit'); $this->addElements(array($name, $pword, $submit)); // buttons do not need labels $submit->setDecorators(array( array('ViewHelper'), array('Description'), array('HtmlTag', array('tag' => 'span', 'class'=>'submit-group')), )); } } </code></pre> <p>This doesn't!</p> <p>Controller</p> <pre><code> public function addAction() { $addform = new Application_Form_Student_Add(); //has a form been submitted? if($this->getRequest()->isPost()){ if(isset($_POST['Cancel'])) $this->_redirect('/student'); $formdata = $this->getRequest()->getPost(); if($addform->isValid($formdata)){ Zend_Debug::dump($formdata); } else { $this->view->errors = $addform->getMessages(); } } $this->view->addForm = $addform->generate(); } </code></pre> <p>Form</p> <pre><code> public function init() { $this->studentform = new Zend_Form(); $baseUrl = new Zend_View_Helper_BaseUrl(); $action = $baseUrl->baseUrl() . "/student/add"; $this->studentform->setAction($action); $this->studentform->setName('addStudent'); $this->studentform->setMethod('post'); $student_title = new App_Form_Element_Text('student_title'); $student_title ->setLabel('Titletest') ->setRequired(true); $cancel = new Zend_Form_Element_Submit('Cancel'); $submit = new Zend_Form_Element_Submit('Submit'); $this->studentform->addElement($student_title); $this->studentform->addElement($cancel); $this->studentform->addElement($submit); } </code></pre> <p>Both display properly, however the first will validate and the second won't. The first will display error messages when a blank form is submitted, however the 2nd always seems to pass validation regardless of the values entered.</p> <p>I've been looking at this for hours and it just probably needs somebody else to look at the code and point out the blindingly obvious to me.</p> <p>In both cases the view just echos the form out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload