<? Online-PHP::Tutorials ?>

« Back

  • ZF: Create very basic login form

     

    The class itself, located in 'models' directory, named "LoginForm.php":
     
    	class Application_Form_LoginForm extends Zend_Form {
    
    		public function init() {
    
    			$login = new Zend_Form_Element_Text('login');
    			$login->setLabel('login')->setRequired(true);
    
    			$passw = new Zend_Form_Element_Password('password');
    			$passw->setLabel('password')->setRequired(true);
    
    			$submit = new Zend_Form_Element_Submit('submit');
    			$submit->setLabel('Login');
    
    			$this->setName('login_form')
    				->setMethod('post')
    				->setAction('/auth/login')
    				->addElements(array($login, $passw, $submit));
    
    		}
    
    	}
     
    usage (The controller action):
        public function indexAction()
        {
            // action body
            $this->view->login_form = new Application_Form_LoginForm();
        }
    
    
    usage (The action view):
    <?php echo $this->login_form; ?>