View Single Post
  #5 (permalink)  
Old 05-10-2008, 08:24 PM
kuba kuba is offline
Junior Member
 
Join Date: Mar 2008
Posts: 26
Default

hi nwim,

form handling doesn't need to be acomplished by Zend_Form and it doesn't matter what templating system you're using (either Zend_View or Smarty, etc.).

all you need to do is eg.:

PHP Code:
class IndexController
{
   public function 
registerAction
   
{
      
$request $this->getRequest();
      if (
$request->isPost()) {
         
//fragment of code eclosed by this if clause will execute only if there is any post data send by a form
         
$errors = array();
         
//if u want to retrieve form field do as follows ('username' is example field name)
         //it is prefered way to $username = $_POST['username']
         
$username $request->getPost('username');
         
//now if you want to validate for 'username' length
         
$validator = new Zend_Validate_StringLength(8);
         if (
$validator->isValid($username)) {
            
// user name appears to be valid
         
} else {
            
// user name is invalid; save the reason
            
foreach ($validator->getMessages() as $messageId => $message) {
               
$errors['username'] = "Validation failure '$messageId': $message";
            }
         }
      
// make errors array available to your view
      
$this->view->errors $errors;
      }
   }

I hope this example gave you a little bit of understanding on form validating, however there is much more to know, like validator chains

Read more on zend framework's manual on official site

Last edited by kuba : 05-11-2008 at 11:57 AM.
Reply With Quote