Re: Getting an array of errors during validation
On Dec 11, 9:14 am, gearvOsh [EMAIL PROTECTED] wrote: So I understand the Model validation using $validate. I applied snooks multiple validations usinghttp://snook.ca/archives/cakephp/multiple_validation_sets_cakephp/, all that works perfectly. I do however dislike it when a field errors, the error message is shown after the input. Id rather a list of all errors be shown above the form, so what im asking is... Simply use FormHelper::error() to print error messages wherever and whenever you want: echo($form-error('Model.field1'); echo($form-error('Model.field2'); (http://api.cakephp.org/class_form_helper.html) Don't forget to remove the error message from your input fields: echo($form-input('Model.field1', array('error' = false))); echo($form-input('Model.field2', array('error' = false))); Marcus --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Getting an array of errors during validation
Ok ill take a look at that. Hopefully I can do something to get an array so I can do a simple loop. On Dec 11, 12:27 am, Marcus [EMAIL PROTECTED] wrote: On Dec 11, 9:14 am, gearvOsh [EMAIL PROTECTED] wrote: So I understand the Model validation using $validate. I applied snooks multiple validations usinghttp://snook.ca/archives/cakephp/multiple_validation_sets_cakephp/, all that works perfectly. I do however dislike it when a field errors, the error message is shown after the input. Id rather a list of all errors be shown above the form, so what im asking is... Simply use FormHelper::error() to print error messages wherever and whenever you want: echo($form-error('Model.field1'); echo($form-error('Model.field2'); (http://api.cakephp.org/class_form_helper.html) Don't forget to remove the error message from your input fields: echo($form-input('Model.field1', array('error' = false))); echo($form-input('Model.field2', array('error' = false))); Marcus --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Getting an array of errors during validation
I figured it out. $validationErrors contains the array, I simply set it in the view. // login.ctp ?php echo $this-element('errors', array('errors' = $form- validationErrors['User'])); ? // elements/errors.ctp ?php if (!empty($errors)) { ? div class=failed h5?php printf(__d('errors', 'totalErrors', true), count ($errors)); ?/h5 ul ?php foreach ($errors as $field = $error) { ? li?php echo $error; ?/li ?php } ? /ul /div ?php } ? But since im doing i18n/l10n and am not able to do __() in the model or the view, I had to do it in the controller. // Validation $this-User-validate = array( 'username' = array( 'notEmpty' = array( 'rule' = 'notEmpty', 'message' = __d('errors', 'usernameEmpty2', true) )), 'password' = array( 'notEmpty' = array( 'rule' = 'notEmpty', 'message' = __d('errors', 'passwordEmpty2', true) )), ); --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Getting an array of errors during validation
Oh and also stupid me, its basically in the manual: http://book.cakephp.org/view/410/Validating-Data-from-the-Controller My way doesnt require you to set the data to the view though, but either way works. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---