In case anyone else wants to know how i've done it, it's as simple as
this

Model

var $validate = array(
  'fieldName' => array('integer_optional' => array('rule' =>
array('optionalInteger', 'fieldName')))
);
// NB: integer_optional is the key to look up the error message

function optionalInteger($data, $fieldName) {
  if (strlen($data[$fieldName]) > 0) {
    return is_numeric($data);
  }

  return true;
}

I couldn't work out how to call an existing validation method (given
the 2 minutes I spent on it) so I just wrote my own since it was
trivial and quicker. I'm still interested to hear a better way to do
this, if one exists :)

Tim

On Mar 28, 8:56 pm, Tim W <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have some data that's optional, but if it's filled in it must be a
> decimal. Is there an easy way to do this with 1.2 validation? My
> current though is that I might create a custom validation rule, and
> from their if the field isn't blank then send it through to the built
> in validation code.
>
> Thanks
>
> Tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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