views:

20

answers:

1

i have written validation class. now, is it ok to extend a form class from the validation class? or even extending the validation class from the request class?

i'm just not sure how to implement the registration process for a new user in a mvc. totally confuse.

Edit: i have found this zend tut here:

// application/controllers/GuestbookController.php
  class GuestbookController extends Zend_Controller_Action

  {
      // snipping indexAction()...

      public function signAction()
      {
          $request = $this->getRequest();
          $form    = new Application_Form_Guestbook();

          if ($this->getRequest()->isPost()) {
              if ($form->isValid($request->getPost())) {
                  $comment = new Application_Model_Guestbook($form->getValues());
                  $mapper  = new Application_Model_GuestbookMapper();
                  $mapper->save($comment);
                  return $this->_helper->redirector('index');
              }
          }

          $this->view->form = $form;
      }
  }  

but i do not understand how in case of wrong inputs you can go back to the form page now with filled input fields

$this->view->form = $form;

this just sets a value but does not redirect to registration.php. so how do i get to registration.php after this

if ($form->isValid($request->getPost())) {
    $comment = new Application_Model_Guestbook($form->getValues());
    $mapper  = new Application_Model_GuestbookMapper();
    $mapper->save($comment);
    return $this->_helper->redirector('index');
}
else {
    // ... do redirect to registration.php and fill input fields with set $_POST
}
A: 

I wouldn't extend it. They have different "scopes" (one inputs data, and the other validates data)...

I would suggest either Dependency Injection if you want to force validation, or simply the option of setting a validation object if necessary. I've done both before.

ircmaxell