views:

60

answers:

2

Hi, I new in Zend.

Main Question: Is this code good for user login (Its beginning- because that I want to know if its can be improve)?

Thanks

view index.phtml

<? echo $this->form

controller IndexAction.php

public function indexAction() {
        $form=new Application_Form_Login();
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                echo " test value username: ".$form->getValue('username');
            }
        }
    }

form Login.php

public function init() {


        $this->setMethod('post');
        $this->setName('user login');
        $username = new Zend_Form_Element_Text('username');
        $username->setLabel("username")
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('password')
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $submit = new Zend_Form_Element_Submit('submit');


        $this->addElements(array($username, $password, $submit));
}
+1  A: 

So far, so good. IMO there's nothing to improve on this further. It renders the form and if the request is POST it validates the form against the data in the POST array.

robertbasic
+1  A: 

what is really special in your code? standart pattern.

SM