True, I'd not considered that part of the hackiness either. For now,
I've gone ahead and done it.

The solution isn't perfect - other tweaks will need to be made to the
other functions in the Error helper, for instance - but it does appear
to work.

Here's my code:

//error.php - modelErrors() function
        function modelErrors()
        {
        $html =& new HtmlHelper;
        $models = func_get_args();
        $list = '';
        foreach ($models as $model)
        {
                if ( isset($this->validationErrors[$model]) )
                {
                        foreach ( $this->validationErrors[$model] as
$field => $errors )
                        {
                                foreach ( $errors as $error )
                                {
                                    foreach( $error as $item )
                                    {
                                        $list .= '<li>' . $item . '</
li>';
                                    }
                                }
                        }
                }
        }

        $output = '';
        if ( !empty($list) )
        {
                $output = '
                        <div id="error-report">
                                <h4>' . __('The following errors need
to be corrected:', true)                                                        
        .
                                                                '</h4>
                                <ul>
                                ' . $list . '
                                </ul>
                        </div>
                        ';
        }

        return $output;
    }

// validation.php - _evaluate() function
    function _evaluate($validation, $messageOnFail, $fieldName = null,
$params = array())
    {
        if ($validation)
        {
            return true;
        }

        if(!preg_match("/does not match pattern/",$messageOnFail))
        {
                if (!isset($params['message']))
                {
                    $params['message'] = Inflector::humanize($fieldName) . "
" . $messageOnFail . ".";
                }

                if ($params['message'])
                {
                    $this->model->validationErrors[$this->name][$fieldName][]
= $params['message'];
                }
        }
        $this->errorCount++;
        return false;
    }

Give that a try, and see if it works for you.

One thing you'll notice, and it may not be something that you want:
I've put an extra conditional in there so that any error messages
return from the validatePattern function don't get added to the array.
Reason I did this was because I'm pattern matching the email address,
but the only error I want to see is "this is not a valid email" - I
don't want to see the other one about it not matching the pattern.
Obviously if you're using patterns directly, this is not the way to
go.

On Feb 8, 1:27 pm, "mcgordon" <[EMAIL PROTECTED]> wrote:
> I totally agree that my solution is a hack. The deeper array would
> definitely be the way to go for multiple error mesages.  The only
> reason I didnt suggest it is that the validationErrors array is part
> of the core model class and I dont want to play around with its
> structure in case it breaks other things in the long run. If it works
> for you, post your code. Id love to see it.


--~--~---------~--~----~------------~-------~--~----~
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