CTED] 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
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
interest
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_m
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 worki
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.
--~--~--
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() fun
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 othe
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->validat
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'
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
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
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
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 cla
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 ca
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
> 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
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
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-pho
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
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 wal
20 matches
Mail list logo