Not sure if this is what you want to do; but in one place in my app
I've done some validation on an array of fields in my controller and
used the results of this to build a custom error message string that I
then set to the session:

            if (!empty($this->data)) {
                $err_msg = $this->_check_kpis($this->data);
                if (strcmp($err_msg, "") != 0)
                {
                    $this->Session->setFlash(__($err_msg, true));
                }
                else
                {
                  // Save the form
               }

before rendering the view again. The $err_msg that comes back from my
function call contains the customized message.

On Jul 28, 5:51 pm, brian <[email protected]> wrote:
> If you're concerned that the user won't immediately notice if there's
> an error (unlikely, as the form is redisplayed, but whatever) just add
> this at the top:
>
> if (!empty($form->validationErrors)) {
>
> and include a notice that there were errors and to check below (where
> the errors are displayed with each element). Displaying errors one at
> a time would be a huge waste of time for the user.
>
> On Tue, Jul 28, 2009 at 10:39 AM, Shaun<[email protected]> wrote:
>
> > I prefer to display form validation errors at the top of the form
> > rather than under each form field.  I would also like to display only
> > one error at a time.  I have the following code at the top of my form:
>
> > <?php
> > if ($form->isFieldError('user_username')){
> >        echo $form->error('user_username');
> > } elseif ($form->isFieldError('user_password')) {
> >        echo $form->error('user_password');
> > } elseif ($form->isFieldError('user_given_name')) {
> >        echo $form->error('user_given_name');
> > } elseif ($form->isFieldError('user_surname')) {
> >        echo $form->error('user_surname');
> > } elseif ($form->isFieldError('user_email')) {
> >        echo $form->error('user_email');
> > }
> > ?>
>
> > How can I move the nested if statements out of my view?  Thanks.
--~--~---------~--~----~------------~-------~--~----~
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