-- Mark Steudel <[EMAIL PROTECTED]> wrote (on Tuesday, 08 April 2008, 03:21 PM -0700): > I’m having a little bit of a problem getting the hang of validation, I think > I’m still thinking in Pear QuickForm mindset. > > I have the following code: > > // create form code > if( $admin->form->isValid( $_POST ) ) { > echo $admin->savePrimarySource( $admin->form->getValues() ); > } else { > echo $admin->form->render(); > } > > When I first load this page, I get the validation errors. My thought > was that it would detect whether or not the form has been POSTed or > not … but I’m guessing it’s just looking at what’s in $_POST (which is > nothing) and says hey your required fields are missing. What’s a good > way to validate a whole form in this fashion?
Zend_Form is de-coupled from both the MVC and HTTP; the idea is that you should be able to use it for a variety of purposes, some of which may have nothing to do with either of those two. If using the ZF MVC, check to see if the request is a POST: if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { $values = $form->getValues(); // usually you'll do something with the values and then // redirect after this... } } $this->view->form = $form; If you're not using the ZF MVC, check to see what the request method was: $method = $_SERVER['REQUEST_METHOD'] if ($method == 'POST') { // validate now.... } It's an extra step, but it ensures that you're explicitly checking the source of your form input. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/