I have tried various combinations for validation still nothing is
working.

This is my last attempt and it's still not validating an empty field,
I still get an empty database value (new id no content - instead of an
error message)

<?php
  class Category extends AppModel
  {
      var $name = 'Category';

    var $validate = array(
      'category' => array(
        'rule' => 'alphaNumeric',
        'required' => true
      )
    );

  }

?>

On May 6, 1:03 pm, matalina <matal...@gmail.com> wrote:
> I followed along with the blog tutorial and got that working with out
> a problem.  Now I'm modifying the blog tutorial for my own purposes
> since the basic technique was the same for this particular part of the
> project but now the fields are not validating.  When I had it as
> notEmpty it still posted an empty entry to the database.  And with it
> alphaNumeric it's still posting an empty entry.
>
> Can I get some help?
>
> Model:
>
> <?php
>   class Category extends AppModel
>   {
>       var $name = 'Category';
>
>       var $validate = array(
>                     'category' => 'alphaNumeric'
>             );
>
>   }
>
> ?>
>
> Controller:
>
> <?php
>   class CategoriesController extends AppController
>   {
>           var $name = 'Categories';
>
>         function index()
>     {
>                 $this->set('categories', $this->Category->find('all'));
>           }
>     function add()
>     {
>                   if (!empty($this->data))
>       {
>                           if ($this->Category->save($this->data))
>         {
>                                   $this->Session->setFlash('Your category has 
> been saved.');
>                                   $this->redirect(array('action' => 'index'));
>                           }
>                   }
>           }
>     function edit($id = null)
>     {
>             $this->Category->id = $id;
>             if (empty($this->data))
>       {
>                 $this->data = $this->Category->read();
>         } else
>       {
>                 if ($this->Category->save($this->data))
>         {
>                         $this->Session->setFlash('Your category has been 
> updated.');
>                         $this->redirect(array('action' => 'index'));
>                 }
>         }
>     }
>     function delete($id)
>     {
>         $this->Category->del($id);
>         $this->Session->setFlash('The category with id: '.$id.' has been
> deleted.');
>         $this->redirect(array('action'=>'index'));
>     }
>
>   }
> ?>
>
> View:
>
> <!-- File: /app/views/categories/add.ctp -->
>
> <h1>Add Post</h1>
> <?php
>         echo $form->create('');
>         echo $form->input('category');
>         echo $form->end('Save Category');
> ?>
>
> Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to