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

  • Home
  • SEARCH
  • 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 1049103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:33:46+00:00 2026-05-16T16:33:46+00:00

Zend Form is not my friend today! This works :- Controller:- public function indexAction()

  • 0

Zend Form is not my friend today!

This works :-

Controller:-


public function indexAction()
    {
        $loginForm = new Application_Form_Login();

        //is there a submitted form?
        if($this->getRequest()->isPost()){
         //yes there is so process it.
         $formdata = $this->getRequest()->getPost();
         if($loginForm->isValid($formdata)){
          $user_logon = $loginForm->getValue('user_name');
          $user_pw = $loginForm->getValue('user_pw');
          if($this->authenticate($user_logon, $user_pw)){
           $this->_redirect();
          }
         } else {
          $this->view->errors = $loginForm->getMessages();
         }
        }

        $this->view->loginForm = $loginForm;

Form


class Application_Form_Login extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */

     $this ->setName('Login');
     $this ->setAction('login')
       ->setMethod('post');

     $name = new App_Form_Element_Text('user_name');
     $name ->setLabel('User Name')
       ->setRequired(true);
     $pword = new Zend_Form_Element_Password('user_pw');
     $pword ->setLabel('Password')
       ->setRequired(true)
       ->addValidator('Alnum');
     $submit = new Zend_Form_Element_Submit('Submit');
     $submit ->setAttrib('id', 'Submit');

     $this->addElements(array($name, $pword, $submit));

     // buttons do not need labels
        $submit->setDecorators(array(
            array('ViewHelper'),
            array('Description'),
            array('HtmlTag', array('tag' => 'span', 'class'=>'submit-group')),
        ));
    }
}

This doesn’t!

Controller


 public function addAction()
    {
     $addform = new Application_Form_Student_Add();

     //has a form been submitted?
     if($this->getRequest()->isPost()){
      if(isset($_POST['Cancel'])) $this->_redirect('/student');
      $formdata = $this->getRequest()->getPost();
      if($addform->isValid($formdata)){
       Zend_Debug::dump($formdata);
      } else {
       $this->view->errors = $addform->getMessages();
      }
  }
  $this->view->addForm = $addform->generate();
    }

Form


public function init()
 {
  $this->studentform = new Zend_Form();

  $baseUrl = new Zend_View_Helper_BaseUrl();
  $action = $baseUrl->baseUrl() . "/student/add";

  $this->studentform->setAction($action);
  $this->studentform->setName('addStudent');
  $this->studentform->setMethod('post');

  $student_title = new App_Form_Element_Text('student_title');
  $student_title ->setLabel('Titletest')
      ->setRequired(true);
  $cancel = new Zend_Form_Element_Submit('Cancel');
  $submit = new Zend_Form_Element_Submit('Submit');
  $this->studentform->addElement($student_title);
  $this->studentform->addElement($cancel);
  $this->studentform->addElement($submit);
 }

Both display properly, however the first will validate and the second won’t. The first will display error messages when a blank form is submitted, however the 2nd always seems to pass validation regardless of the values entered.

I’ve been looking at this for hours and it just probably needs somebody else to look at the code and point out the blindingly obvious to me.

In both cases the view just echos the form out.

  • 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-16T16:33:46+00:00Added an answer on May 16, 2026 at 4:33 pm

    In the working code you use $this to refer to your form in init in the second version you use $this->studentForm.

    So I would be curious to know why the codes differ there and what object is that second init from. The code you posted is different there.

    Something tells me in your second controller you should be using

    $addform->studentForm->stuff
    

    Since its not an instance of Zend_Form but an object containing a studentForm Zend_Form.

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

Sidebar

Related Questions

Using Zend_Form, how would I create form elements like this: <input type=text name=element[1] value=
I am using the Zend Framework. I have a controller named 'UserController' that has
I'm doing some form in Zend Framework for file upload on Apache friends -
I'm using Zend 1.8.4 and setting up a simple form test. My form class
When you submit a form, disabled form fields are not submitted in the request.
This piece of valid json (it has been generated using php's json_encode): {html:form is
I have a zend form that lets the user fill out attributes of an
I'm using zend form in a non-zend project and I'm able to access Zend_Form
I have tried all the combinations I can think off but this form: class
this is my form script: located in application/forms and i copy it form here

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.