Just took at look at the code and your right franky, after you return
false from your custom function invalidFields() then calls $this-
>invalidate() itself overwriting the message you just wrote.

However this is not the case if you return true.

This may be a bit "wrong" but you can get around this like so

function ValidFun($ruleParams){
  $fieldName = array_keys($ruleParams);
  $fieldName = $fieldName[0];
  if ($conditions){
    // all validation passed
  } else {
   // validation failed
   $this->invalidate($fieldName, 'Your Error Message');
  }

  return true;
}

By always returning true invalidFields() will not set the error
message itself, but the Model::validationErrors will still contain the
invalid field with your error message and and so Model::validates()
will return the correct value of false.

On Jun 28, 8:45 am, francky06l <[EMAIL PROTECTED]> wrote:
> I am not sure that will work (I might be wrong) but it seems to me
> that the model->invalidate is called after your validFunc returning
> false (this call will oerwrite your message). I haven't tested,
> neither check the code deeply enough to know if the call to invalidate
> (into the validateField method) checks for an existing messages prior
> to call invalidate..
>
> Let me know :-)
> Thanks
>
> On Jun 28, 12:30 am, Geoff Ford <[EMAIL PROTECTED]> wrote:
>
> > Oops just reread the question.
>
> > To set the error message from within the ValidFunc you can use the
> > Model::invalidate($field, $value = null);
>
> > On Jun 28, 8:26 am, Geoff Ford <[EMAIL PROTECTED]> wrote:
>
> > > if believe that you can change the error message with
> > > var $validate = array(
> > >                 'directory' => array('error_mesasage' =>
> > > array(array('rule' => 'ValidFunc', 'message'=>'message'))
> > >         );
>
> > > On Jun 28, 5:32 am, francky06l <[EMAIL PROTECTED]> wrote:
>
> > > > I guess you can't do this using the model validation, but if your
> > > > validation function is in the current model, you could replace the
> > > > value $this->data['Model']['field'] and return true (in this way, this
> > > > will not be considered as an error).
> > > > If your goal is to correct the value, show it with a message, the
> > > > above is still valid (for the value) but I have no idea how to change
> > > > the message. You can have a look to the bakery (multiple validation),
> > > > Mariano has done work about validation messages into the view-side,
> > > > maybe there you could interact with it.
>
> > > > On Jun 27, 9:11 pm, phpjoy <[EMAIL PROTECTED]> wrote:
>
> > > > > ahoy,
>
> > > > > i have the following validation in a model:
> > > > >         var $validate = array(
> > > > >                 'directory' => array('rule' => 'ValidFunc', 
> > > > > 'message'=>'message')
> > > > >         );
>
> > > > >         function ValidFunc($value) {
> > > > > $newvalue = 'new' .$value;
> > > > > $value = $newvalue;
> > > > > case 1: /*message=1*/ return false;
> > > > > case 2: /*message=2*/ return false;
> > > > >         }
>
> > > > > there are 2 things i'm struggling to do:
> > > > > 1) change the validation message from the ValidFunc,
> > > > > 2) change $value for the form to $newvalue.
>
> > > > > anyone knows how i can do that?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to