php - How to check form validation in controller in Zend Framework 1.12 -
how check if form validated or not, , how show error message if form not according validations
in zf2 write as
usercontroller $request = $this->getrequest(); $form = new form_loginform(); if($request->ispost()){ if($form->isvalid($this->_request->getpost())){ $authadapter = $this->getauthadapter(); $username = 'john'; $password = '123'; $authadapter->setidentity($email) ->setcredential($password); $auth = zend_auth::getinstance(); $result = $auth->authenticate($authadapter); if($result->isvalid()){ $identity = $authadapter->getresultrowobject(); $authstorage = $auth->getstorage(); $authstorage->write($identity); $this->_helper->redirector(register/user); echo 'valid'; } else { $this->view->errormessage = "user name or password incorrect"; } } }
the above code in zend framework2 , need code in zend framework 1.12
. how form login.phtml
usercontroller , how write code check validation in line 4 written in zend framework2
my login.phtml
form is
<form action="<?php echo $this->url(array('controller'=>'user','action'=>'login'), 'default',true);?>" method="post"> email: <input type="text" name="user_email" type="email" oninvalid="setcustomvalidity('plz enter valid email ')" onchange="try{setcustomvalidity('')}catch(e){}" required /> password: <input type="password" name="password" required /> <input type="submit" name="submit" value="submit" /> </form>
how this....
$form = new form_loginform(); if ($this->getrequest()->ispost()) { if ($form->isvalid($_post)) { $formdata = $this->_getformdata(); $authadapter = $this->_getauthadapter($formdata); $auth = zend_auth::getinstance(); $result = $auth->authenticate($authadapter); /** * authentication failed */ if (!$result->isvalid()) { switch ($result->getcode()) { // username doesn't exist case zend_auth_result::failure_identity_not_found : $yourlogic; break; // username , password combination incorrect case zend_auth_result::failure_credential_invalid : $yourlogic; break; // general error message default : $yourlogic; } } /** * authentication success */ else { // store identity object password column has been omitted $data = $authadapter->getresultrowobject(null, 'password'); } } }
Comments
Post a Comment