We (the entire team) have been pulling hair over this problem for the last 2 days. For some strange reason our Zend Framework 1.11.2 will not let us post plain form into the controller unless we create a Zend_Form class.
HTML in view file (no javascript, nothing):
<html><body>
<form action="/index/login/" method="post">
Email: <input type="text" name="email"/><br />
Password: <input type="password" name="password" />
<p><input type=submit name="ac" class="btn btn-success" value="Login"></p>
</form></body></html>
Index Controller:
public function loginAction()
{
$request = $this->getRequest();
if ($request->getParam('email')) {
Zend_Debug::dump($request);
}
}
$request->getParams() is empty!
But if we create a Zend_Form or pass the fields in as GET then $request->getParams() is filled with data.
I just don't get it. Is there something in Zend that you have to turn off to use plain form? We think we've tried everything, accessing global $_POST and $_REQUEST variables, and calling $request->getPost(). All empty unless we create a Zend_Form class and instantiate it inside the controller.
Looks like an problem with your Form Action. Please use "baseUrl" View Helper or URL View Helper to create correct action url:
<?php
// correct action url
$actionURL = $this->url(array(
'controller' => 'index',
'action' => 'login',
'module' => 'default',
));
?>
<html>
<body>
<form action="<?php echo $actionURL; ?>" method="post">
Email: <input type="text" name="email"/><br />
Password: <input type="password" name="password" />
<p><input type=submit name="ac" class="btn btn-success" value="Login"></p>
</form>
</body>
...pass the fields in as GET then $request->getParams() is filled with data.
Since you are crafting a form post, you will need to use the getPost()
method.
public function loginAction()
{
if ($email = $this->_request->getPost('email')) {
Zend_Debug::dump($email);
}
}
First use the latest version
Zend Framework 1.11.11
Then try this code inside loginAction
if($this->getRequest()->isPost())
{
print_r($this->_getAllParams());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.