Re: usage of the new validation class in 1.2.x.x.

2007-02-07 Thread snowdog

Ok, I found the solution for my question - using minLength rule...

On 7 Lut, 18:33, "snowdog" <[EMAIL PROTECTED]> wrote:
> That is great help! Thanks.
> I have one more problem - how to check if the field is NOT BLANK? I
> tried for same time an got nothing.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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: usage of the new validation class in 1.2.x.x.

2007-02-07 Thread snowdog

That is great help! Thanks.
I have one more problem - how to check if the field is NOT BLANK? I
tried for same time an got nothing.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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: usage of the new validation class in 1.2.x.x.

2007-01-01 Thread gabordemeter


Thanks Nate!

The previous days I looked a bit into this and came to the conclusion
that I would like to be able to display several errors for each form
field (i.e. if the username is both using non-alphanumeric characters
as well as having more than the allowed limit of chars I would like to
see both error images displayed below my message).

The solution I found was as follows:

1) In app_model.php I now have:

class AppModel extends Model{

var $validate;

function __construct()
{
$this->validate = new Validation();
parent::__construct();
}
}

2) In my model I have something like:

function beforeValidate()
{
if 
(!$this->validate->alphaNumeric($this->data['User']['username']))
$this->invalidate('username_alphanumeric');
if
(!$this->validate->someOtherFunction($this->data['User']['username']))
$this->invalidate('username_someOtherFunction');
if ($this->validate->blank($this->data['User']['password']))
$this->invalidate('password_blank');
}

3) In  my view I have:

input('User/username', array('class'=>'signup')); ?>
tagErrorMsg('User/username_alphanumeric', 'Username
must be alphanumeric.') ?>
tagErrorMsg('User/username_blank', 'Username cannot
be someOtherFunction.') ?>

password('User/password', array('class'=>'signup'));
?>
tagErrorMsg('User/password_blank', 'Please choose a
password.') ?>

Btw, I just read the excellent article on your blog explaining the new
automagic in the form helper and will convert the above inputs to it
soon.



Ok, so is the above the right way to do what I'm trying to do? Or is
there a simpler or better way to achieve it?



Also, if I do it like the above, the entire validation happens in
beforeValidate() and I will therefore not have anything in $validate. I
would however want to do the following:

If my beforeValidate logic will invalidate one or more fields (so there
exists at least one validation error), besides displaying the
respective error messages for each field like I did above, I would also
like to have a generic message at the top of my form saying something
like "there were errors in you form...please scroll down to see
them...blah blah".

How should I do this? I tried:

   function beforeValidate()
{
if 
(!$this->validate->alphaNumeric($this->data['User']['username']))
$this->invalidate('username_alphanumeric');
if
(!$this->validate->someOtherFunction($this->data['User']['username']))
$this->invalidate('username_someOtherFunction');
if ($this->validate->blank($this->data['User']['password']))
$this->invalidate('password_blank');

   $abc = "there were errors in you form...please scroll
down to see them...blah blah";
if ($this->validationErrors) $this->set('message', $abc);
}

The above did not work. Not sure if i can $this->set() from inside a
model. If not, how can I do it?


Thanks again for your previous reply!











On Jan 1, 12:35 pm, "nate" <[EMAIL PROTECTED]> wrote:

Right now, the only way to use the new Validation class is to write
your rules like this:

var $validate = array('username' => array('rule' => 'alphaNumeric'));

You can specify other rules as follows:

'rule' => array('between', $min, $max)

'rule' => array('blank')

'rule' => array('cc', $type, $deep)
Where $type can be 'fast' (a basic check that covers all card types) or
'all' (check all cards) or an array of one or more of the following:
'amex', 'bankcard', 'diners', disc', 'electron', 'enroute', 'jcb',
'maestro', 'mc', 'solo', 'switch', 'visa' or 'voyager'.

'rule' => array('comparison', $operator, $compare)
$operator may be one of the following: 'isgreater', 'isless',
'greaterorequal', 'lessorequal', 'equalto', 'notequal', or, their
symbol equivalents: '>', '<', '>=', '<=', '==', '!='.

'rule' => array('custom', $regex)
Where $regex is a custom regular expression.

'rule' => array('date', $format)
Where $format is one of the following: 'dmy', 'mdy', 'ymd', 'dMy',
'Mdy', 'My', 'my'.  $format can also be an array containing mulitple
values.

'rule' => array('decimal', $precision)
Checks that the input is a decimal number with $precision places after
the decimal point.

'rule' => array('email', $deep)
If $deep is true, the email address will be checked for a valid host
name.

'rule' => array('minLength', $min)

'rule' => array('maxLength', $max)

'rule' => array('numeric')

'rule' => array('postal')

'rule' => array('ssn')

'rule' => array('url')

Those are the rules in a nutshell, although more will be added shortly.
 Most of them should be pretty self-explanatory.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send e

Re: usage of the new validation class in 1.2.x.x.

2007-01-01 Thread nate


Right now, the only way to use the new Validation class is to write
your rules like this:

var $validate = array('username' => array('rule' => 'alphaNumeric'));

You can specify other rules as follows:

'rule' => array('between', $min, $max)

'rule' => array('blank')

'rule' => array('cc', $type, $deep)
Where $type can be 'fast' (a basic check that covers all card types) or
'all' (check all cards) or an array of one or more of the following:
'amex', 'bankcard', 'diners', disc', 'electron', 'enroute', 'jcb',
'maestro', 'mc', 'solo', 'switch', 'visa' or 'voyager'.

'rule' => array('comparison', $operator, $compare)
$operator may be one of the following: 'isgreater', 'isless',
'greaterorequal', 'lessorequal', 'equalto', 'notequal', or, their
symbol equivalents: '>', '<', '>=', '<=', '==', '!='.

'rule' => array('custom', $regex)
Where $regex is a custom regular expression.

'rule' => array('date', $format)
Where $format is one of the following: 'dmy', 'mdy', 'ymd', 'dMy',
'Mdy', 'My', 'my'.  $format can also be an array containing mulitple
values.

'rule' => array('decimal', $precision)
Checks that the input is a decimal number with $precision places after
the decimal point.

'rule' => array('email', $deep)
If $deep is true, the email address will be checked for a valid host
name.

'rule' => array('minLength', $min)

'rule' => array('maxLength', $max)

'rule' => array('numeric')

'rule' => array('postal')

'rule' => array('ssn')

'rule' => array('url')

Those are the rules in a nutshell, although more will be added shortly.
Most of them should be pretty self-explanatory.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~--~~~~--~~--~--~---



usage of the new validation class in 1.2.x.x.

2006-12-31 Thread gabordemeter


Hi,

Just installed cake 1.2.0.4206 two days ago. So far have not
encountered any problems with it.

I did however noticed the new validation class with a much wider range
of validation methods than before and would like to start using it.
However, since 1.2.x.x. documentation has not been released yet, I was
wondering if anyone knows how to properly use the new validation
methods.

Basically, if I want to check in my User model if a certain submitted
field (say 'username') is alphanumeric, what is the syntax for doing
this check in the User model?

Should I write something like $validate = array('username' =>
'alphanumeric');? Or is there a new syntax for doing this check in
cake 1.2.x.x.?

Thx and have a Happy New Year!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~--~~~~--~~--~--~---