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 8320617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:42:51+00:00 2026-06-08T22:42:51+00:00

I have an issue with redisplaying a view after a validation failure with a

  • 0

I have an issue with redisplaying a view after a validation failure with a Zend form.

My initial action looks like

public function test1Action() {
    // get a form and pass it to the view
    $this->view->form = $this->getForm(); 

    // extra stuff I need to display 
    $this->view->name = "Bob";
}

and the view

Hello <?= $this->name?>
<?php echo $this->form;?>

The problem comes when the action “test2” called after the form is submitted has a validation error :

public function test2Action() {
    if (!$this->getRequest()->isPost()) {
        return $this->_forward('test1');
    }

    $form = $this->getForm();
    if (!$form->isValid($_POST)) {
        $this->view->form = $form;
        return $this->render('test1'); // go back to test1
    }
}

Indeed, the variable “name” is lost and the view is incorrect. Instead of saying “Hello Bob” it says “Hello”.

How should I handle that ? should I redirect to test1 instead of just rendering test1 again ? how ?

EDIT

Following the answer of Mr Coder, here is what I ended up with :

Controller:

    public function getForm() {
        // what is important is that the form goes to action test3 and not test4
        // SNIP form creation with a field username
        return $form;
    }

    public function test3Action()
    {
        $this->view->form = $this->getForm();
        $this->view->name = "Bob";

        if(!$this->getRequest()->isPost())return;

        if($this->view->form->isValid($_POST))
        {
            //save the data and redirect
            $values = $this->view->form->getValues();
            $username = $values["username"];

            $defaultSession = new Zend_Session_Namespace('asdf');
            $defaultSession->username = $username;

            $this->_helper->redirector('test4');
        }
    }


    public function test4Action()
    {
        $defaultSession = new Zend_Session_Namespace('asdf');
        $this->view->username = $defaultSession->username;
    }

test3.phtml

Hello <?= $this->name?>
<?php echo $this->form;?>

test4.phtml

success for <?php echo $this->username;?>
  • 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-06-08T22:42:53+00:00Added an answer on June 8, 2026 at 10:42 pm

    To bring your bob back do

    public function test2Action() {
        if (!$this->getRequest()->isPost()) {
            return $this->_forward('test1');
        }
    
        $form = $this->getForm();
        if (!$form->isValid($_POST)) {
            $this->view->form = $form;
            $this->view->name = 'bob';        
            return $this->render('test1'); // go back to test1
        }
    }
    

    But I will advice my solution of handling form which goes something like

    public function test2Action()
    {
    
       $this->view->form = new My_Form();
    
       if(!$this->getRequest()->isPost())return;   
    
      if($this->view->form->isValid())
       {
        //save the data and redirect 
           $this->_helper->redirector('success');
       }
    
      }
    

    inside your test2.phtml

    <?php echo $this->form ?>
    

    }

    This approach save you from creating multiple action for saving one form and changing view manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have an issue with jquery autocomplete, focus function After i type something in the
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have a form_for a comment. Comments belongs_to Issue. I have a comments form
I have issue where i want to create Dynamic function which will do some
Seems like everyone have issue accessing local machine or internet etc from emulator. All
Below is the code fragment I have issue with socket programing. Here after select
I have issue, after checkout on checkout/onepage/success get a user info using order id,
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR
Share your ideas please! I have issue to check the folder and convert a

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.