@Jeremy:

*It's just that I've never had to do any date manipulation or conversion to
get it to validate*

That was my point exactly ... I don't mind converting at all but I honestly
really didn't think I would have to. It would only make sense that if Cake
"automagically" sets the date into an array, accepts the array when writing
to the db, and provides a validation rule for date ... why would it not
validate the date as an array?

Anyhow, if i don't convert it it complains that param 2 of preg_match needs
to be a string and I would normally agree unless running the array through a
foreach which I was under the assumption Cake would do in the case of an
array.

Since I've been playing around with it I've come up with a few ways to
convert it over in the model, some more straightforward than others.

- Ed

On Wed, Apr 28, 2010 at 12:20 AM, Jeremy Burns <[email protected]> wrote:

> As an aside, is the date being sent in via the form helper using the date
> input? It's just that I've never had to do any date manipulation or
> conversion to get it to validate.
>
> Jeremy Burns
> [email protected] <[email protected]>
>
>
> On 27 Apr 2010, at 23:29, Ed Propsner wrote:
>
> Well I either never tried to convert to a string or I mucked something up
> (the latter of the two seems most likely) because it took the string with no
> arguments, go figure. I expected as much.
>
> Now here is a new question. Let's say (hypothetically) that I was so anal
> retentive that I absolutely had to do the date conversion in the model
> instead of the controller, I assume there must be an easy way?
>
> I can get close with the following code, but sill no cigar.
>
> [rule]
>                                   'date' => array(
>    'convertDate' => array(
>  'rule' => 'date',
>  'message' => 'Date is required',
>  'allowEmpty' => false
>  )
>    )
> [/rule]
>
> [function]
>                                  function convertDate($field)
>                          {
>                       $date =
> $field['date']['year'].'-'.$field['date']['month'].'-'.$field['date']['day'];
>                        return $date;
>                          }
> [/function]
>
> I can get the converted date into the rule but it usually just displays it
> as the 'message'. How do I validate the returned value of convertDate()
> instead of field 'date' ?
>
> - Ed
>
> On Tue, Apr 27, 2010 at 3:49 PM, Ed Propsner <[email protected]> wrote:
>
>> I'm relatively sure the first thing I did was to convert it over to a
>> string but still ended up with the same error, I'll try it again though to
>> be sure. Perhaps I'm just expecting too much from Cake? After all, Cake
>> "automagically" structured the date as an array and it will accept and write
>> it to the db as an array, I just assumed  that it would convert it back or
>> do some other "automagic" in the case of validation.
>>
>>
>> On Tue, Apr 27, 2010 at 3:24 PM, John Andersen 
>> <[email protected]>wrote:
>>
>>> As far as I can read from the api, then the validation expects a date
>>> as a string, and you seems to pass it an array!
>>> Please correct me if I am wrong :)
>>> Enjoy,
>>>   John
>>>
>>> On Apr 27, 8:29 am, Ed Propsner <[email protected]> wrote:
>>> > I'm having a few problems trying to validate a date and I'm not sure
>>> what
>>> > I'm doing wrong ...
>>> >
>>> > [date] => Array
>>> >                 (
>>> >                     [month] =>
>>> >                     [day] =>
>>> >                     [year] =>
>>> >                 )
>>> >
>>> >  I have the validation rule in the model set up close to the example
>>> > in the book.
>>> >
>>> > 'dob' => array(
>>> >         'rule' => 'date',
>>> >         'message' => 'Some message here.',
>>> >         'allowEmpty' => false
>>> >     )
>>> >
>>> > The book says if no keys are supplied the default key that will be
>>> > used is 'ymd' ... that's fine.
>>> >
>>> > I'm not concerned about the format, I would just like to ensure the
>>> > fields are not empty.
>>> >
>>> > When I submit the form it returns the following complaint:
>>> >
>>> > " preg_match() expects parameter 2 to be string, array given "
>>> >
>>> > What am I messing up this time ?
>>> >
>>> > - Ed
>>> >
>>> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help
>>> others with their CakePHP related questions.
>>> >
>>> > You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> > To post to this group, send email to [email protected]
>>> > To unsubscribe from this group, send email to
>>> > [email protected]<cake-php%[email protected]>For
>>> >  more options, visit this group athttp://
>>> groups.google.com/group/cake-php?hl=en
>>>
>>> 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.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]<cake-php%[email protected]>For
>>>  more options, visit this group at
>>> http://groups.google.com/group/cake-php?hl=en
>>>
>>
>>
>
> 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.
> To post to this group, send email to [email protected]
> 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
>
>
>  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.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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.
To post to this group, send email to [email protected]
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

Reply via email to