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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:45:05+00:00 2026-06-12T20:45:05+00:00

I started studying the Zend_Form component and understand most aspects of it. I know

  • 0

I started studying the Zend_Form component and understand most aspects of it. I know how to add form elements and set configuration options for them, how to apply form decorators, how to add validators and filters… But today i got stuck on the processing of those forms.

There’s one particular thing that just baffles me. I’ll illustrate it with an example which i kept as simple as possible.

First we create the form as a separate class. Nothing special here, just a username and password field and a submit button. We’ll also add a label and some filters and validators to them.

class Login_Form extends Zend_Form
{
    public function init()
    {
        $this->setaction('/user/login')
             ->setMethod('post');

        $username = new Zend_Form_Element_Text('username');
        $username->setLabel('Username:')
                 ->setRequired(true)
                 ->addFilter('StringToLower')
                 ->addValidator('NotEmpty');

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Password:')
                 ->setRequired(true);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setValue('Submit');

        $this->addElements(array(
            $username,
            $password,
            $submit
            ));

        return $this;  
    }
}

Next we’ll create a ‘user’ action controller with a ‘login’ action method. Here, i want to check if the form got submitted (if not it should be displayed) and validate it. Notice the two identical lines of code. Although the $form object did not change in the mean time, the first produces no output, the second does.

class UserController extends Zend_Controller_Action
{
    public function loginAction()
    {
        $form = new Login_Form;

        // Check if form got submitted
        if ($this->getRequest()->isPost())
        {
            // This does not produce output
            echo 'Username: ' . $form->getValue('username');

            if ($form->isValid($_POST))
            {
                // This does produce output (same line of code as above)
                echo 'Username: ' . $form->getValue('username');
            }
            else
            {
                echo $form;
            }
        }
        else
        {
            echo $form;
        }
    }
}

If i would just want the unfiltered values, I could get them from the request object with $this->getRequest()->getPost(). I want the filtered values though (the filters are defined in the Login_Form class) so I should get them from the form object with getValues(). I find it awfully strange that the $form object changes after calling isValid() on it (which just returns a boolean and does not alter the $form object). Any help with this would be very much appreciated!

  • 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-12T20:45:06+00:00Added an answer on June 12, 2026 at 8:45 pm

    This how the Zend_Form object works: You need to pass the actual data that was submitted into it, it does not grab it from somewhere itself. This is because the source of data can vary. One application always uses POST, someone wants to validate GET parameters as well, and a completely different application doesn’t even have HTTP requests, but does want to validate input from the commandline.

    I wonder why your code seems to work. First, your form doesn’t even define a method – will fail for sure. Second, in your controller I would expect $form->getValue(‘username’) to work, but the access to a property should not work – I do not see any code inside the Zend_Form source that sets public properties.

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

Sidebar

Related Questions

I started studying DLL's with implicit linking. I don't really fully understand how it
I'm new to using vectors...I just started studying them today. I'm trying to create
just started studying xslt.just want to know how would count the number of international
I started studying about AppDomains, and I just cannot understand the difference between CreateInstance
I have just started studying node.js and express, the documentation of express on the
I have recently started studying about threads. I thought of starting from the beginning
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like
I've been started studying PHP in my spare time, and the first code example
I just started studying Drupal 7 and learned how powerful CCK and Views are.
Sorry if this question is too simple or easy. I just started studying Delegates

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.