Re: Need little help with a validation rule
Hi guys thx for the responses @Brian i already have the notEmptY rule on each field. But the rule will fail is the field is not set. @starkey overriding model::save doesn't sound cake-ish to me... imo a custom validation rule will be more coherent @jstein thx for the hint On 30 Apr, 01:54, brian bally.z...@gmail.com wrote: I assumed the 'required'=true was obvious, given the parameters mentioned. I should have mentioned that, also. On Wed, Apr 29, 2009 at 6:27 PM, jstein jst...@image.dk wrote: On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote: Just use a rule (eg. notEmpty) for each of them. You'll get errors for whichever fields were not set. No, notEmpty will fail validation, if the field is present but empty. It will NOT fail, if the field is not set at all. If the field MUST be set, use 'required'=true (and still use the notEmpty rule, if empty values should not be allowed). Seehttp://book.cakephp.org/view/129/required I just learned the difference the hard way... ;-) I don't think the case when none of the fields are present can be handled by validation rules, but starkey has given a solution for this. Regards Jonathan --~--~-~--~~~---~--~~ 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: Need little help with a validation rule
Ernesto: I like to make custom validation methods when dealing with complex relationships between fields. http://edwardawebb.com/programming/php-programming/cakephp/validating-optional-fields-cakephp-dreaded-scenario On Apr 30, 4:31 am, Ernesto e.fanz...@gmail.com wrote: Hi guys thx for the responses @Brian i already have the notEmptY rule on each field. But the rule will fail is the field is not set. @starkey overriding model::save doesn't sound cake-ish to me... imo a custom validation rule will be more coherent @jstein thx for the hint On 30 Apr, 01:54, brian bally.z...@gmail.com wrote: I assumed the 'required'=true was obvious, given the parameters mentioned. I should have mentioned that, also. On Wed, Apr 29, 2009 at 6:27 PM, jstein jst...@image.dk wrote: On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote: Just use a rule (eg. notEmpty) for each of them. You'll get errors for whichever fields were not set. No, notEmpty will fail validation, if the field is present but empty. It will NOT fail, if the field is not set at all. If the field MUST be set, use 'required'=true (and still use the notEmpty rule, if empty values should not be allowed). Seehttp://book.cakephp.org/view/129/required I just learned the difference the hard way... ;-) I don't think the case when none of the fields are present can be handled by validation rules, but starkey has given a solution for this. Regards Jonathan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Need little help with a validation rule
Hello. I have a model with 5 fields model_id parameter_A parameter_B parameter_C parameter_D if none of them are set - the model should ignore the record if all of them are set - the model should save the record if some of them are set -the model should return a validation error what rule can i use? --~--~-~--~~~---~--~~ 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: Need little help with a validation rule
Just use a rule (eg. notEmpty) for each of them. You'll get errors for whichever fields were not set. On Wed, Apr 29, 2009 at 9:43 AM, Ernesto e.fanz...@gmail.com wrote: Hello. I have a model with 5 fields model_id parameter_A parameter_B parameter_C parameter_D if none of them are set - the model should ignore the record if all of them are set - the model should save the record if some of them are set -the model should return a validation error what rule can i use? --~--~-~--~~~---~--~~ 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: Need little help with a validation rule
In your model you can override the save() method to check if all fields are empty. If they are then ignore the record. If one or more are set then call parent::save()... using the validation rule Brian mentioned. On Apr 29, 9:43 am, Ernesto e.fanz...@gmail.com wrote: Hello. I have a model with 5 fields model_id parameter_A parameter_B parameter_C parameter_D if none of them are set - the model should ignore the record if all of them are set - the model should save the record if some of them are set -the model should return a validation error what rule can i use? --~--~-~--~~~---~--~~ 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: Need little help with a validation rule
On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote: Just use a rule (eg. notEmpty) for each of them. You'll get errors for whichever fields were not set. No, notEmpty will fail validation, if the field is present but empty. It will NOT fail, if the field is not set at all. If the field MUST be set, use 'required'=true (and still use the notEmpty rule, if empty values should not be allowed). See http://book.cakephp.org/view/129/required I just learned the difference the hard way... ;-) I don't think the case when none of the fields are present can be handled by validation rules, but starkey has given a solution for this. Regards Jonathan --~--~-~--~~~---~--~~ 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: Need little help with a validation rule
I assumed the 'required'=true was obvious, given the parameters mentioned. I should have mentioned that, also. On Wed, Apr 29, 2009 at 6:27 PM, jstein jst...@image.dk wrote: On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote: Just use a rule (eg. notEmpty) for each of them. You'll get errors for whichever fields were not set. No, notEmpty will fail validation, if the field is present but empty. It will NOT fail, if the field is not set at all. If the field MUST be set, use 'required'=true (and still use the notEmpty rule, if empty values should not be allowed). See http://book.cakephp.org/view/129/required I just learned the difference the hard way... ;-) I don't think the case when none of the fields are present can be handled by validation rules, but starkey has given a solution for this. Regards Jonathan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---