Jules, have a look at my reply a moment ago to msg, 'returning or
exiting from methods of controllers'. The reason the form is
redisplayed empty is because you're redirecting. This causes a new
request to be made, so $this->data is empty and FormHelper has nothing
to fill in the form with.

If either validation or save fails, you usually want only to set a
flash msg without doing a redirect. This allows the rest of the action
to be processed, meaning that the form will simply be re-displayed.
Because $this->data still contains whatever the user submitted, the
form should contain the data.

As for comparing 2 fields:

var $validate = array(
        'field1' => array(
                'fieldComparison' => array(
                        'rule' => array('compareFieldValues', 'field2'),
                        'message' => 'field1 and field2 are the same!'
                )
        )
);

function compareFieldValues($field1 = array(), $other_field_name = null)
{
        foreach ($field as $key => $value)
        {
                if ($value === $this->data[$this->name][$other_field_name])
                {
                        return false;
                }
                else
                {
                        continue;
                }
        }
        return true;
}


On Mon, May 18, 2009 at 9:30 PM, Jules <[email protected]> wrote:
>
> When a submitted form fails a validation rule, the form is presented
> back to the user with their values intact.  This is obviously a good
> thing, as the user doesn't have to fill the whole thing in again.
>
> I have a form where I need to compare two of the submitted values to
> make sure they're not the same.  I can't, as far as I know, use a
> validation rule to compare two fields in the same form.  How can I
> display the form back the user with their values intact?  Currently I
> set a flash message, then redirect back to the form, but the user has
> to fill the form in again.
>
> 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