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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:11:33+00:00 2026-06-15T07:11:33+00:00

I have a simple Zend Form that contains a textbox with setRequired(TRUE) and other

  • 0

I have a simple Zend Form that contains a textbox with setRequired(TRUE) and other validators and a simple submit button in IndexController.

My question is, is it possible another controller will process and validate my post form?

Login.php

<?php

class Application_Form_Login extends Zend_Form
{

    public function init()
    {
        $username = $this->createElement('text', 'username');
        $username->setLabel('Username:');
        $username->setRequired(TRUE);
        $username->addValidator(new Zend_Validate_StringLength(array('min' => 3, 'max' => 10)));
        $username->addFilters(array(
                new Zend_Filter_StringTrim(),
                new Zend_Filter_StringToLower()
                )
        );
        $this->addElement($username);

        // create submit button
        $this->addElement('submit', 'login',
                array('required'    => false,
                'ignore'    => true,
                'label'     => 'Login'));
    }}

IndexController.php

<?php

class AttendantController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $loginForm = new Application_Form_Login();
        $loginForm->setAction('/Auth/process');
        $loginForm->setMethod('post');
        $this->view->loginForm = $loginForm;
    }
}

AuthController.php

class AuthController extends Zend_Controller_Action
{
    public function processAction()
    {
        // How to validate the form posted here in this action function?
        // I have this simple code but I'm stacked here validating the form

        // Get the request
        $request = $this->getRequest();
        // Create a login form
        $loginForm = new Application_Form_Login();
        // Checks the request if it is a POST action
        if($request->isPost()) {
            $loginForm->populate($request->getPost());
            // This is where I don't know how validate the posted form
            if($loginForm->isValid($_POST)) {
                // codes here
            }
        }
    }
}
  • 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-15T07:11:35+00:00Added an answer on June 15, 2026 at 7:11 am

    You’re pretty close. In the process action you create a new instance of the login form (which you are doing), and you pass the POST data to the isValid() method of that form in order to validate. So:

    public function processAction()
    {
        $request = $this->getRequest();
    
        $loginForm = new Application_Form_Login();
        if($request->isPost()) {
            if($loginForm->isValid($request->getPost)) {
                // codes here
            } else {
                // assign the login form back to the view so errors can be displayed
                $this->view->loginForm = $loginForm;
            }
        }
    }
    

    Generally it is easier to display and process the form within the same action, and redirect when the submission is successful. This is the Post/Redirect/Get pattern – see http://en.wikipedia.org/wiki/Post/Redirect/Get. This saves you having to create an instance of the same form in two different actions and makes it easier to redisplay the form in case of errors.

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

Sidebar

Related Questions

The question is quite simple : I have a controller plugin for Zend Framework.
I have simple php validation form that is halfway working. If you leave the
I have a simple content edit form (Zend_Form) that I populate() with an array
I have weird problem with zend framework basics. I have simple action in IndexController:
I have a quick and hopefully simple question that I hope someone can help
I have a simple Zend-based form with reCaptcha element: $form = new Zend_Form(); $form->setName('forgotpassword')
I have a simple Zend Framework site I am developing with the addition that
i have a simple form that has a textarea ans a hidden field $textarea
I have a form that I am trying to add a simple select element
i am using zend form and i have a condition such that: when i

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.