Re: Setting Required Validation in a Model
On Sat, Dec 20, 2008 at 8:53 PM, Rob Wilkerson r...@robwilkerson.org wrote: On Dec 20, 8:10 pm, Rob Wilkerson r...@robwilkerson.org wrote: On Dec 20, 7:58 pm, Rob Wilkerson r...@robwilkerson.org wrote: If I were to simplify this example and simple ask that the login field be required, how would I do that? Do I really need the 'rule' key _and_ the 'allowEmpty' key? Would it suffice to remove the 'rule' key and just retain 'required' and 'allowEmpty'? And, as a follow up, what do I need to do to get the required class to appear? I set up my Address model with the following complete validation: public $validate = array ( 'street_address_1' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'Street address is required' ), 'city' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'City is required' ), 'state_id' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'State is required' ), 'zip_code' = array ( 'rule' = array ( 'postal', null, 'us' ), 'required' = true, 'allowEmpty' = false, 'message' = 'Expected a 5 digit U.S. zip code' ) ); I see the required class when I access /addresses/add, but not when I'm entering an address through another model. I have a Vendor that belongsTo an Address. I'm using the form on vendors/add where I've created a form with fields named Address.city, Address.zip_code, etc. Am I missing something? A solution to this is still eluding me, so I'm going to bump once and see if a little more visibility helps. I'm hoping to find out: 1. Do I really need the 'rule' key _and_ the 'allowEmpty' key? Would it suffice to remove the 'rule' key and just retain 'required' and 'allowEmpty'? 2. How do I get the required class to appear on div's surrounding a $form-input() that is part of an associated model? Thanks, all. -- Rob Wilkerson http://robwilkerson.org --~--~-~--~~~---~--~~ 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: Setting Required Validation in a Model
I never use allowEmpty or required = true. Simply use the rule notEmpty which means the field cannot be empty, thus required. And if a field doesnt have that rule, its not required, it works perfectly for me. --~--~-~--~~~---~--~~ 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: Setting Required Validation in a Model
On Mon, Dec 22, 2008 at 5:50 PM, gearvOsh mileswjohn...@gmail.com wrote: I never use allowEmpty or required = true. Simply use the rule notEmpty which means the field cannot be empty, thus required. And if a field doesnt have that rule, its not required, it works perfectly for me. Okay, that helps. At least I know I don't _need_ anything other than the rule value. Of course, that makes me wonder even more about why the other keys exist and how they behave. I'll give the book another read. Maybe I missed something. Any idea what it takes to get the form helper to automatically populate the required class in the generated markup? Thanks for your help. -- Rob Wilkerson http://robwilkerson.org --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Setting Required Validation in a Model
I'm trying to figure out how to set validation in one of my models (v1.2) and I don't understand the docs. In this case, I want to start simple and just indicate that in my Address model, street_address_1 is required. In the code below (borrowed from the book), I don't understand the breakdown. The way I read it is clearly incorrect because it looks like the 'alphaNumeric' rule is required and that doesn't make any sense to me. I also can't find any built-in required rule (though I do so notEmpty, minLength, etc.). If I were to simplify this example and simple ask that the login field be required, how would I do that? ?php class User extends AppModel { var $name = 'User'; var $validate = array( 'login' = array( 'alphaNumeric' = array( 'rule' = 'alphaNumeric', 'required' = true, 'message' = 'Alphabets and numbers only' ), 'between' = array( 'rule' = array('between', 5, 15), 'message' = 'Between 5 to 15 characters' ) ), 'password' = array( 'rule' = array('minLength', '8'), 'message' = 'Mimimum 8 characters long' ), 'email' = 'email', 'born' = array( 'rule' = 'date', 'message' = 'Enter a valid date', 'allowEmpty' = true ) ); } ? --~--~-~--~~~---~--~~ 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: Setting Required Validation in a Model
On Dec 20, 7:58 pm, Rob Wilkerson r...@robwilkerson.org wrote: If I were to simplify this example and simple ask that the login field be required, how would I do that? As it always seems to happen, I found my explicit answer in the book shortly after hitting Send, but that did lead to another question. Given: public $validate = array ( 'street_address_1' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'Street address is required' ), 'city' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'City is required' ) ); Do I really need the 'rule' key _and_ the 'allowEmpty' key? Would it suffice to remove the 'rule' key and just retain 'required' and 'allowEmpty'? Thanks. --~--~-~--~~~---~--~~ 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: Setting Required Validation in a Model
On Dec 20, 8:10 pm, Rob Wilkerson r...@robwilkerson.org wrote: On Dec 20, 7:58 pm, Rob Wilkerson r...@robwilkerson.org wrote: If I were to simplify this example and simple ask that the login field be required, how would I do that? Do I really need the 'rule' key _and_ the 'allowEmpty' key? Would it suffice to remove the 'rule' key and just retain 'required' and 'allowEmpty'? And, as a follow up, what do I need to do to get the required class to appear? I set up my Address model with the following complete validation: public $validate = array ( 'street_address_1' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'Street address is required' ), 'city' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'City is required' ), 'state_id' = array ( 'rule' = 'notEmpty', 'required' = true, 'allowEmpty' = false, 'message' = 'State is required' ), 'zip_code' = array ( 'rule' = array ( 'postal', null, 'us' ), 'required' = true, 'allowEmpty' = false, 'message' = 'Expected a 5 digit U.S. zip code' ) ); I see the required class when I access /addresses/add, but not when I'm entering an address through another model. I have a Vendor that belongsTo an Address. I'm using the form on vendors/add where I've created a form with fields named Address.city, Address.zip_code, etc. Am I missing something? Sorry about all of the variations on the same question. Being new, I'm trying to sort out a lot of things at once. :-) Thanks again. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---