Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7558947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:30:24+00:00 2026-05-30T12:30:24+00:00

Using only PHP (i.e. no JS), how do you redirect a Zend form in

  • 0

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;
    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:30:26+00:00Added an answer on May 30, 2026 at 12:30 pm

    Here’s what I ended up doing:

    <form id="login"> regular stuff here, elements, etc</form>
    
    
    
    <script type="text/javascript">
    
    $(document).ready(function() {
    
        $('#loginbtn').live('click',function(event){
    
            var em = $("#useremail").val();
            var pwd = $("#userpassword").val();
    
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: "/auth/login",
                data: { email: em, password: pwd },
                success: function(result){
                    if(result.msg == "success"){
                        window.location = "/user/" + result.id + "/home";
                    }else{
                        $(".errormsg").html(result.msg);
                    }
                },
                error: function(jqXHR, exception) {
                    if (jqXHR.status === 0) {
                        alert('Not connect.\n Verify Network.');
                    } else if (jqXHR.status == 404) {
                        alert('Requested page not found. [404]');
                    } else if (jqXHR.status == 500) {
                        alert('Internal Server Error [500].');
                    } else if (exception === 'parsererror') {
                        alert('Requested JSON parse failed.');
                    } else if (exception === 'timeout') {
                        alert('Time out error.');
                    } else if (exception === 'abort') {
                        alert('Ajax request aborted.');
                    } else {
                        alert('Uncaught Error.\n' + jqXHR.responseText);
                    }
                }       
            });
    
            return false;
        });
    });
    

    And in my controller action:

    public function loginAction()
    

    {

        $this->_helper->layout->disableLayout();
            $this->_helper->viewRenderer->setNoRender(TRUE); // suppress auto-rendering and displaying a view
        $data['email'] = $_POST['email'];
        $data['password'] = $_POST['password'];
    
        if ($this->_processLogin($data)) {
                // We're authenticated!
            $auth = Zend_Auth::getInstance();
            $id = $auth->getIdentity()->id;
            echo Zend_Json::encode(array('msg' => 'success', 'id' => $id));
        } else {
                      $this->_helper->json(array('msg' => 'Invalid credentials. Try again'));
            } 
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my page, I'm using a javascript function <script> function redirect(){ window.location=hurray.php; } </script>
I'm building a PHP site, but for now the only PHP I'm using is
Can I send email using jQuery only? I don't have .Net or PHP etc
On the PHP website, the only real checking they suggest is using is_uploaded_file() or
I'm doing form validation using a PHP script. I initially wrote this code in
I'm using a host that will only allow PHP files to be located in
I'm using mod_rewrite to redirect on URLs like: mysite.com/123 RewriteEngine On RewriteRule ^([0-9]+)$ /n/index.php?id=$1
Using only ANSI C, what is the best way to, with fair certainty, determine
Using only VBScript (launched from Windows Scripting Host) can I pull the DLL metadata
Using only MySQL , I'm seeing if it's possible run an insert statement ONLY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.