Re: More 1.2 validation

2007-02-08 Thread MrTufty

Indeed Mariano, I'll do that. I'm certainly not looking to steal
Evan's limelight on this one, compared to what he's done, my stuff is
just minor tweaks :)

On Feb 8, 7:42 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> You may want to combine efforts with Evan who is the original developer:
>
> http://blog.evansagge.com
>
> Otherwise we would have two versions of the same library floating around.
> Not particularly DRY if you ask me ;)
>
> -MI
>
> ---
>
> Remember, smart coders answer ten questions for every question they ask.
> So be smart, be cool, and share your knowledge.
>
> BAKE ON!
>
> blog:http://www.MarianoIglesias.com.ar
>
> -Mensaje original-
> De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> de MrTufty
> Enviado el: Jueves, 08 de Febrero de 2007 12:14 p.m.
> Para: Cake PHP
> Asunto: Re: More 1.2 validation
>
> When I get this sorted out and working in a way that makes sense to
> everyone, I'll post it up somewhere as a complete package to drop in.
> And probably stick it up on the Bakery or Trac, if enough people are
> interested in seeing it there.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread Mariano Iglesias

You may want to combine efforts with Evan who is the original developer:

http://blog.evansagge.com

Otherwise we would have two versions of the same library floating around.
Not particularly DRY if you ask me ;)

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar

-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de MrTufty
Enviado el: Jueves, 08 de Febrero de 2007 12:14 p.m.
Para: Cake PHP
Asunto: Re: More 1.2 validation

When I get this sorted out and working in a way that makes sense to
everyone, I'll post it up somewhere as a complete package to drop in.
And probably stick it up on the Bakery or Trac, if enough people are
interested in seeing it there.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

Bug fix for the validateRequired / validateNotEmpty:

function _evaluate($validation, $messageOnFail, $fieldName = null,
$params = array())
{
if ($validation)
{
return true;
}

if(!preg_match("/does not match pattern/",$messageOnFail) && !
preg_match("/should not be empty/", $messageOnFail))
{
if (!isset($params['message']))
{
$params['message'] = Inflector::humanize($fieldName) . "
" . $messageOnFail . ".";
}

if ($params['message'])
{
$this->model->validationErrors[$this->name][$fieldName][]
= $params['message'];
}
}
$this->errorCount++;
return false;
}

That part at least should be fine, still working on the other chunks
of code.

On Feb 8, 3:14 pm, "MrTufty" <[EMAIL PROTECTED]> wrote:
> Damn, I didn't pick that one up either. Will bug fix that later on.
>
> A possible modification would be to add an extra parameter to each
> function specifying whether or not to output the message - but that
> might make things more complicated than they need to be.
>
> When I get this sorted out and working in a way that makes sense to
> everyone, I'll post it up somewhere as a complete package to drop in.
> And probably stick it up on the Bakery or Trac, if enough people are
> interested in seeing it there.
>
> On Feb 8, 2:18 pm, "mcgordon" <[EMAIL PROTECTED]> wrote:
>
> > Good catch. I hadn't considered the default messages getting added to
> > the array.
>
> > Be careful of validateRequired calling validateNotEmpty. You'll want
> > to add a check for that error message as well or you'll see both
> > "field should not be empty" and "field is required" for the same field.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

Damn, I didn't pick that one up either. Will bug fix that later on.

A possible modification would be to add an extra parameter to each
function specifying whether or not to output the message - but that
might make things more complicated than they need to be.

When I get this sorted out and working in a way that makes sense to
everyone, I'll post it up somewhere as a complete package to drop in.
And probably stick it up on the Bakery or Trac, if enough people are
interested in seeing it there.

On Feb 8, 2:18 pm, "mcgordon" <[EMAIL PROTECTED]> wrote:
> Good catch. I hadn't considered the default messages getting added to
> the array.
>
> Be careful of validateRequired calling validateNotEmpty. You'll want
> to add a check for that error message as well or you'll see both
> "field should not be empty" and "field is required" for the same field.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread mcgordon

Good catch. I hadn't considered the default messages getting added to
the array.

Be careful of validateRequired calling validateNotEmpty. You'll want
to add a check for that error message as well or you'll see both
"field should not be empty" and "field is required" for the same field.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

True, I'd not considered that part of the hackiness either. For now,
I've gone ahead and done it.

The solution isn't perfect - other tweaks will need to be made to the
other functions in the Error helper, for instance - but it does appear
to work.

Here's my code:

//error.php - modelErrors() function
function modelErrors()
{
$html =& new HtmlHelper;
$models = func_get_args();
$list = '';
foreach ($models as $model)
{
if ( isset($this->validationErrors[$model]) )
{
foreach ( $this->validationErrors[$model] as
$field => $errors )
{
foreach ( $errors as $error )
{
foreach( $error as $item )
{
$list .= '' . $item . '';
}
}
}
}
}

$output = '';
if ( !empty($list) )
{
$output = '

' . __('The following errors need
to be corrected:', true)
.
'

' . $list . '


';
}

return $output;
}

// validation.php - _evaluate() function
function _evaluate($validation, $messageOnFail, $fieldName = null,
$params = array())
{
if ($validation)
{
return true;
}

if(!preg_match("/does not match pattern/",$messageOnFail))
{
if (!isset($params['message']))
{
$params['message'] = Inflector::humanize($fieldName) . "
" . $messageOnFail . ".";
}

if ($params['message'])
{
$this->model->validationErrors[$this->name][$fieldName][]
= $params['message'];
}
}
$this->errorCount++;
return false;
}

Give that a try, and see if it works for you.

One thing you'll notice, and it may not be something that you want:
I've put an extra conditional in there so that any error messages
return from the validatePattern function don't get added to the array.
Reason I did this was because I'm pattern matching the email address,
but the only error I want to see is "this is not a valid email" - I
don't want to see the other one about it not matching the pattern.
Obviously if you're using patterns directly, this is not the way to
go.

On Feb 8, 1:27 pm, "mcgordon" <[EMAIL PROTECTED]> wrote:
> I totally agree that my solution is a hack. The deeper array would
> definitely be the way to go for multiple error mesages.  The only
> reason I didnt suggest it is that the validationErrors array is part
> of the core model class and I dont want to play around with its
> structure in case it breaks other things in the long run. If it works
> for you, post your code. Id love to see it.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread mcgordon

I totally agree that my solution is a hack. The deeper array would
definitely be the way to go for multiple error mesages.  The only
reason I didnt suggest it is that the validationErrors array is part
of the core model class and I dont want to play around with its
structure in case it breaks other things in the long run. If it works
for you, post your code. Id love to see it.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

I'll take that as a challenge then :)

The workaround would be quite effective, but not ideal as you say...

One thing I considered, although it's probably not optimal, is to
store the messages in another slightly deeper array.

So when assigning the error messages, I'd use:

$this->model->validationErrors[$this->name][][$fieldName] =
$params['message'];

Which if I'm thinking correctly about this would produce something
like this:

array(
'User' => array(
0 => array(
'username' => 'You must choose a username'),
1 => array(
'username' => 'Your username is too short. It must be between 4 and 14
characters'),
2 => array(
'email' => 'Your email address is not valid')
)
);

etc...

I don't know how effective that would be, and I've not yet developed
any code for it so it could be completely wrong. But I might give it a
try next week (got a weekend away from coding, lucky me).

Thanks Marcel :)


On Feb 8, 12:46 pm, "mcgordon" <[EMAIL PROTECTED]> wrote:
> For multiple validation rules on the same field, each failure will
> overwrite the existing message with its own message, so in your case,
> for usernames, if your validation rules looked like this:
>
> 'username' => array(
>  'required' => array('message' =>'You must choose a username')
> ,'pattern' => array('pattern' => "/^[a-z0-9]+$/", 'letters and
> numbers only')
> ,'length' => array('min' => 5, 'max'=>12, 'message'=>'The username
> must be between 5 and 12 characters')
> ,unique' => array('message'=>'that username is already in use')
> )
>
> and your user chose Petr as a username, he'd first see the length rule
> and when he'd corrected that, he'd get a second error telling him
> about the uppercase P. Not ideal, but that's the way it works. Think
> about the order in which you want to apply your tests to minimize that
> kind of thing.
>
> If you want to show all messages at once, you'd have to hack the
> _evaluate routine by concatenating the $params['message']
>
> $this->model->validationErrors[$this->name][$fieldName] .= ' ' .
> $params['message'];
>
> This will generate a warning if 
> $this->model->validationErrors[$this->name][$fieldName] is not defined so be 
> sure to test using isset() and
>
> then assign(=) or concatenate(.=) accordingly.
>
> What you can't do is have a separate list item for each error because
> of the way that the validationErrors array is designed in the first
> place.
>
> A workaround could be to add a unique string separator, something that
> you know for sure will never appear in an error message, before you
> concatenate and then, in the modelErrors routine, explode() the
> combined error message based on your special string and then print out
> the single messages as individual list items.  I'll leave that as an
> exercise for the reader ;)


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread mcgordon

For multiple validation rules on the same field, each failure will
overwrite the existing message with its own message, so in your case,
for usernames, if your validation rules looked like this:

'username' => array(
 'required' => array('message' =>'You must choose a username')
,'pattern' => array('pattern' => "/^[a-z0-9]+$/", 'letters and
numbers only')
,'length' => array('min' => 5, 'max'=>12, 'message'=>'The username
must be between 5 and 12 characters')
,unique' => array('message'=>'that username is already in use')
)

and your user chose Petr as a username, he'd first see the length rule
and when he'd corrected that, he'd get a second error telling him
about the uppercase P. Not ideal, but that's the way it works. Think
about the order in which you want to apply your tests to minimize that
kind of thing.

If you want to show all messages at once, you'd have to hack the
_evaluate routine by concatenating the $params['message']

$this->model->validationErrors[$this->name][$fieldName] .= ' ' .
$params['message'];

This will generate a warning if $this->model->validationErrors[$this-
>name][$fieldName] is not defined so be sure to test using isset() and
then assign(=) or concatenate(.=) accordingly.

What you can't do is have a separate list item for each error because
of the way that the validationErrors array is designed in the first
place.

A workaround could be to add a unique string separator, something that
you know for sure will never appear in an error message, before you
concatenate and then, in the modelErrors routine, explode() the
combined error message based on your special string and then print out
the single messages as individual list items.  I'll leave that as an
exercise for the reader ;)


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

Excellent!

Thank you Marcel, you've been a star; my code now works as expected
and I can get on with developing the other parts of my system now. I
second the call that this level of functionality should be added to
the core - it's so useful. Potentially in time the current validation
class might be able to do all this, but to be honest I find the syntax
for that fiddly at best.

One last question and then I'll leave you alone - is it expected that
I should only get one error message per field? Ideally I'd like to
have all the possible errors displayed, not just one of them. I
suspect that's something to do with the way the errors array is built
up?

On Feb 8, 11:41 am, "mcgordon" <[EMAIL PROTECTED]> wrote:
> contentTag is deprecated in 1.1 and they've taken it out of 1.2
> altogether.  Just stick straight HTML in your helper.  This is what my
> modelErrors function looks like:
>
> function modelErrors()
> {
> $html =& new HtmlHelper;
> $models = func_get_args();
> $list = '';
> foreach ($models as $model)
> {
> if ( isset($this->validationErrors[$model]) )
> {
> foreach ( $this->validationErrors[$model] as $field 
> => $errors )
> {
> foreach ( $errors as $error )
> {
> $list .= '' . $error . '' . 
> NL;
> }
> }
> }
> }
>
> $output = '';
> if ( !empty($list) )
> {
> $output = '
> 
> ' . __('The following errors need to be 
> corrected:', true) .
> '
> 
> ' . $list . '
> 
> 
> ';
> }
>
> return $output;
>
> }


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread mcgordon

contentTag is deprecated in 1.1 and they've taken it out of 1.2
altogether.  Just stick straight HTML in your helper.  This is what my
modelErrors function looks like:

function modelErrors()
{
$html =& new HtmlHelper;
$models = func_get_args();
$list = '';
foreach ($models as $model)
{
if ( isset($this->validationErrors[$model]) )
{
foreach ( $this->validationErrors[$model] as $field => 
$errors )
{
foreach ( $errors as $error )
{
$list .= '' . $error . '' . NL;
}
}
}
}

$output = '';
if ( !empty($list) )
{
$output = '

' . __('The following errors need to be 
corrected:', true) .
'

' . $list . '


';
}

return $output;
}


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

Thanks again :)

I'm still having a few problems, the ErrorHelper provided uses a
method of the HTML Helper which doesn't appear to exist - it outputs
by using $html->contentTag(), which doesn't work. I've looked through
the HTML Helper itself and it seems to be using output in the format
of $this->output($this->tags['fieldset'], $data1, $data2); etc...

Unfortunately the  tag which I need for displaying the error
messages is not in the var $tags array. I know I could modify the
ErrorHelper's output to put out straight HTML, which would work, but
is there a real Cake-y way to do this?

On Feb 8, 10:23 am, "mcgordon" <[EMAIL PROTECTED]> wrote:
> The problem is in the class name "Validation" which is the same as the
> core class name.  If you rename it the conflict goes away.
>
> You've got to change two things in the code, first the name of the
> class in the class definition (file validation.php).  The author's
> name is Evan so I renamed his class eValidation:
>
> "class eValidation" on line 26 of Validation.php
>
> Don't forget to rename the constructor on line 45:
>
> function eValidation(&$data, &$model)
>
> Next you have to change the name of the class where it gets
> instantiated.  In app_model.php look for the function invalid_fields
> that you added and change this line to include your new class name:
>
> $validation =& new eValidation($data, $this);
>
> it should work now.
>
> While we're at it, the other bugs I was talking about occur when the
> code passes the field to be validated through the _evaluate function
> twice. Look at this function below:
>
> function validatePattern($fieldName, $params)
> {
> $pattern = $params['pattern'];
> return $this->_evaluate(preg_match($pattern, $this->data[$this->name]
> [$fieldName]),
> "does not match pattern {$pattern}", $fieldName, 
> $params);
>
> }
>
> it validates the field against a user-supplied pattern and sends the
> result to the _evaluate function where the model->validationErrors are
> set.  Good so far.
>
> The following function is a convenience function so that you don't
> have to remember the regex for a valid word:
>
> function validateWord($fieldName, $params)
> {
> $params['pattern'] = '/^\\w*$/';
> return $this->_evaluate(!$this->validatePattern($fieldName, $params),
> "is not a valid word", $fieldName, $params);
>
> }
>
> it first runs the field through validatePattern() [which in turn runs
> it through _evaluate()] and then sends the inverse of the result
> through _evaluate again, resulting in the opposite answer to what
> you'd expect.
>
> If we follow the logic, for a given field containing valid data,
> validateWord() calls validatePattern() which calles _evaluate() with
> "true" as the first parameter (the regex matched for valid data).
> _evaluate() in turn returns true and so validatePattern() also returns
> true.
>
> now we run _evaluate again with (!true) as the first parameter.  this
> time _evaluate() fails and the error message is set, even though the
> field is valid. the problem is with the ! symbol that negates the
> first return value. By simply removing the ! the function returns true
> as expected and the field validates.
>
> This is true throughout the code wherever a convenience function is
> used to alias a more general function. The second time through
> _evaluate()  - which is done to allow for custom error messages - the
> validation fails.
>
> The following functions need to be changed:
> validateRequired
> validateWord
> validateInteger
> validateNumber
> validateEmail
> validateYear
>
> > I was almost tempted to
> > simply delete the standard Validation class and overwrite it with this
> > one, but that would cause other problems down the road, I'm sure.
>
> Bad Idea Jeans™  ;)
>
> Don't touch the core code unless you're using some kind of versioning
> system that will let you merge in the latest updates or you'll never
> remember all the places where you made changes. That goes double for
> now as they're adding new stuff to the trunk every day.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread mcgordon

The problem is in the class name "Validation" which is the same as the
core class name.  If you rename it the conflict goes away.

You've got to change two things in the code, first the name of the
class in the class definition (file validation.php).  The author's
name is Evan so I renamed his class eValidation:

"class eValidation" on line 26 of Validation.php

Don't forget to rename the constructor on line 45:

function eValidation(&$data, &$model)


Next you have to change the name of the class where it gets
instantiated.  In app_model.php look for the function invalid_fields
that you added and change this line to include your new class name:

$validation =& new eValidation($data, $this);

it should work now.


While we're at it, the other bugs I was talking about occur when the
code passes the field to be validated through the _evaluate function
twice. Look at this function below:

function validatePattern($fieldName, $params)
{
$pattern = $params['pattern'];
return $this->_evaluate(preg_match($pattern, $this->data[$this->name]
[$fieldName]),
"does not match pattern {$pattern}", $fieldName, 
$params);
}

it validates the field against a user-supplied pattern and sends the
result to the _evaluate function where the model->validationErrors are
set.  Good so far.

The following function is a convenience function so that you don't
have to remember the regex for a valid word:

function validateWord($fieldName, $params)
{
$params['pattern'] = '/^\\w*$/';
return $this->_evaluate(!$this->validatePattern($fieldName, $params),
"is not a valid word", $fieldName, $params);
}

it first runs the field through validatePattern() [which in turn runs
it through _evaluate()] and then sends the inverse of the result
through _evaluate again, resulting in the opposite answer to what
you'd expect.

If we follow the logic, for a given field containing valid data,
validateWord() calls validatePattern() which calles _evaluate() with
"true" as the first parameter (the regex matched for valid data).
_evaluate() in turn returns true and so validatePattern() also returns
true.

now we run _evaluate again with (!true) as the first parameter.  this
time _evaluate() fails and the error message is set, even though the
field is valid. the problem is with the ! symbol that negates the
first return value. By simply removing the ! the function returns true
as expected and the field validates.

This is true throughout the code wherever a convenience function is
used to alias a more general function. The second time through
_evaluate()  - which is done to allow for custom error messages - the
validation fails.

The following functions need to be changed:
validateRequired
validateWord
validateInteger
validateNumber
validateEmail
validateYear


> I was almost tempted to
> simply delete the standard Validation class and overwrite it with this
> one, but that would cause other problems down the road, I'm sure.

Bad Idea Jeans™  ;)

Don't touch the core code unless you're using some kind of versioning
system that will let you merge in the latest updates or you'll never
remember all the places where you made changes. That goes double for
now as they're adding new stuff to the trunk every day.


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-08 Thread MrTufty

Ok, now I'm a bit further along... I've added the code to my Cake
project, but I'm confused as to which parts I need to change to stop
it conflicting with the 1.2 validation class. I was almost tempted to
simply delete the standard Validation class and overwrite it with this
one, but that would cause other problems down the road, I'm sure.

Can you advise me on which bits I need to rename/change/delete to make
this work correctly?

Thanks! :)

On Feb 7, 11:23 pm, "MrTufty" <[EMAIL PROTECTED]> wrote:
> Hi Marcel -
>
> THAT is exactly the sort of helpful answer I was hoping for. Fantastic
> bit of code, I think I'll be making use of it until such time as the
> Cake core includes something comparable.
>
> I've bookmarked the page in question, and courtesy of the Foxmarks
> extension for Firefox, I'll check it out first thing tomorrow when I
> get to work :)
>
> Thanks again - and thanks also to the author of said code :)
>
> On Feb 7, 9:06 pm, "marcelgordon" <[EMAIL PROTECTED]> wrote:
>
> > > I'm trying to use the new methods of validation from the 1.2 code
>
> > Have a look at the code on this page which works fine with 1.2
>
> >http://blog.evansagge.com/2006/12/28/evans-cakephp-validation-techniq...
>
> > it takes care of 1), 2) and 3) from above (and probably 4 but i didn't
> > check)
>
> > I've been using it for a while with good results
>
> > be aware of a couple of things if you use this code.
>
> > 1) the class name conflicts with the core Validation class.  You'll
> > have to rename it if you want to use this code with 1.2
>
> > 2) there are some bugs in the code, but they're easily fixed.  I
> > pointed one out in my comment and then went on to discover that the
> > same error occurs througout the code.
>
> > 3) there is an unresolved issue described in comment #5 that the
> > author hasn't posted a fix for and I haven't had time to track down on
> > my own.
>
> > Despite these few problems, it's a very useful piece of code as it
> > resolves the biggest shortcoming of the core Validation class so far,
> > which is multiple checks with distinct error messages on the same
> > field. Maybe one of the developers could look at incorporating this
> > into the core...


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-07 Thread MrTufty

Hi Marcel -

THAT is exactly the sort of helpful answer I was hoping for. Fantastic
bit of code, I think I'll be making use of it until such time as the
Cake core includes something comparable.

I've bookmarked the page in question, and courtesy of the Foxmarks
extension for Firefox, I'll check it out first thing tomorrow when I
get to work :)

Thanks again - and thanks also to the author of said code :)

On Feb 7, 9:06 pm, "marcelgordon" <[EMAIL PROTECTED]> wrote:
> > I'm trying to use the new methods of validation from the 1.2 code
>
> Have a look at the code on this page which works fine with 1.2
>
> http://blog.evansagge.com/2006/12/28/evans-cakephp-validation-techniq...
>
> it takes care of 1), 2) and 3) from above (and probably 4 but i didn't
> check)
>
> I've been using it for a while with good results
>
> be aware of a couple of things if you use this code.
>
> 1) the class name conflicts with the core Validation class.  You'll
> have to rename it if you want to use this code with 1.2
>
> 2) there are some bugs in the code, but they're easily fixed.  I
> pointed one out in my comment and then went on to discover that the
> same error occurs througout the code.
>
> 3) there is an unresolved issue described in comment #5 that the
> author hasn't posted a fix for and I haven't had time to track down on
> my own.
>
> Despite these few problems, it's a very useful piece of code as it
> resolves the biggest shortcoming of the core Validation class so far,
> which is multiple checks with distinct error messages on the same
> field. Maybe one of the developers could look at incorporating this
> into the core...


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-07 Thread marcelgordon

> I'm trying to use the new methods of validation from the 1.2 code

Have a look at the code on this page which works fine with 1.2

http://blog.evansagge.com/2006/12/28/evans-cakephp-validation-technique-20/

it takes care of 1), 2) and 3) from above (and probably 4 but i didn't
check)

I've been using it for a while with good results


be aware of a couple of things if you use this code.

1) the class name conflicts with the core Validation class.  You'll
have to rename it if you want to use this code with 1.2

2) there are some bugs in the code, but they're easily fixed.  I
pointed one out in my comment and then went on to discover that the
same error occurs througout the code.

3) there is an unresolved issue described in comment #5 that the
author hasn't posted a fix for and I haven't had time to track down on
my own.

Despite these few problems, it's a very useful piece of code as it
resolves the biggest shortcoming of the core Validation class so far,
which is multiple checks with distinct error messages on the same
field. Maybe one of the developers could look at incorporating this
into the core...


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-07 Thread MrTufty

Thanks Tarique, will take a look later on.

I was hoping to avoid having to use anything not in the core code,
purely for stability later on. But if it's required... then that's
what I'll do :)

On Feb 7, 3:55 pm, "Dr. Tarique Sani" <[EMAIL PROTECTED]> wrote:
> On 2/7/07, MrTufty <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to use the new methods of validation from the 1.2 code
>
> Oh forgot to add - my code is V1.1
>
> T
>
> --
> =
> PHP for E-Biz:http://sanisoft.com
> Cheesecake-Photoblog:http://cheesecake-photoblog.org
> =


--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-07 Thread Dr. Tarique Sani

On 2/7/07, MrTufty <[EMAIL PROTECTED]> wrote:
> I'm trying to use the new methods of validation from the 1.2 code

Oh forgot to add - my code is V1.1

T

-- 
=
PHP for E-Biz: http://sanisoft.com
Cheesecake-Photoblog: http://cheesecake-photoblog.org
=

--~--~-~--~~~---~--~~
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: More 1.2 validation

2007-02-07 Thread Dr. Tarique Sani

On 2/7/07, MrTufty <[EMAIL PROTECTED]> wrote:
> 1) Multiple validation rules for a single field
Tick

> 2) An equivalent to validates_uniqueness_of from Rails - effectively
> connecting to the database and seeing if the submitted value already
> exists in the table
Tick

> 3) A replacement for the old VALID_NOT_EMPTY - we now have a
> validation rule for seeing if a field is blank, but I can't figure out
> how you'd use that to make sure it's NOT blank.
Tick

> 4) Clarification on the comparison rule - should we be using this for
> strings (such as in my password/password_confirmation) or will it only
> work with numbers?
Tick

All the above plus automagic generation of Javascript (jquery) for
validation and also AJAX calls if needed for client side validation.
(server side validation takes place none the less)

Check out the stuff which I have committed to Cheesecake SVN over past
few days - been planning to write a tutorial but that does not seem to
be happening - if you can figure that out and write one it would be
great.

Hint: see the comment system

But the key is if its not there - build it

Cheers
Tarique

P.S. the above work is bu no means original but built upon ideas
borrowed from several tutorials and blogs

-- 
=
PHP for E-Biz: http://sanisoft.com
Cheesecake-Photoblog: http://cheesecake-photoblog.org
=

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



More 1.2 validation

2007-02-07 Thread MrTufty

Hi guys... it seems like every time I come on here, I'm posting about
validation. Probably because, at least to me, it's one of the most
confusing parts of the framework.

I'm trying to use the new methods of validation from the 1.2 code
(current SVN version as of today), and I'm hitting brick walls
probably because I'm trying to do something that makes no sense.

The initial part of my application is basic user authentication. I
have no issues with login and logout, I understand how to work with
the Session component, and I've been playing with the Cookie component
also to handle persistent logins.

The confusing part is signups, and the problem comes down to the
specific rules I want to apply.

I need my usernames to be alphanumeric only (at least for the moment),
but I also want them to be within a certain size range, and also to be
unique (for obvious reasons). Previously I've used beforeValidate for
this (although my attempt earlier on didn't get very far and gave me
nearly 100 lines of code for the various conditions).

There are similar conditions applied to the other 3 fields in my
signup form - which are password, password_confirmation, and email. I
can accept happily the difficulties of producing a validation system
that does everything that everyone needs it to do - but some things
would make life a lot easier.

1) Multiple validation rules for a single field
2) An equivalent to validates_uniqueness_of from Rails - effectively
connecting to the database and seeing if the submitted value already
exists in the table
3) A replacement for the old VALID_NOT_EMPTY - we now have a
validation rule for seeing if a field is blank, but I can't figure out
how you'd use that to make sure it's NOT blank.
4) Clarification on the comparison rule - should we be using this for
strings (such as in my password/password_confirmation) or will it only
work with numbers?

The last feature I'd like to see is definable error messages for these
validation rules, but I'm pretty sure that's something you guys are
already working on.

To clarify, I don't expect you guys to just jump and develop this
functionality simply because I've asked for it - in fact some of these
things I'm going to have a crack at developing myself before
submitting as a patch - but I would like an idea of if/when these
things are going to appear, if ever?

Thanks :)


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---