Using only PHP (i.e. no JS), how do you redirect a Zend form in a fancybox iframe to its parent page, only if the form was successful? For instance, I set setAttrib("target","_parent") in the Zend form, but it forces the submit action to redirect on the iframe, and not the parent page. I want it to return to the parent page only if the submit action is unsuccessful. If login is not successful, it stays on the fancybox iframe successfully displaying error message. I am using Zend Framework. Here are some code:
Login.php
class Application_Form_Login extends Zend_Form
{
public function init()
{
$this->setAction('/auth/login')
->setAttrib('id', 'login_form')
->setAttrib('target', '_parent')
->setName('login_form')
->setMethod('post');
----->added all elements here
}
}
loginAction (inside authController.php)
public function loginAction()
{
$request = $this->getRequest();
$form = new Application_Form_Login();
//$form->setAttrib('target','_parent');
//$this->view->login_form = $form;
if($request->isPost()){
if($form->isValid($request->getPost())){
$data = $form->getValues();
if ($this->_processLogin($data)) {
// We're authenticated! Redirect to the home page
$auth = Zend_Auth::getInstance();
$id = $auth->getIdentity()->id;
//this is where I need some logic to redirect on parent page only if successful login
$this->_redirect('/user/'.$id.'/home');
} else {
$form->setAttrib('target','_self');
$this->view->errorMessage = "Invalid credentials. Try again";
$form = new Application_Form_Login();
$this->view->login_form = $form;
}
}else{
$form->setAttrib('target','_self');
$this->view->errorMessage = "Can't be empty. Please try again.";
$form = new Application_Form_Login();
$this->view->login_form = $form;
}
}else{
}
$this->view->login_form = $form;
}