If I uncomment the below line then I am unable to get the value in $this->_request->getPost('Login')
//$this->setDecorators(array(array('viewScript', array('viewScript' => 'admin/login_decorator.phtml'))));
$this->_request->getPost
works fine with forms but not with form decorator.
Below are the files...
forms/loinForm.php
<?php
class Application_Form_LoginForm extends Zend_Form {
public function __construct($options = null) {
parent::__construct($options);
$this->setMethod('post');
$name = new Zend_Form_Element_Text('username');
$name->removeDecorator('Label')
->removeDecorator("HtmlTag")
->addErrorMessage("Please Enter username")
->setRequired(true);
$password = new Zend_Form_Element_Password('password');
$password->removeDecorator('Label')
->removeDecorator("HtmlTag")
->addErrorMessage("Please Enter password")
->setRequired(true);
$submit = new Zend_Form_Element_Submit('Login');
$submit->removeDecorator('Label')
->removeDecorator("HtmlTag");
$this->addElements(array($name, $password, $submit));
//$this->setDecorators(array(array('viewScript', array('viewScript' => 'admin/login_decorator.phtml'))));
}
}
views/scripts/admin/login_decorator.phtml
<link href="<?php echo $this->baseUrl(); ?>/css/login.css" media="screen" rel="stylesheet" type="text/css">
<section class="container">
<div class="login">
<h1>Login to Administrator</h1>
<form action="" method="post" enctype="application/x-www-form-urlencoded">
<p><input type="text" name="username" value="" placeholder="Username"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
</form>
</div>
<div class="login-help">
<p>Forgot your password? <a href="#">Click here to reset it</a>.</p>
</div>
</section>
login.phtml
<?php echo $this->form; ?>
adminController.php loginAction()
public function loginAction() {
$mysession = new Zend_Session_Namespace('Admin');
if (isset($mysession->adminName)) {
$this->_redirect('/admin');
}
$form = new Application_Form_loginForm();
$this->view->form = $form;
//Preform Admin login action
if ($this->_request->getPost('Login')) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) { //If form data is valid
$name = $this->_request->getPost('username');
$password = $this->_request->getPost('password');
/* * **Creating object of model adminlogin class**** */
$adminLoginObj = new Application_Model_Adminlogin();
$fetchResult = $adminLoginObj->checkAdminAuthority($name, $password);
if (count($fetchResult) > 0) {
$mysession->adminName = $name;
$this->_redirect('/admin/');
} else {
$mysession->failLogin = "Invalid Username or Password!";
$this->_redirect('/admin/login');
}
}
}
}
I am unable to find out the reason for this issue. Please help me to resolve this. Thanks in advance.