Re: Repopulating a form after an error
On Mon, May 18, 2009 at 11:12 PM, Jules wrote: > > Thank you Brian, I wasn't aware that you could write a custom > validation function. > > However, I've tried both methods, and am still having the same > problem. In both cases, the form comes back with fresh data in it. > > I have confirmed that the custom validation rule is firing. Can you post the controller action code? It may be something in there. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Repopulating a form after an error
Thank you Brian, I wasn't aware that you could write a custom validation function. However, I've tried both methods, and am still having the same problem. In both cases, the form comes back with fresh data in it. I have confirmed that the custom validation rule is firing. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Repopulating a form after an error
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 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Repopulating a form after an error
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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---