Re: possible bug? validation successful even though required fields are not empty
sorry Chris, you are absolutely correct. I misunderstood what jonkee posted. On Wed, May 14, 2008 at 9:06 PM, Chris Hartjes <[EMAIL PROTECTED]> wrote: > > On Wed, May 14, 2008 at 3:38 PM, Marc Schuetze <[EMAIL PROTECTED]> wrote: >> >> But the current behavior is not doing that. When a field is missing in >> a request it is not being picked up by the validation routine > > Wasn't this question already answered in this thread? If your > validation rules require that a certain field be present, then you > MUST specify that the field is required in your validation rules. > > > var $validate = array( > 'name' => VALID_NOT_EMPTY, > ); > > is not the same as > > var $validate = array( > 'name' => array('rule' => 'alphaNumeric', 'required' => true, > 'message' => 'Required') > ); > > If I am misunderstanding the issue, please correct me. > > -- > Chris Hartjes > Internet Loudmouth > Motto for 2008: "Moving from herding elephants to handling snakes..." > @TheKeyBoard: http://www.littlehart.net/atthekeyboard > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
On Wed, May 14, 2008 at 3:38 PM, Marc Schuetze <[EMAIL PROTECTED]> wrote: > > But the current behavior is not doing that. When a field is missing in > a request it is not being picked up by the validation routine Wasn't this question already answered in this thread? If your validation rules require that a certain field be present, then you MUST specify that the field is required in your validation rules. var $validate = array( 'name' => VALID_NOT_EMPTY, ); is not the same as var $validate = array( 'name' => array('rule' => 'alphaNumeric', 'required' => true, 'message' => 'Required') ); If I am misunderstanding the issue, please correct me. -- Chris Hartjes Internet Loudmouth Motto for 2008: "Moving from herding elephants to handling snakes..." @TheKeyBoard: http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
> But the current behavior is indeed correct. You simply cannot trust > that values that should be set in your form will be. If you get a > request that comes in missing a field, your validation routine needs > to pick that up. Otherwise, you'd need to do an isset() for each > required value after validation occurs. > --~--~-~--~~~---~--~~ But the current behavior is not doing that. When a field is missing in a request it is not being picked up by the validation routine --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
> What if there was a case where you didn't want to save all of the > fields again when you're updating a record? There are a few ways to go, the easiest probably being Model::saveField(): $this->User->id = 1 $this->User->saveField('username', 'new_username') Or use some more complex validation to make use of the 'on' key (http://book.cakephp.org/view/125/data-validation#on-131). Or if you need to update a few fields, you could save some queries by copying the data first, modifying the columns you want to change and then saving the data. But the current behavior is indeed correct. You simply cannot trust that values that should be set in your form will be. If you get a request that comes in missing a field, your validation routine needs to pick that up. Otherwise, you'd need to do an isset() for each required value after validation occurs. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
My understanding is that the controller should remove the field from the validation array: unset($this->ModelName->validate['field_name']); On Wed, May 14, 2008 at 12:22 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > What if there was a case where you didn't want to save all of the > fields again when you're updating a record? > > For instance, if a user is updating his or her User record, and wants > to edit a username and birthdate, for example. You probably wouldn't > have a form field for 'password' in this same place, so that field > would not be included in your array of data being saved, but even if > password is required, you wouldn't expect this to throw an error. > > I haven't done much w/ 1.2 validation, and I don't really know what > the difference is between allowEmpty and required, but in 1.1 if a > field was not present in your array of save data, it was not > validated. Perhaps 1.2 solves this all by using required to specify a > field has to be present in the array, and allowEmpty to say, if the > field is present, it can't be empty...? I have no idea... > > If you wanted to not allow a field to be saved, you can always > unset(this->data[Model][field]) or I believe there's an > 'expectedFields' attribute to the save function. > > On Apr 29, 2:55 pm, jonknee <[EMAIL PROTECTED]> wrote: >> > well my thinking is, if you wanted a field validated, you would have a >> > form field present for it, at which point it would pass this field >> > along for validation >> >> You should never trust your validation to the form values that should >> be coming in from the user (you should never trust *anything* from the >> user). The user could easily not pass form fields and could also >> easily pass values you don't expect.A model with a field marked as >> required should always be required, no matter the circumstances. >> >> Luckily, it appears CakePHP is doing just that. I just tried removing >> a form field for a model that had a required validation and it >> wouldn't save. I changed required=True to required=False and it saved >> just fine. >> >> I think the problem MarcS is having is simply a problem in his >> validation routine. Can you post some code? > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
What if there was a case where you didn't want to save all of the fields again when you're updating a record? For instance, if a user is updating his or her User record, and wants to edit a username and birthdate, for example. You probably wouldn't have a form field for 'password' in this same place, so that field would not be included in your array of data being saved, but even if password is required, you wouldn't expect this to throw an error. I haven't done much w/ 1.2 validation, and I don't really know what the difference is between allowEmpty and required, but in 1.1 if a field was not present in your array of save data, it was not validated. Perhaps 1.2 solves this all by using required to specify a field has to be present in the array, and allowEmpty to say, if the field is present, it can't be empty...? I have no idea... If you wanted to not allow a field to be saved, you can always unset(this->data[Model][field]) or I believe there's an 'expectedFields' attribute to the save function. On Apr 29, 2:55 pm, jonknee <[EMAIL PROTECTED]> wrote: > > well my thinking is, if you wanted a field validated, you would have a > > form field present for it, at which point it would pass this field > > along for validation > > You should never trust your validation to the form values that should > be coming in from the user (you should never trust *anything* from the > user). The user could easily not pass form fields and could also > easily pass values you don't expect.A model with a field marked as > required should always be required, no matter the circumstances. > > Luckily, it appears CakePHP is doing just that. I just tried removing > a form field for a model that had a required validation and it > wouldn't save. I changed required=True to required=False and it saved > just fine. > > I think the problem MarcS is having is simply a problem in his > validation routine. Can you post some code? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
The alphaNumeric rule may not be enough if you want spaces, hyphens, etc. to be accepted as well. If so, try 'rule' => array('minLength', 1) instead. On Tue, Apr 29, 2008 at 3:36 PM, Marc Schuetze <[EMAIL PROTECTED]> wrote: > > ok I'll be sure to do that. > > thanks for your help > > > > On Tue, Apr 29, 2008 at 8:28 PM, jonknee <[EMAIL PROTECTED]> wrote: > > > > On Apr 29, 3:13 pm, MarcS <[EMAIL PROTECTED]> wrote: > > > I don't think there's a bug in it. > > > > > > all I have is this > > > > > > var $validate = array( > > > 'name' => VALID_NOT_EMPTY, > > > 'url' => array('rule' => 'url','message' => 'this field > must contain a valid url') > > > ); > > > > Not a bug per se, just not enough to tell CakePHP that the field is > > required. VALID_NOT_EMPTY is a regex and will only be executed if a > > value is passed. That's somewhat lame, but here's what you do if you > > want it really to be required (just for the name field, you can get > > the idea): > > > > var $validate = array( > > 'name' => array('rule' => 'alphaNumeric', 'required' => true, > > 'message' => 'Required') > > ); > > > > You have to set required=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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
ok I'll be sure to do that. thanks for your help On Tue, Apr 29, 2008 at 8:28 PM, jonknee <[EMAIL PROTECTED]> wrote: > > On Apr 29, 3:13 pm, MarcS <[EMAIL PROTECTED]> wrote: > > I don't think there's a bug in it. > > > > all I have is this > > > > var $validate = array( > > 'name' => VALID_NOT_EMPTY, > > 'url' => array('rule' => 'url','message' => 'this field > must contain a valid url') > > ); > > Not a bug per se, just not enough to tell CakePHP that the field is > required. VALID_NOT_EMPTY is a regex and will only be executed if a > value is passed. That's somewhat lame, but here's what you do if you > want it really to be required (just for the name field, you can get > the idea): > > var $validate = array( > 'name' => array('rule' => 'alphaNumeric', 'required' => true, > 'message' => 'Required') > ); > > You have to set required=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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
On Apr 29, 3:13 pm, MarcS <[EMAIL PROTECTED]> wrote: > I don't think there's a bug in it. > > all I have is this > > var $validate = array( > 'name' => VALID_NOT_EMPTY, > 'url' => array('rule' => 'url','message' => 'this field must > contain a valid url') > ); Not a bug per se, just not enough to tell CakePHP that the field is required. VALID_NOT_EMPTY is a regex and will only be executed if a value is passed. That's somewhat lame, but here's what you do if you want it really to be required (just for the name field, you can get the idea): var $validate = array( 'name' => array('rule' => 'alphaNumeric', 'required' => true, 'message' => 'Required') ); You have to set required=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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
I don't think there's a bug in it. all I have is this var $validate = array( 'name' => VALID_NOT_EMPTY, 'url' => array('rule' => 'url','message' => 'this field must contain a valid url') ); I had a bug in my script which caused both name and url to not be passed and that's how I noticed that it still validates and just leaves the fields empty. On Apr 29, 7:55 pm, jonknee <[EMAIL PROTECTED]> wrote: > > well my thinking is, if you wanted a field validated, you would have a > > form field present for it, at which point it would pass this field > > along for validation > > You should never trust your validation to the form values that should > be coming in from the user (you should never trust *anything* from the > user). The user could easily not pass form fields and could also > easily pass values you don't expect.A model with a field marked as > required should always be required, no matter the circumstances. > > Luckily, it appears CakePHP is doing just that. I just tried removing > a form field for a model that had a required validation and it > wouldn't save. I changed required=True to required=False and it saved > just fine. > > I think the problem MarcS is having is simply a problem in his > validation routine. Can you post some code? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
> well my thinking is, if you wanted a field validated, you would have a > form field present for it, at which point it would pass this field > along for validation You should never trust your validation to the form values that should be coming in from the user (you should never trust *anything* from the user). The user could easily not pass form fields and could also easily pass values you don't expect.A model with a field marked as required should always be required, no matter the circumstances. Luckily, it appears CakePHP is doing just that. I just tried removing a form field for a model that had a required validation and it wouldn't save. I changed required=True to required=False and it saved just fine. I think the problem MarcS is having is simply a problem in his validation routine. Can you post some code? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
yeah I can see that argument. thanks for your replies On Apr 29, 6:59 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > well my thinking is, if you wanted a field validated, you would have a > form field present for it, at which point it would pass this field > along for validation > > On Apr 29, 1:55 pm, MarcS <[EMAIL PROTECTED]> wrote: > > > yeah I guess I'll have to do that. > > But it doesn't make much sense to me that cake will save records even > > though validation rules say that the field shouldn't be empty. > > There ought to be an option which would force it to validate all > > fields, including those that have not been passed. > > > On Apr 29, 6:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > Cake only validates the fields you're passing to it, so since there is > > > no 'b' in your data save, it's not being validated > > > > As far as I know it still works this way in 1.2; but I could be wrong; > > > try passing array('a'=>'food', 'b'=>'') > > > > On Apr 29, 1:50 pm, MarcS <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > I'm wondering whether the following is desired behaviour or it is a > > > > bug. > > > > > let's say a table has 2 columns a and b. B is required. > > > > when I do > > > > $this->Model->save('a' => 'foo'); > > > > the record validates even though a is required. It seems like fields > > > > that are not included in the data passed to save() are just ignored. > > > > Is that supposed to be that way? Wouldn't make much sense to me > > > > > Marc --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
> But it doesn't make much sense to me that cake will save records even > though validation rules say that the field shouldn't be empty. Again, you're not saving the invalid data, you're only saving the valid data. Validation is about making sure data that's going to be saved is correct according to your rules. If you want to check another field that won't be saved first, then you need to change your validation rules to take that into account. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
well my thinking is, if you wanted a field validated, you would have a form field present for it, at which point it would pass this field along for validation On Apr 29, 1:55 pm, MarcS <[EMAIL PROTECTED]> wrote: > yeah I guess I'll have to do that. > But it doesn't make much sense to me that cake will save records even > though validation rules say that the field shouldn't be empty. > There ought to be an option which would force it to validate all > fields, including those that have not been passed. > > On Apr 29, 6:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > Cake only validates the fields you're passing to it, so since there is > > no 'b' in your data save, it's not being validated > > > As far as I know it still works this way in 1.2; but I could be wrong; > > try passing array('a'=>'food', 'b'=>'') > > > On Apr 29, 1:50 pm, MarcS <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I'm wondering whether the following is desired behaviour or it is a > > > bug. > > > > let's say a table has 2 columns a and b. B is required. > > > when I do > > > $this->Model->save('a' => 'foo'); > > > the record validates even though a is required. It seems like fields > > > that are not included in the data passed to save() are just ignored. > > > Is that supposed to be that way? Wouldn't make much sense to me > > > > Marc --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
How does it not make sense to you? If you are not attempting to save the data, why do you care if it's valid? Quite the contrary; validating data I'm not trying to save wouldn't make much sense. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
yeah I guess I'll have to do that. But it doesn't make much sense to me that cake will save records even though validation rules say that the field shouldn't be empty. There ought to be an option which would force it to validate all fields, including those that have not been passed. On Apr 29, 6:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Cake only validates the fields you're passing to it, so since there is > no 'b' in your data save, it's not being validated > > As far as I know it still works this way in 1.2; but I could be wrong; > try passing array('a'=>'food', 'b'=>'') > > On Apr 29, 1:50 pm, MarcS <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I'm wondering whether the following is desired behaviour or it is a > > bug. > > > let's say a table has 2 columns a and b. B is required. > > when I do > > $this->Model->save('a' => 'foo'); > > the record validates even though a is required. It seems like fields > > that are not included in the data passed to save() are just ignored. > > Is that supposed to be that way? Wouldn't make much sense to me > > > Marc --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: possible bug? validation successful even though required fields are not empty
Cake only validates the fields you're passing to it, so since there is no 'b' in your data save, it's not being validated As far as I know it still works this way in 1.2; but I could be wrong; try passing array('a'=>'food', 'b'=>'') On Apr 29, 1:50 pm, MarcS <[EMAIL PROTECTED]> wrote: > Hi, > > I'm wondering whether the following is desired behaviour or it is a > bug. > > let's say a table has 2 columns a and b. B is required. > when I do > $this->Model->save('a' => 'foo'); > the record validates even though a is required. It seems like fields > that are not included in the data passed to save() are just ignored. > Is that supposed to be that way? Wouldn't make much sense to me > > Marc --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
possible bug? validation successful even though required fields are not empty
Hi, I'm wondering whether the following is desired behaviour or it is a bug. let's say a table has 2 columns a and b. B is required. when I do $this->Model->save('a' => 'foo'); the record validates even though a is required. It seems like fields that are not included in the data passed to save() are just ignored. Is that supposed to be that way? Wouldn't make much sense to me Marc --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---