Re: Validation Help

2011-01-13 Thread rgreenphotodesign
Here are my model rules..


'tin' = array(
//removed because not alll providers will have TIN
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please provide a Tax ID for your 
organization.',
'allowEmpty' = false,
'required' = true,
'last' = true, // Stop validation after this 
rule
//'on' = 'create', // Limit validation to 
'create' or 'update'
operations
),
'ssn' = array(
'rule' = array('ssn', null),
'message' = 'The Tax ID must be 9 characters 
long (excluding -)',
'last' = true

),
),
'name' = array(
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please provide a Legal 
Organization Name',
'allowEmpty' = false,
'required' = true,
'last' = true

)
),
'address' = array(
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please enter one line for 
address',
'allowEmpty' = false,
'required' = true,
'last' = true
)
),

'countries_id' = array(
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please select Country',
'allowEmpty' = false,
'required' = true,
'last' = true
)
),
'states_id' = array(
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please select State',
'allowEmpty' = false,
'required' = true,
'last' = true
)
),
'cities_id' = array(
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please select City',
'allowEmpty' = false,
'required' = true,
'last' = true
)
),
'zip' = array(
'notempty' = array(
'rule' = array('notempty'),
'message' = 'Please select Zip',
'allowEmpty' = false,
'required' = true,
'last' = true
)
)
);

Is it being caused by the required/allowEmpty combo?

On Jan 13, 10:32 am, rgreenphotodesign rgr...@rgreenphotography.com
wrote:
 I'm working on validation between two model model1 hasMany model2. I
 have a two step process where in the end users first view they need to
 enter a subset of data for both model1  2. Once this is complete,
 they're then allowed to complete the entire process which includes
 additional data for each model that needs to be validated at that
 point.

 First step in my process:

 First view contains a name field for model1 and a username for model2.
 Sent to model1 controller. In the controller I'm doing the following

 $this-Model1-set($this-data);
 if($this-Model1-validates(array('fieldList' = array('name' {
 //perform save with validate set to false

 }

 with or without the fieldList is looks to be generating the same
 results. All validation rules are processed for the model. In the
 process of testing I've eliminated model2 from the equation because I
 can't get model1 to work. Ultimately I'd like to be able to choose a
 subset of rules for both model 1  2 in this process. If I'm
 understanding correctly $this-Model-saveAll($this-data,
 array('validate' = 'only')) would still execute all validation rules.

 Any ideas on why even on the basic example why the fieldList isn't
 working? Am I missing something?

 I'm on Cake 1.3.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.

Re: Validation Help

2011-01-13 Thread rgreenphotodesign
The answer I found was...

no need for allowEmpty or required in notempty rule (that I can see).
Have to do the following to get both models to validate:

$this-Model1-set($this-data)
$this-Model1-Model2-set($this-data) // I would think this line is
all that would be needed, but you need both set statements

then:
if($this-Model1-validates(array('fieldList' = array('field names
for model1)))  $this-Model1-Model2-validates(array('fieldList' =
array('field names for model 2'


If there is a better way, I'd love to learn!

Thanks Russ
On Jan 13, 11:08 am, rgreenphotodesign rgr...@rgreenphotography.com
wrote:
 Here are my model rules..

                 'tin' = array(
                         //removed because not alll providers will have TIN
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please provide a Tax ID for 
 your organization.',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true, // Stop validation after this 
 rule
                                 //'on' = 'create', // Limit validation to 
 'create' or 'update'
 operations
                         ),
                         'ssn' = array(
                                 'rule' = array('ssn', null),
                                 'message' = 'The Tax ID must be 9 characters 
 long (excluding -)',
                                 'last' = true

                         ),
                 ),
                 'name' = array(
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please provide a Legal 
 Organization Name',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true

                         )
                 ),
                 'address' = array(
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please enter one line for 
 address',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true
                         )
                 ),

                 'countries_id' = array(
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please select Country',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true
                         )
                 ),
                 'states_id' = array(
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please select State',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true
                         )
                 ),
                 'cities_id' = array(
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please select City',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true
                         )
                 ),
                 'zip' = array(
                         'notempty' = array(
                                 'rule' = array('notempty'),
                                 'message' = 'Please select Zip',
                                 'allowEmpty' = false,
                                 'required' = true,
                                 'last' = true
                         )
                 )
         );

 Is it being caused by the required/allowEmpty combo?

 On Jan 13, 10:32 am, rgreenphotodesign rgr...@rgreenphotography.com
 wrote:







  I'm working on validation between two model model1 hasMany model2. I
  have a two step process where in the end users first view they need to
  enter a subset of data for both model1  2. Once this is complete,
  they're then allowed to complete the entire process which includes
  additional data for each model that needs to be validated at that
  point.

  First step in my process:

  First view contains a name field for model1 and a username for model2.
  Sent to model1 controller. In the controller I'm doing the following

  $this-Model1-set($this-data);
  if($this-Model1-validates(array('fieldList' = array('name' {
  //perform save with validate set to false

  }

  with or without the fieldList is looks to be generating the same
  

RE: Validation Help - All code Included - Figured Out

2009-10-19 Thread Dave Maharaj :: WidePixels.com

I got it working.

Dave

-Original Message-
From: Dave Maharaj :: WidePixels.com [mailto:d...@widepixels.com] 
Sent: October-19-09 2:16 PM
To: cake-php@googlegroups.com
Subject: Validation Help - All code Included


This is driving me crazy.
User Model:
 
var $validate = array(
'username' = array(
'usernameRule-1' = array(
'rule' = array(
'notEmpty'),  
'message' = 'Please choose a Username',
'required' = true,
'allowEmpty' = false,
'last' = true),
   
'usernameRule-2' = array(
'rule' = array(
'minLength', 8),  
'message' = 'Username must be 8 characters or more',
'required' = true,
'allowEmpty' = false,
'last' = true)
  
   )
);

View:
?php echo $form-create('User', array('controller' = 'user',  'action' =
'registration'));? ?php echo $form-input('User.username');? ?php echo
$form-end('Submit');? /div

Controller:
function registration()
{
if (!empty($this-data)) {

if ($this-User-validates()) {
$this-Session-setFlash('All valid.');
 
 } else {
$errors = $this-User-invalidFields();
debug($errors);
  $this-Session-setFlash('There was an error signing up.
Please, try again.');
 }
}
}

I removed everything but 1 field.
No matter what I enter all I get is Please choose a Username. Enter 100
characters and same message.

$errors returns:
I have abcdefghijklmnop as a username, more than 8, not emptydoes not
matter what I enter it always the same thing.

Array
(
[username] = Please choose a Username
)

Please someone, anyone letmeknow what I am doing wrong?

Thanks

Dave




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Validation Help

2009-09-15 Thread mikeottinger

Hi Dave, you might check your spelling real quick: minLenght should be
minLength. That's probably why your length validation is always
passing.

On Sep 15, 8:30 am, Dave Maharaj :: WidePixels.com
d...@widepixels.com wrote:
 I am finally getting around to implementing the validation rules but seem to
 be not quite understanding it or something.

 I have this set up to validate Username:
 
 'username' = array(
              'user-notempty' = array(
                   'rule' = array(
                       'minLenght', 8),
                   'required' = true,
                   'allowEmpty' = false,
                   'last' = true,
                   'message' = 'User name must be a minimun of 8
 characters.'),
              'user-unique' = array(
                 'rule' = array('checkUnique', 'username'),
                 'message' = 'Username taken. Use another')),
 

 Now it checks the unique factor just fine if there is a match when I test it
 but if i enter a Username that is less than 8 characters it does nothing in
 validation. It passes as OK.

 I also can not seem to validate fields that are not  in a database such as
 when I want to change the password. User enters new password in new_pass
 field and new_confirm in new_confirm field. There are no fields in the db
 for these fields but i added :

 'new_confirm' = array(
              'notempty' = array(
                   'rule' = array(
                       'minLenght', 8),
                   'required' = true,
                   'allowEmpty' = false,
                   'message' = 'Please confirm your password.'
                   )
              ),

 'new_pass' = array(
              'notempty' = array(
                   'rule' = array(
                       'minLenght', 8),
                   'required' = true,
                   'allowEmpty' = false,
                   'message' = 'Please enter a password with minimum 8
 characters.'
                   )
              ),

 I read the cookbook validation section and it makes sense to me but
 obviously am doing something wrong.

 Ideas where I went wrong?

 Thanks

 Dave
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



RE: Validation Help

2009-09-15 Thread Dave Maharaj :: WidePixels.com

Good looking out! Thanks man.

It all looks the same when you stare at it for hours. Fresh eye.

Thanks,

Dave

-Original Message-
From: mikeottinger [mailto:mikeottin...@gmail.com] 
Sent: September-15-09 1:32 PM
To: CakePHP
Subject: Re: Validation Help


Hi Dave, you might check your spelling real quick: minLenght should be
minLength. That's probably why your length validation is always passing.

On Sep 15, 8:30 am, Dave Maharaj :: WidePixels.com
d...@widepixels.com wrote:
 I am finally getting around to implementing the validation rules but 
 seem to be not quite understanding it or something.

 I have this set up to validate Username:
 
 'username' = array(
              'user-notempty' = array(
                   'rule' = array(
                       'minLenght', 8),
                   'required' = true,
                   'allowEmpty' = false,
                   'last' = true,
                   'message' = 'User name must be a minimun of 8 
 characters.'),
              'user-unique' = array(
                 'rule' = array('checkUnique', 'username'),
                 'message' = 'Username taken. Use another')), 

 Now it checks the unique factor just fine if there is a match when I 
 test it but if i enter a Username that is less than 8 characters it 
 does nothing in validation. It passes as OK.

 I also can not seem to validate fields that are not  in a database 
 such as when I want to change the password. User enters new password 
 in new_pass field and new_confirm in new_confirm field. There are no 
 fields in the db for these fields but i added :

 'new_confirm' = array(
              'notempty' = array(
                   'rule' = array(
                       'minLenght', 8),
                   'required' = true,
                   'allowEmpty' = false,
                   'message' = 'Please confirm your password.'
                   )
              ),

 'new_pass' = array(
              'notempty' = array(
                   'rule' = array(
                       'minLenght', 8),
                   'required' = true,
                   'allowEmpty' = false,
                   'message' = 'Please enter a password with minimum 8 
 characters.'
                   )
              ),

 I read the cookbook validation section and it makes sense to me but 
 obviously am doing something wrong.

 Ideas where I went wrong?

 Thanks

 Dave


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: validation help

2009-05-07 Thread arif hossen
I think it should be:

?php
 class Category extends AppModel
 {
 var $name = 'Category';
   var $validate = array(
 'category' = array(
   'rule' = 'alphaNumeric',
   'required' = true,
   'allowEmpty'=false
 )
   );
 }
?





On Thu, May 7, 2009 at 7:57 AM, Dr. Loboto drlob...@gmail.com wrote:


 Output $this-data in controller and check actual data you try to
 save.

 On May 7, 5:35 am, matalina matal...@gmail.com wrote:
  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 --
 
   h1Add Post/h1
   ?php
   echo $form-create('');
   echo $form-input('category');
   echo $form-end('Save Category');
   ?
 
   Thanks in advance.
 



-- 
Regards,
Mohammad Arif Hossen
Junior Web Developer
United Group International(UGIBD)
Mobile: +88 01714355911

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: validation help

2009-05-07 Thread matalina

arif's sugggestion didn't work either

Dr. Loboto I'm not sure how that will help since the data is saving to
the database correctly.  When I put in an empty field it saves the
empty field instead of outputting an error message.  When I put in a
category name it saves it.

Gwoo #2:  But the data is saving when I have data in there doesn't
that indicate the form is sending correctly?

Gwoo #1: pr outputs AppModel Object so I'm assuming if it printed
Category Object then I would have found it.  This seems to be the
error.  How can I fix this?  Is this an inflection problem with
category and categories?

Thanks for all the help.

On May 6, 10:56 pm, arif hossen arifhossen2...@gmail.com wrote:
 I think it should be:

 ?php
  class Category extends AppModel
  {
      var $name = 'Category';
    var $validate = array(
      'category' = array(
        'rule' = 'alphaNumeric',
        'required' = true,
        'allowEmpty'=false
      )
    );
  }
 ?



 On Thu, May 7, 2009 at 7:57 AM, Dr. Loboto drlob...@gmail.com wrote:

  Output $this-data in controller and check actual data you try to
  save.

  On May 7, 5:35 am, matalina matal...@gmail.com wrote:
   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 --

h1Add Post/h1
?php
        echo $form-create('');
        echo $form-input('category');
        echo $form-end('Save Category');
?

Thanks in advance.

 --
 Regards,
 Mohammad Arif Hossen
 Junior Web Developer
 United Group International(UGIBD)
 Mobile: +88 01714355911

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: validation help

2009-05-07 Thread matalina

I think I figured it out I had my model file named wrong.

yep that was the problem thanks for the help.

On May 7, 8:16 am, matalina matal...@gmail.com wrote:
 arif's sugggestion didn't work either

 Dr. Loboto I'm not sure how that will help since the data is saving to
 the database correctly.  When I put in an empty field it saves the
 empty field instead of outputting an error message.  When I put in a
 category name it saves it.

 Gwoo #2:  But the data is saving when I have data in there doesn't
 that indicate the form is sending correctly?

 Gwoo #1: pr outputs AppModel Object so I'm assuming if it printed
 Category Object then I would have found it.  This seems to be the
 error.  How can I fix this?  Is this an inflection problem with
 category and categories?

 Thanks for all the help.

 On May 6, 10:56 pm, arif hossen arifhossen2...@gmail.com wrote:

  I think it should be:

  ?php
   class Category extends AppModel
   {
       var $name = 'Category';
     var $validate = array(
       'category' = array(
         'rule' = 'alphaNumeric',
         'required' = true,
         'allowEmpty'=false
       )
     );
   }
  ?

  On Thu, May 7, 2009 at 7:57 AM, Dr. Loboto drlob...@gmail.com wrote:

   Output $this-data in controller and check actual data you try to
   save.

   On May 7, 5:35 am, matalina matal...@gmail.com wrote:
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 --

 h1Add Post/h1
 ?php
         echo $form-create('');
         echo $form-input('category');
         echo $form-end('Save Category');
 ?

 Thanks in advance.

  --
  Regards,
  Mohammad Arif Hossen
  Junior Web Developer
  United Group International(UGIBD)
  Mobile: +88 01714355911
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: validation help

2009-05-06 Thread matalina

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 --

 h1Add 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
-~--~~~~--~~--~--~---



Re: validation help

2009-05-06 Thread Gwoo

Are you sure that cake is finding your model? pr($this-Category);
inside your controller. If you see an AppModel instance rather than a
Category instance then you know cake is unable to find the model.

Also, make sure that the form input is correctly sending the fields
you are expecting. If you are missing 'category' inside of $this-data
['Category'] then the validation will not be checked.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: validation help

2009-05-06 Thread Dr. Loboto

Output $this-data in controller and check actual data you try to
save.

On May 7, 5:35 am, matalina matal...@gmail.com wrote:
 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 --

  h1Add 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
-~--~~~~--~~--~--~---