Reputation: 366
I'm trying to redirect with Zend framework but something really strange happens what I just can't understand.
At first you are at token.phtml
, the loginform
action looks like this:
<?php print $this->url(array('controller' => 'login', 'action' => 'login'));?>"
In the loginAction
I'm checking if a user exists or not. When an user is not found I want it to stay at token.phtml
so I do this:
$this->_redirect('/login/token');
But the URL changes to the URL like you where logged in also if I do view page source in Firefox it shows the source of the logged on page.
But it does go to token.phtml
because it outputs the <div>
's and everything just fine.
Upvotes: 2
Views: 782
Reputation: 366
Apparently jquery mobile is causing this problem. jquery mobile submits its forms via AJAX automatically, if i turn AJAX off the URL changes correctly and so does the source.
Upvotes: 0
Reputation: 11
try to leave form action empty, so you'll get the request in tokenAction. In tokenAction check if user exist and all that stuff, then if true redirect to login action
$this->_helper->redirector->gotoRoute(
array(
// route like:
'controller' => 'login'
'action' => 'login'
),
'routenameifyouwant'
);
Upvotes: 0
Reputation: 2431
change your way: if bad login stay in same page ad show message error and if login right, redirect where you want: try to change your action controller so:
public function loginAction()
{
$form = new Form_Login();
if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
//stuff check login
$loginResult = //call method check, if bad return message error
if (true === $loginResult) {
//login success redirect where you want
$this->_helper->redirector('index', 'index');
} else {
// auth failed
foreach ($loginResult as $field => $message) {
$form->getElement($field)->addError($message);
}
}
}
$this->view->form = $form;
}
Upvotes: 1