I'm pretty sure i know what you are trying to do (in my application an
address model requires one of: flat_number, house_number or house_name).

In your before filter you can add and remove the validation rules based on
what data is available. Can you do a var_dump() of $this->request->data
that'll help me show you what i mean.

On Fri, Jun 8, 2012 at 10:58 PM, Michael Gaiser <[email protected]> wrote:

> I have added the validation rule already to the model and it works when
> there is data supplied to it, but I still need a way to force it to run the
> rule even if $this->request->data is empty when saving. I need to be able
> to tell it to run the rule because even if that field is empty, there might
> be another one that has the data. How do you get a rule to run even if the
> field its attached to doesnt have any data? How do you detect that out of
> the 4 possible links, none were selected to be saved?
>
> On Fri, Jun 8, 2012 at 4:19 PM, veganista <[email protected]> wrote:
>
>> I have done this before in (1.3) but it wasn't a pretty solution.
>>
>> If your using 2.2 you might want to take a look at this:
>> http://book.cakephp.org/2.0/en/models/data-validation.html#dynamically-change-validation-rules
>>
>> You could use that in the beforeValidate() callback of the model and
>> choose what validation rules to add based on the data supplied.
>>
>>
>>
>> On Friday, June 8, 2012 10:13:31 AM UTC+2, Michael wrote:
>>>
>>> So I need to check that at least one field out of four is being set
>>> before I will allow to save. The validation rule works great as long as you
>>> have something sent to it, but since all the option fields have an empty
>>> slot, it would be easy to pass an array with all the right bits of info for
>>> that table except for one of the four ids. Since none of the four had data
>>> sent to them, their validation rule never gets called and it allows it to
>>> save. Any ideas how to get around this? I have tried to play around with
>>> the 'required' flag, but it really doesn't seem to be what I am really
>>> looking for since it would require all four to be set before allowing it to
>>> save. Any ideas? Thanks in advance.
>>>
>>  --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> [email protected] For more options, visit this group
>> at http://groups.google.com/group/cake-php
>>
>
>  --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to