Monday, November 24, 2008

AW: validation

Hi sundar,

I give you an exapmple of a complicated rule combination of one of my models, which shows the error message in the view when a validation error occured:

class User extends AppModel {

var $name = 'User';
var $useTable = 'users';

var $validate = array(
'name' => array('rule' => array('custom', '/^[a-zA-Z0-9äöüßéèáàóò\'\-\/ \.&\´]*$/i',
'message' => 'Keine unerlaubten Sonderzeichen verwenden.')),
'username' => array(
'Myrule1' => array( 'rule' => 'alphaNumeric',
'message' => 'Keine unerlaubten Sonderzeichen verwenden.',
'last' => true),
'Myrule2' => array( 'rule' => 'isUnique',
'message' => 'Loginname ist schon vergeben.',
'last' => true)),
'password' => array(
'Myrule1' => array( 'rule' => array('custom', '/[a-z]/i'),
'message' => 'Mindestens eine Zahl, einen großen und kleinen Buchstaben verwenden.',
'last' => true),
'Myrule2' => array( 'rule' => array('custom', '/[A-Z]/i'),
'message' => 'Mindestens eine Zahl, einen großen und kleinen Buchstaben verwenden.',
'last' => true),
'Myrule3' => array( 'rule' => array('custom', '/[0-9]/i'),
'message' => 'Mindestens eine Zahl, einen großen und kleinen Buchstaben verwenden.',
'last' => true),
'Myrule4' => array( 'rule' => array('minLength', '8'),
'message' => 'Mindestlänge 8 Zeichen',
'last' => true))//end password Myrules
);

This gives you the respective error message in your view:

<?php echo $form->create('User');?>
<fieldset>
<legend><?php __('Add User');?></legend>
<?php
echo $form->input('name');
echo $form->input('username');
echo $form->input('password');
?>
</fieldset>
<?php echo $form->end('Submit');?>

Hope that helps

Anja


-----Ursprüngliche Nachricht-----
Von: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] Im Auftrag von sun
Gesendet: Dienstag, 25. November 2008 05:48
An: CakePHP
Betreff: Re: validation


Thanks...

I have written the custom validation method in model. i am asking about how to call the error message in controller error message should display only when the form field is empty...
(refer my first post) can u help to solve this issue?

call the error message in controller by using sessions .. i dnt know it is possible to work r not. u have any idea abt this?

by
sundar


--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: