gpt4 book ai didi

php - post 方法不适用于 zend 框架中的表单装饰器

转载 作者:行者123 更新时间:2023-11-30 23:08:07 24 4
gpt4 key购买 nike

如果我取消注释下面的行,那么我将无法在 $this->_request->getPost('Login') 中获取值

//$this->setDecorators(array(array('viewScript', array('viewScript' => 'admin/login_decorator.phtml'))));

$this->_request->getPost 适用于表单,但不适用于表单装饰器。

下面是文件...

表格/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>

登录.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');
}
}
}
}

我无法找出这个问题的原因。请帮我解决这个问题。提前致谢。

最佳答案

请检查在你的 Controller 中如果 ($this->_request->getPost('Login')) { ...}

在 views/scripts/admin/login_decorator.phtml 中

<input type="submit" name="commit" value="Login">

字段名称与操作不匹配。

请相应检查。希望对您有所帮助。

关于php - post 方法不适用于 zend 框架中的表单装饰器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20965248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com