Re: Validation problem

2014-02-11 Thread Slawomir Wawak
It started to work, however I still don't know why. ;-)
Well, beginnings are difficult... 
Thanks for help.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Validation problem

2014-02-10 Thread Slawomir Wawak
Thanks a lot. This
 

> $this->Student->set($this->request->data)
>

helped. Now most of the fields are being validated. Only two left:

'password' => array(
> 'rule'=> array('minLength', '6'),
> 'required'=>true,
> 'message' => 'Co najmniej 6 znaków'
> ), 
> 'moodle_password' => array(
> 'rule'=> array('equalTo', 'some_text'),
> 'required'=>true,
> 'message' => 'Błędne hasło Moodle'
> ),
>

Both don't validate. I don't know why. :-(

Regards,
Slawek.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Validation problem

2014-02-10 Thread AD7six


On Monday, 10 February 2014 15:53:45 UTC+1, Slawomir Wawak wrote:
>
> Hi!
> I try to create some validation to my form. I followed some forums and 
> blogs looking for solution, but nothing helps.
>
> My controller looks like this:
>
> public function add() {
>> if ($this->request->is('post')) {
>> $this->Student->create();
>> *if ($this->Student->validates()) {*
>> .
>>
>
The above is attempting to validate an empty Student object - Student 
doesn't have any form data in it. You are missing:

$this->Student->set($this->request->data)

or similar.
 

> When I enable "required => true" form fails each time, even when correct.
>

Because the form data isn't in/on the model - you're validating nothing.
 

> When I show debug($this->Student->data) all data is there.
>

Where are you doing that? 

AD

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Validation problem

2010-07-14 Thread Felix Fennell
Thanks grigri, cricket, I've got it working now - I worked out the "+"
thing from a regex tutorial.

On 14 July 2010 02:09, cricket  wrote:
> On Tue, Jul 13, 2010 at 2:57 PM, Felix Fennell  
> wrote:
>> Removing the /i doesn't do anything unfortunately - I read the
>> handbook page too and thought it should work.
>>
>> They use this to check for any string using alphanumeric characters +
>> dashes + underscores;
>>
>> [0-9a-zA-Z_-]
>>
>> So I would have though that using [a-zA-Z] would work for just upper
>> and lowercase letters.
>
> [-_A-Za-z]+
>
> Note the "+". You want to specify that the string can be one or more
> characters. Without it, and with the ^ and $ wrapping the brackets,
> you're specifying that it must be just a single char.
>
>> Just so I'm not doing anything stupid, everytime I update the
>> validation in the model and upload it, I then delete what ever files
>> are in the /app/tmp/cache/models directory - is there anything else I
>> need to do.
>
> That should do it, Although, if debug is > 0 that shouldn't be an issue, 
> AFAIK.
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-14 Thread cricket
On Tue, Jul 13, 2010 at 2:57 PM, Felix Fennell  wrote:
> Removing the /i doesn't do anything unfortunately - I read the
> handbook page too and thought it should work.
>
> They use this to check for any string using alphanumeric characters +
> dashes + underscores;
>
> [0-9a-zA-Z_-]
>
> So I would have though that using [a-zA-Z] would work for just upper
> and lowercase letters.

[-_A-Za-z]+

Note the "+". You want to specify that the string can be one or more
characters. Without it, and with the ^ and $ wrapping the brackets,
you're specifying that it must be just a single char.

> Just so I'm not doing anything stupid, everytime I update the
> validation in the model and upload it, I then delete what ever files
> are in the /app/tmp/cache/models directory - is there anything else I
> need to do.

That should do it, Although, if debug is > 0 that shouldn't be an issue, AFAIK.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-14 Thread Felix Fennell
Ok, I've got everything working now!

The rules I have ended up with are;

First name: 'rule' => '/^[a-zA-Z]+$/',

Second name: 'rule' => '/^[a-zA-Z]+$/',

Company name: 'rule' => '/^[a-zA-Z\s]+$/',

(Company name should also allow spaces)

I realise that I could use "/i" instead of the [a-zA-Z] bit but as its
working I don't really want to mess it up.

So thanks again to both McBuck DGAF and Dr. Loboto for your help in fixing this.

Felix

On 14 July 2010 14:44, McBuck DGAF  wrote:
> I would defer to Dr. Loboto on this, since he obviously knows more
> about regex than I do.  Maybe he can suggest the correct rule . . . ?
>
> My only response to your last post, Felix, is that you cannot remove "/
> i" since the "/" is required to delimit the regex.  In other words,
> just remove"i".
>
> Good luck.
>
> On Jul 14, 3:32 am, "Dr. Loboto"  wrote:
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-14 Thread grigri
A regexp that only allows letters, numbers and spaces?

'/^[a-z0-9\\x20]*$/i'

A regexp that only allows "words" of letters and numbers, each
separated by a single space:

'/^(?:[a-z0-9]+\\x20)*[a-z0-9]$/'

hth
grigri

On Jul 14, 2:44 pm, McBuck DGAF  wrote:
> I would defer to Dr. Loboto on this, since he obviously knows more
> about regex than I do.  Maybe he can suggest the correct rule . . . ?
>
> My only response to your last post, Felix, is that you cannot remove "/
> i" since the "/" is required to delimit the regex.  In other words,
> just remove"i".
>
> Good luck.
>
> On Jul 14, 3:32 am, "Dr. Loboto"  wrote:

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-14 Thread McBuck DGAF
I would defer to Dr. Loboto on this, since he obviously knows more
about regex than I do.  Maybe he can suggest the correct rule . . . ?

My only response to your last post, Felix, is that you cannot remove "/
i" since the "/" is required to delimit the regex.  In other words,
just remove"i".

Good luck.

On Jul 14, 3:32 am, "Dr. Loboto"  wrote:

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-14 Thread Dr. Loboto
Rule '/^[a-z]$/i' accepts strictly one latin symbol in any case.
Example: 'a' or 'B'.
Rule '/^[a-z][A-Z]$/i' is same as '/^[a-z][A-Z]$/' and accept strictly
two latin symbols, first in lowercase and second in upper. Example:
'aB'.
Rule '/^[a-zA-Z]$/i' is same as '/^[a-zA-Z]$/' and same as '/^[a-z]$/
i'. So look upper: it accepts strictly one latin symbol in any case.
Example: 'a' or 'B'.

So these rules should always fail for username/name/company/etc unless
you want them to be 1 symbol.

On Jul 14, 1:57 am, Felix Fennell  wrote:
> Removing the /i doesn't do anything unfortunately - I read the
> handbook page too and thought it should work.
>
> They use this to check for any string using alphanumeric characters +
> dashes + underscores;
>
> [0-9a-zA-Z_-]
>
> So I would have though that using [a-zA-Z] would work for just upper
> and lowercase letters.
>
> Just so I'm not doing anything stupid, everytime I update the
> validation in the model and upload it, I then delete what ever files
> are in the /app/tmp/cache/models directory - is there anything else I
> need to do.
>
> Felix.
>
> On 13 July 2010 19:37, McBuck DGAF  wrote:
>
>
>
> > I thought the "i" at the end of the rule I suggested would make it
> > case insensitive, as described in the manual. (Like I said, regex is
> > not my thing, I am still learning there . . .)  Anyway, try removing
> > the "i" from the end of the last rule you suggested (ie, '/^[a-zA-Z]
> > $/') and see if that works.
>
> > On Jul 13, 1:36 pm, Felix  wrote:
> >> OK, that validation rule works, kinda.
>
> >> If I remove the validation for the company name (temporarily) the rest
> >> of the form validation works, with one exception.
>
> >> The new regex doesn't allow for upper case letters, only lower case.
>
> >> I tried changing it from; '/^[a-z]$/i'
>
> >> to: '/^[a-z][A-Z]$/i' --didn't work
>
> >> to: '/^[a-zA-Z]$/i' --didn't work
>
> >> I think there's something basic I'm missing here!
>
> >> As for the company name that still gives the same errors as before.
>
> >> Thanks for your help thus far, Felix.
>
> >> On Jul 13, 3:13 pm, McBuck DGAF  wrote:
>
> >> > Sorry, I wasn't looking at the regex itself, I was just looking at the
> >> > way you implemented it (and we have not addressed your 'company_name'
> >> > issue at all, but the solution here should be readily adaptable to
> >> > that).
>
> >> > I am no regex expert, but wouldn't the following get you what you
> >> > want?:
>
> >> > 'rule' => '/^[a-z]$/i',
>
> >> >  (the regex must be delimited by "/", which is probably the source of
> >> > your current error)
>
> >> > On Jul 12, 7:18 pm, Felix  wrote:
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
> > with their CakePHP related questions.
>
> > 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+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-13 Thread Felix Fennell
Removing the /i doesn't do anything unfortunately - I read the
handbook page too and thought it should work.

They use this to check for any string using alphanumeric characters +
dashes + underscores;

[0-9a-zA-Z_-]

So I would have though that using [a-zA-Z] would work for just upper
and lowercase letters.

Just so I'm not doing anything stupid, everytime I update the
validation in the model and upload it, I then delete what ever files
are in the /app/tmp/cache/models directory - is there anything else I
need to do.

Felix.

On 13 July 2010 19:37, McBuck DGAF  wrote:
> I thought the "i" at the end of the rule I suggested would make it
> case insensitive, as described in the manual. (Like I said, regex is
> not my thing, I am still learning there . . .)  Anyway, try removing
> the "i" from the end of the last rule you suggested (ie, '/^[a-zA-Z]
> $/') and see if that works.
>
> On Jul 13, 1:36 pm, Felix  wrote:
>> OK, that validation rule works, kinda.
>>
>> If I remove the validation for the company name (temporarily) the rest
>> of the form validation works, with one exception.
>>
>> The new regex doesn't allow for upper case letters, only lower case.
>>
>> I tried changing it from; '/^[a-z]$/i'
>>
>> to: '/^[a-z][A-Z]$/i' --didn't work
>>
>> to: '/^[a-zA-Z]$/i' --didn't work
>>
>> I think there's something basic I'm missing here!
>>
>> As for the company name that still gives the same errors as before.
>>
>> Thanks for your help thus far, Felix.
>>
>> On Jul 13, 3:13 pm, McBuck DGAF  wrote:
>>
>> > Sorry, I wasn't looking at the regex itself, I was just looking at the
>> > way you implemented it (and we have not addressed your 'company_name'
>> > issue at all, but the solution here should be readily adaptable to
>> > that).
>>
>> > I am no regex expert, but wouldn't the following get you what you
>> > want?:
>>
>> > 'rule' => '/^[a-z]$/i',
>>
>> >  (the regex must be delimited by "/", which is probably the source of
>> > your current error)
>>
>> > On Jul 12, 7:18 pm, Felix  wrote:
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-13 Thread McBuck DGAF
I thought the "i" at the end of the rule I suggested would make it
case insensitive, as described in the manual. (Like I said, regex is
not my thing, I am still learning there . . .)  Anyway, try removing
the "i" from the end of the last rule you suggested (ie, '/^[a-zA-Z]
$/') and see if that works.

On Jul 13, 1:36 pm, Felix  wrote:
> OK, that validation rule works, kinda.
>
> If I remove the validation for the company name (temporarily) the rest
> of the form validation works, with one exception.
>
> The new regex doesn't allow for upper case letters, only lower case.
>
> I tried changing it from; '/^[a-z]$/i'
>
> to: '/^[a-z][A-Z]$/i' --didn't work
>
> to: '/^[a-zA-Z]$/i' --didn't work
>
> I think there's something basic I'm missing here!
>
> As for the company name that still gives the same errors as before.
>
> Thanks for your help thus far, Felix.
>
> On Jul 13, 3:13 pm, McBuck DGAF  wrote:
>
> > Sorry, I wasn't looking at the regex itself, I was just looking at the
> > way you implemented it (and we have not addressed your 'company_name'
> > issue at all, but the solution here should be readily adaptable to
> > that).
>
> > I am no regex expert, but wouldn't the following get you what you
> > want?:
>
> > 'rule' => '/^[a-z]$/i',
>
> >  (the regex must be delimited by "/", which is probably the source of
> > your current error)
>
> > On Jul 12, 7:18 pm, Felix  wrote:

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-13 Thread Felix
OK, that validation rule works, kinda.

If I remove the validation for the company name (temporarily) the rest
of the form validation works, with one exception.

The new regex doesn't allow for upper case letters, only lower case.

I tried changing it from; '/^[a-z]$/i'

to: '/^[a-z][A-Z]$/i' --didn't work

to: '/^[a-zA-Z]$/i' --didn't work

I think there's something basic I'm missing here!

As for the company name that still gives the same errors as before.

Thanks for your help thus far, Felix.

On Jul 13, 3:13 pm, McBuck DGAF  wrote:
> Sorry, I wasn't looking at the regex itself, I was just looking at the
> way you implemented it (and we have not addressed your 'company_name'
> issue at all, but the solution here should be readily adaptable to
> that).
>
> I am no regex expert, but wouldn't the following get you what you
> want?:
>
> 'rule' => '/^[a-z]$/i',
>
>  (the regex must be delimited by "/", which is probably the source of
> your current error)
>
> On Jul 12, 7:18 pm, Felix  wrote:

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-13 Thread McBuck DGAF
Sorry, I wasn't looking at the regex itself, I was just looking at the
way you implemented it (and we have not addressed your 'company_name'
issue at all, but the solution here should be readily adaptable to
that).

I am no regex expert, but wouldn't the following get you what you
want?:

'rule' => '/^[a-z]$/i',

 (the regex must be delimited by "/", which is probably the source of
your current error)

On Jul 12, 7:18 pm, Felix  wrote:

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-12 Thread Felix
Hi, thanks for the reply - I have updated the validation rules in the
model with your suggestion, I get the following errors back for data
that should be valid (ie. allowed)

==

Warning (2): preg_match() [function.preg-match]: No ending delimiter
'^' found [CORE/cake/libs/model/model.php, line 2571]
Notice (8): Undefined offset:  0 [CORE/cake/libs/model/model.php, line
2550]
Warning (512): Could not find validation handler  for company_name
[CORE/cake/libs/model/model.php, line 2573]

==

The validation rule should only allow a user to input lower and upper
case letters - no numbers spaces or punctuation. (I'm hoping thats
what my original expressions did!)

The "Account" model now reads as;

==

 array(
 'rule' => 'email',
 'message' => 'Email must be valid.',
 'allowEmpty' => false
  ),
  'password' => array(
 'rule' => array('minlength', 6),
 'message' => 'Passwords must be six (6) characters or
more.',
 'allowEmpty' => false
  ),
  'first_name' => array(
 'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$',
 'message' => 'Names can only contain letters.',
 'allowEmpty' => false
  ),
  'second_name' => array(
 'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$',
 'message' => 'Names can only contain letters.',
 'allowEmpty' => false
  ),
  'company_name' => array(
 'rule' => array('custom' => '(\w(\s)?)+'),
 'message' => 'Company names can only contain letters,
numbers and spaces.'
  ),
  /*
  'terms_accepted' => array(
  'rule' => array('boolean'),
  'required' => true,
  'message' => 'You must agree to the terms and conditions
and privacy policy.',
  )
   */
  );
}
?>

==

On Jul 12, 2:39 pm, McBuck DGAF  wrote:
> Instead of:
>
> >                'rule' => array('custom' => 
> > '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$'),
>
> Could you try:
>
>                 'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*
> $',
>
> If that works, and you use this regular expression more than once, you
> could consider implementing a custom validation rule as described
> here:
>
> http://book.cakephp.org/view/1179/Custom-Validation-Rules
>
> On Jul 11, 5:41 pm, Felix  wrote:
>
>
>
> > Hi, I have an odd validation issue I can't work out.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-12 Thread Felix Fennell
Hi, thanks for the reply - I have updated the validation rules in the
model with your suggestion, I get the following errors back for data
that should be valid (ie. allowed)

==

Warning (2): preg_match() [function.preg-match]: No ending delimiter
'^' found [CORE/cake/libs/model/model.php, line 2571]
Notice (8): Undefined offset:  0 [CORE/cake/libs/model/model.php, line 2550]
Warning (512): Could not find validation handler  for company_name
[CORE/cake/libs/model/model.php, line 2573]

==

The validation rule should only allow a user to input lower and upper
case letters - no numbers spaces or punctuation. (I'm hoping thats
what my original expressions did!)

The "Account" model now reads as;

==

 array(
  'rule' => 'email',
  'message' => 'Email must be valid.',
  'allowEmpty' => false
   ),
   'password' => array(
  'rule' => array('minlength', 6),
  'message' => 'Passwords must be six (6) characters or more.',
  'allowEmpty' => false
   ),
   'first_name' => array(
  'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$',
  'message' => 'Names can only contain letters.',
  'allowEmpty' => false
   ),
   'second_name' => array(
  'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$',
  'message' => 'Names can only contain letters.',
  'allowEmpty' => false
   ),
   'company_name' => array(
  'rule' => array('custom' => '(\w(\s)?)+'),
  'message' => 'Company names can only contain letters,
numbers and spaces.'
   ),
   /*
   'terms_accepted' => array(
   'rule' => array('boolean'),
   'required' => true,
   'message' => 'You must agree to the terms and conditions
and privacy policy.',
   )
*/
   );
}
?>

==

On 12 July 2010 14:39, McBuck DGAF  wrote:
> Instead of:
>
>>                'rule' => array('custom' => 
>> '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$'),
>
> Could you try:
>
>                'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*
> $',
>
> If that works, and you use this regular expression more than once, you
> could consider implementing a custom validation rule as described
> here:
>
> http://book.cakephp.org/view/1179/Custom-Validation-Rules
>
>
> On Jul 11, 5:41 pm, Felix  wrote:
>> Hi, I have an odd validation issue I can't work out.
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-12 Thread McBuck DGAF
Instead of:

>'rule' => array('custom' => 
> '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$'),

Could you try:

'rule' => '^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*
$',

If that works, and you use this regular expression more than once, you
could consider implementing a custom validation rule as described
here:

http://book.cakephp.org/view/1179/Custom-Validation-Rules


On Jul 11, 5:41 pm, Felix  wrote:
> Hi, I have an odd validation issue I can't work out.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-02-10 Thread Guillermo Mansilla
I would do something like this:
items_controller.php

function foo(){
if (!empty($this->data)) { //check if there is data sent
if($this->User->field('email', array('conditions' =>
array('email' => $this->data['User']['email']{ //find the emai in the
database

} else {  //email not found
 //your requestAction call
}
}
}

On 10 February 2010 01:09, dtirer  wrote:

> I have a form with an 'Item' and 'email' field.  It submits to an
> Items Controller.
> I want to validate both fields, however, the 'email' is technically
> part of a User model.
>
> So what happens is, when the form is submitted, it's supposed to
> search for the Item in the form.  it also check if the email is
> already in the DB, and if it isn't it does a requestAction to the
> UsersController, and runs the email through the signup() function, and
> then goes back to finishing the Items Controler work.
>
> So how do I go about validating the Email field?
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem wtih "required" flag set

2009-12-23 Thread Dr. Loboto
When cake validates fields it first checks for field existence in data
array. If there is no such key, with required=true cake invalidate it,
with required=false cake skip it. So this flag behave exactly as it is
named. If field is required it must be present in data array.

On Dec 24, 1:21 am, Philip  wrote:
> Hi all,
>
> I have been reading posts on the confusion over "required" flag and I
> think I understand it pretty well.
>
> However I am having problem trying to make it work.
>
> For example, here is my call:
>
> $this->User->validate(array('User'=>array('username'=>'test')));
>
> And for the model, I have just one rule, which is "notEmpty" with
> "required" set to "true".
>
> Odd thing is that if I use a html FORM to post ($this->User->validate
> ($_POST['data']), then it works, but not when I invoke it directly.
>
> I am wondering if this has anything to do with the way I structure the
> data array?
>
> Any ideas would be appreciated, many thanks in advance.
>
> Philip

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: validation problem

2009-03-14 Thread brian

On Sat, Mar 14, 2009 at 6:32 AM, kaushik  wrote:
>
> I do not want to save the data, I want just if user has entered any
> valid data, the valid data should not be entered again, they should
> remain in the input box and invalid field will be blank with error
> massage. Now he has to entry all the data again.

If you don't remove or change $this->data then the form should be
re-filled by FormHelper when that view is displayed again.

function yourAction()
{
if (!empty($this->data))
{
/* only reach here 2nd time through
 */
if ($this->YourModel->validates)
{
  if ($this->YourModel->save($this->data)
  {
...
/* you will not reach here if validation failed
 */
$this->redirect(...);
  }
}
}
// display the form  ...
}

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



Re: validation problem

2009-03-14 Thread kaushik

I do not want to save the data, I want just if user has entered any
valid data, the valid data should not be entered again, they should
remain in the input box and invalid field will be blank with error
massage. Now he has to entry all the data again.

On Mar 13, 1:33 pm, ShuXun Liu  wrote:
> Try use the third param in Save action.
> like this:
>
> $this->User->save(   $this->data,  // make sure there is a "id" in data
> array
>    true,
>    array('email') //just save email
> )
>
> 2009/3/13 kaushik 
>
>
>
> > I have validate different field using cakephp's in-bulit validation
> > system. but now problem is that the system does not persist all the
> > values even if they are valid, e.g in a form, i have to give name,
> > email, state, and the value given in email is not valid, but other
> > values given in the field is valid. But when the system is reloading
> > the form with the error massage, all the fields are blanks. I want to
> > persist the valid values so that the user has to enter just invalid
> > data.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validation problem

2009-03-13 Thread ShuXun Liu
Try use the third param in Save action.
like this:

$this->User->save(   $this->data,  // make sure there is a "id" in data
array
   true,
   array('email') //just save email
)



2009/3/13 kaushik 

>
> I have validate different field using cakephp's in-bulit validation
> system. but now problem is that the system does not persist all the
> values even if they are valid, e.g in a form, i have to give name,
> email, state, and the value given in email is not valid, but other
> values given in the field is valid. But when the system is reloading
> the form with the error massage, all the fields are blanks. I want to
> persist the valid values so that the user has to enter just invalid
> data.
> >
>

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



Re: Validation Problem

2009-03-02 Thread Braindead

Take a look at the MultivalidateableBehavior in the bakery. That's
what I used to solve your kind of problems.
http://bakery.cakephp.org/articles/view/multivalidatablebehavior-using-many-validation-rulesets-per-model
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validation Problem

2009-03-02 Thread brian

You can use 'on' => 'create' or 'on' => 'update' to gain a finer grain
of control. You can also set 'allowEmpty' => true for some fields.

See here:
http://teknoid.wordpress.com/2008/06/09/15-essential-cakephp-tips/
http://lemoncake.wordpress.com/2007/07/03/all-about-validation-in-cakephp-12/

On Mon, Mar 2, 2009 at 1:07 AM, akmjahan...@gmail.com
 wrote:
>
> I am facing a problem about validation. In my user model there are 20
> validation for registration form. During registration validation works
> properly. But when any other action (i.e. update profile) under user
> controller there are only 8 fields to check validation from user model
> but it get failed. In this case when I removed others validation rule
> (from all 20) i.e. 12 out of 20 (only 8 from update profile action)
> then update profile action works. But I need all 20 rules within user
> model. Is there anyone to help me ?
>
> >
>

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



Re: Validation problem

2009-01-06 Thread dbennett


Be careful using the alphaNumeric and money validation rules as they require
UTF-8 support for PCRE.  On a stock Centos 5 install (or Redhat ES5) I have
PCRE 6.6 06-Feb-2006  compiled in.The following script fails (the
alphaNumeric test from CakePHP 1.2 validation.php):



If you don't need UTF-8 alphaNumeric support I recommend a simpler match
expression:

  /^[A-Z0-9]+$/

--Dave


Oribium wrote:
> 
> 
> I am taking a look at cake 1.2, and I run into problems with the
> validation
> of form data. I took advantage of the console application to bake some
> views, a model, and a controller based on an existing MySQL-database.
> I
> don't yet have a deep understanding of cake, and would happily welcome
> hints and pointers which direction I should go.
> 
> I am trying to post data from a form to a database. However, whatever
> data
> I post, I get redirected back to the form, where a label "This field
> cannot
> be left blank" is attached to all fields. For instance if I fill the
> alphanumeric field "last_name" with "Jones" (without qoutes), I will
> get
> the error message: "This field cannot be left blank". Futhermore,
> $this->validationErrors contains all fields and the same error
> message. I
> have verified that the correct data from the form are assigned to the
> controller object's data array with Configure::write('debug', 3);
> 
> The view is just a simple form like:
> 
> echo $form->create('Lead');
> echo $form->input('last_name');
> echo $form->input('modified_user_id');
> ... quite a few more fields here ...
> echo $form->end('Submit');
> 
> There are also a few form fields added with pure html code. These
> fields
> are not supposed to be posted to the database, neither be validated
> with
> the standard cake validation feature.
> 
> In the model, there is nothing but "name" and the validation array.
> 
> The model's validation array looks like:
> 
> var $validate = array(
> 'last_name' => array('alphanumeric'),
> 'modified_user_id' => array('alphanumeric'),
> --- quite a few more fields here ---
> )
> 
> The controller's add function:
> 
> function add() {
> if (!empty($this->data)) {
> if ($this->RequestHandler->isPost()) {
> $this->Lead->create();
> $this->Lead->set($this->data);
> if ($this->Lead->save($this->data)) {
> $this->Session->setFlash(__('The Lead has been saved', true));
> $this->redirect(array('action'=>'index'));
> } else {
> $this->Session->setFlash(__('The Lead could not be saved. Please, try
> again.', true));
> }
> }
> }
> }
> 
> I also tried the following code in the controller: if
> ($this->Lead->validates()) with the same result.
> 
> PHP version: 5.1.6
> OS: Linux
> 
> CakePHP version:
> $Id: VERSION.txt 7692 2008-10-02 05:06:48Z nate $
> 
> libs/model/model.php version:
> $Id: model.php 7690 2008-10-02 04:56:53Z nate $
> 
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Validation-problem-tp21051012p21315909.html
Sent from the CakePHP mailing list archive at Nabble.com.


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



Re: Validation problem

2008-12-17 Thread pkclarke

Hi Oribium,

I have had this problem.  "This field cannot be left blank" is Cake's
default response when the data you are saving does not meet your data
structure and you haven't configured a validation message for the
validation scenario.

For example: if you specify a max field length of 3 characters, then
try to save a string of 3 or more, you get the "This field cannot be
left blank" response (if you haven't configured a validation rule in
your Model).

Additionally, it seems the message does not necessarily appear on the
field which is having the issue.

To fix it, try constructing a query to save the data that is causing
the issue.  When you identify the problematic data, add a validation
rule into your model to catch it and return a more meaningful
validation message.


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



Re: Validation problem

2008-12-17 Thread Oribium

Thank you for you reply, Rob.

I simplified things trying to get the troubleshooting more easy. I
created
a model, and a view with only one field, "first_name". I also created
an
add function in the controller which is supposed to validate input
rather
then saving data to the database. The problem remains and I get
redirected
back to the form, where a label "Valid characters: letters and numbers
only, please try again" is attached to the field.

The view:


create('Lead');?>


input('first_name'); ?>

end('Submit');
pr($this->validationErrors);
pr($session);
?>

The model:

 array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Valid characters: letters and numbers only, 
please try
again.'
)));
}
?>

The add function in the controller:

function add() {
if (!empty($this->data)) {
if ($this->RequestHandler->isPost()) {
$this->Lead->create();
$this->Lead->set($this->data);
Debugger::dump($this->data['Lead']);
Debugger::dump($this->Lead->validationErrors);
Debugger::dump($this->Lead->invalidFields());
Debugger::dump($this->Lead->validate);
if ($this->Lead->validates()) {
$this->_sendMail();
$this->Session->setFlash(__('The Lead 
has been saved', true));

$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Lead 
could not be saved. Please,
try
again.', true));
}
}
}
}


Output from the Debugger statements in the add function:

array(
"first_name" => "Paul"
)

array()

array(
"first_name" => "Valid characters: letters and numbers only, please
try
again."
)

array(
"first_name" => array()
)

Dump of the SessionHelper Object:

SessionHelper Object
(
   [helpers] =>
   [__active] => 1
   [valid] =>
   [error] =>
   [_userAgent] => 372acfb5aa1873a6a6ce218959a07d36
   [path] => /
   [lastError] =>
   [security] =>
   [time] => 1229549419
   [sessionTime] =>
   [watchKeys] => Array
   (
   )

   [id] =>
   [_log] =>
   [base] => /somepath
   [webroot] => /somepath/
   [here] => /somepath/leads/add
   [params] => Array
   (
   [pass] => Array
   (
   )

   [named] => Array
   (
   )

   [controller] => leads
   [action] => add
   [plugin] =>
   [form] => Array
   (
   )

   [data] => Array
   (
   [Lead] => Array
   (
   [first_name] => Paul
   )

   )

   [url] => Array
   (
   [url] => leads/add
   )

   [isAjax] =>
   [models] => Array
   (
   [0] => Lead
   )

   )

   [action] => add
   [data] => Array
   (
   [Lead] => Array
   (
   [first_name] => Paul
   )

   )

   [themeWeb] =>
   [plugin] =>
   [validationErrors] => Array
   (
   [Lead] => Array
   (
   [first_name] => Valid characters: letters and
numbers
only, please try again.
   )

   )

)

On 17 Dec, 20:03, Rob  wrote:
> Without looking at your data model, I can't say for sure, but it would
> seem like you may be breaking a rule that is implied by the table.
>
> That said, you might want to add a message to your $validate like:
>
>             'last_name'  => array(
>                 'alphaNumeric' => array(
>                     'rule' => 'alphanumeric',
>                     'message' => 'Only letters and numbers for last
> name, please try again.'
>             ),
>         )
>
> On Dec 17, 2:56 am, Oribium  wrote:
>
> > I am taking a look at cake 1.2, and I run into problems with the
> > validation
> > of form data. I took advantage of the console application to bake some
> > views, a model, and a controller based on an existing MySQL-database.
> > I
> > don't yet have a deep understanding of cake, and would happily welcome
> > hints and pointers which direction I should go.
>
> > I am trying to post data from a form to a database. However, whatever
> > data
> > I post, I get redirected back to the form, where a label "This field
> > cannot
> > be left blank" is attached to all fields. For instance if I fill the
> > alphanumeric field "last_name" with "Jones" (wi

Re: Validation problem

2008-12-17 Thread Rob

Without looking at your data model, I can't say for sure, but it would
seem like you may be breaking a rule that is implied by the table.

That said, you might want to add a message to your $validate like:

'last_name'  => array(
'alphaNumeric' => array(
'rule' => 'alphanumeric',
'message' => 'Only letters and numbers for last
name, please try again.'
),
)

On Dec 17, 2:56 am, Oribium  wrote:
> I am taking a look at cake 1.2, and I run into problems with the
> validation
> of form data. I took advantage of the console application to bake some
> views, a model, and a controller based on an existing MySQL-database.
> I
> don't yet have a deep understanding of cake, and would happily welcome
> hints and pointers which direction I should go.
>
> I am trying to post data from a form to a database. However, whatever
> data
> I post, I get redirected back to the form, where a label "This field
> cannot
> be left blank" is attached to all fields. For instance if I fill the
> alphanumeric field "last_name" with "Jones" (without qoutes), I will
> get
> the error message: "This field cannot be left blank". Futhermore,
> $this->validationErrors contains all fields and the same error
> message. I
> have verified that the correct data from the form are assigned to the
> controller object's data array with Configure::write('debug', 3);
>
> The view is just a simple form like:
>
> echo $form->create('Lead');
> echo $form->input('last_name');
> echo $form->input('modified_user_id');
> ... quite a few more fields here ...
> echo $form->end('Submit');
>
> There are also a few form fields added with pure html code. These
> fields
> are not supposed to be posted to the database, neither be validated
> with
> the standard cake validation feature.
>
> In the model, there is nothing but "name" and the validation array.
>
> The model's validation array looks like:
>
> var $validate = array(
> 'last_name' => array('alphanumeric'),
> 'modified_user_id' => array('alphanumeric'),
> --- quite a few more fields here ---
> )
>
> The controller's add function:
>
> function add() {
> if (!empty($this->data)) {
> if ($this->RequestHandler->isPost()) {
> $this->Lead->create();
> $this->Lead->set($this->data);
> if ($this->Lead->save($this->data)) {
> $this->Session->setFlash(__('The Lead has been saved', true));
> $this->redirect(array('action'=>'index'));} else {
>
> $this->Session->setFlash(__('The Lead could not be saved. Please, try
> again.', true));
>
> }
> }
> }
> }
>
> I also tried the following code in the controller: if
> ($this->Lead->validates()) with the same result.
>
> PHP version: 5.1.6
> OS: Linux
>
> CakePHP version:
> $Id: VERSION.txt 7692 2008-10-02 05:06:48Z nate $
>
> libs/model/model.php version:
> $Id: model.php 7690 2008-10-02 04:56:53Z nate $
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validation problem

2008-07-04 Thread Steve W

Have you tried specifying the rule as an array as per the docs?

http://manual.cakephp.org/view/141/email

...
'rule' => array('email', true)


On Jul 4, 10:48 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> is try to validate an emailadres, my fieldname is 'email'.
>
> The code looks like this:
>
> var $validate = array(
> 'email' => array(
> 'rule' => 'email',
> 'message' => 'Please enter valid emailadres'
> )
> );
>
> I doesn't trigger an error, not when left blank, or entering 'sldkjf'.
>
> What's my problem?

--~--~-~--~~~---~--~~
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: validation problem

2008-07-04 Thread [EMAIL PROTECTED]

need no help anymore
--~--~-~--~~~---~--~~
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: Validation problem in CakePHP 1.2

2008-04-26 Thread Cody Sortore

Never mind I found my answer!  For those of you looking to get two
password fields to validate, or having the same problem as me this
form has your answers.  Here's what was wrong:

In the Controller this is what I had:

   //register function
function register() {
if (!empty($this->data)) {
if ($this->data['User']['password'] == $this-
>Auth->password($this-
>data['User']['password_confirm'])) {

$this->User->create();
$this->User->save($this->data);
$this->Session->setFlash("You have
been registered!  You can log
in now.");
$this->redirect(array('action' =>
'index'));
}
}
}

I checked out my original code and compared it, after comparing it I
added this little snippet and now it works:

//register function
function register() {
if (!empty($this->data)) {
if ($this->data['User']['password'] == 
$this->Auth->password($this-
>data['User']['password_confirm'])) {
$this->User->create() && 
$this->User->validates();
if ($this->User->save($this->data)) {
$this->Session->setFlash("You have been 
registered!  You can log
in now.");
$this->redirect(array('action' => 
'index'));
}
}
}
}


--~--~-~--~~~---~--~~
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: Validation problem in CakePHP 1.2

2008-04-26 Thread Cody Sortore

Controller (where I suspect the problem is, most changes were made
here):

Auth->allow('register', 'top');
}

//top users funciton
function top() {
$this->set('users', $this->User->findAll());
}

//login function
function login() {
}

//index function
function index() {
}

//register function
function register() {
if (!empty($this->data)) {
if ($this->data['User']['password'] == 
$this->Auth->password($this-
>data['User']['password_confirm'])) {
$this->User->create();
$this->User->save($this->data);
$this->Session->setFlash("You have been 
registered!  You can log
in now.");
$this->redirect(array('action' => 'index'));
}
}
}
}

?>

Model:

 array(
VALID_NOT_EMPTY,
'alphanumeric' => array(
'rule' => 'alphaNumeric',
'message' => 'Only alphabets and numbers allowed',
),
'maxlength' => array(
'rule' => array('maxLength', 50),
'message' => 'Username has a maximum length of 
50 characters',
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Username is required, how do you 
expect to log in?'
),
'isUnique' => array(
'rule' => array('isUnique', 'username'),
'message' => 'Hey! Lookey there, someone got to 
that username
before you. Sorry, but you\'ll have to choose another.'
)
),

//email validation
'email' => array(
VALID_NOT_EMPTY,
'maxlength' => array(
'rule' => array('maxLength', 40),
'message' => 'Email has a maximum length of 40 
characters.'
),
'email' => array(
'rule' => array('email', true),
'message' => 'Please supply a valid email 
address.'
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Email is required.'
),
'isUnique' => array(
'rule' => array('isUnique', 'email'),
'message' => 'That email address has already 
been claimed by
another... maybe even you, please try again.  This time enter an email
address not in use on this site ;-)'
)
),

//first name validation
'first_name' => array(
VALID_NOT_EMPTY,
'maxlength' => array(
'rule' => array('maxLength', 15),
'message' => 'First name has a maximum length 
of 15 characters',
),
'required' => array(
'rule' => array('required' => true),
'message' => 'First name is required, don\'t 
you want your friends
to be able to find you?'
)
),

//last name validation
'last_name' => array(
VALID_NOT_EMPTY,
'maxlength' => array(
'rule' => array('maxLength', 30),
'message' => 'Last name has a maximum length of 
30 characters'
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Last name is required, don\'t you 
want your friends
to be able to find you?'
)
),

//password validation
'password' => array(
'passwordConfirm' => array(
'rule' => array('confirmPassword', 'password'),
'message' => 'passwords don\'t match up, please 
verify and submit
again!'
)
),

//confirm password
'confirm_password' => array(
VALID_NOT_EMPTY,
'alphanumeric' => array(
'rule' => 'alphaNum

Re: Validation Problem

2008-04-23 Thread b logica

I'm a dough-head. Sorry, I didn't read your post correctly.

But, would you really need to change the name f any countries? Those
don't change too often. And when one did, I'd think you'd want to
update the main DB record for it rather than the association to some
other model.

If what you want to do is to update the list of associated countries
to your model, you could do:

$form->select('Country.Country', $countries, null, array('class' =>
'Required', 'multiple' => 'checkbox'));

(note the double "Country"--that's important)

This will create checkboxes for each country. I can't remember,
offhand, how to make the associated ones checked (sorry).

Your $countries var would be an array gotten from a find('list') call
in the controller. Or, you could replace it with

$this->requestAction('Countries/getList') if you had an appropriate
controller/action for that.

On Wed, Apr 23, 2008 at 1:57 PM, plinto <[EMAIL PROTECTED]> wrote:
>
>  Thanks, I understand what you are saying but what I need is to be able
>  to edit mutliple items at once.
>  For example if I have to edit 20 countries, clicking on every one,
>  editing it and saving it would take me alot more time then selecting
>  the ones I need to edit and having them presented in 1 page to be
>  edited and saved.
>  I also need to validate them but, for example, being all
>  "Country.name" I don't know how to obtain this.
>
>  For the part about the parser, Thanks! I'm pretty new to php and
>  cakephp, but willing to learn.
>
>
>
>  On Apr 22, 6:49 pm, "b logica" <[EMAIL PROTECTED]> wrote:
>  > You might find it simpler to, instead creating a form, to put links
>  > around the country names pointing to an edit method. In the edit view,
>  > create one form to edit the table fields and one form to delete. So
>  > you have something like:
>  >
>  > Edit Canada
>  >
>  > echo $form->create('Country', array('action' => 'delete');
>  > echo $form->hidden('Country.id', array('value' => $some_var));
>  > echo $form->submit('delete');
>  > echo $form->end();
>  >
>  > echo $form->create('Country', array('action' => 'edit');
>  > ...
>  > echo $form->submit('edit');
>  > echo $form->end();
>  >
>  > This way, each action points directly to the corresponding method and
>  > you only have to deal with one item at a time. I realise that this may
>  > not be practical but it may work for you.
>  >
>  > Regarding $some_var above, your code appears to assume that the
>  > country IDs & names are going to line up with your counter var $i. I
>  > may be missing something but that looks odd to me. I'd think it's be
>  > better (if your $countries array is constructed as $id => $name) to do
>  > it with a while like so:
>  >
>  > foreach ($countries as $key => $name)
>  > {
>  >$html->link($name, "countries/edit/${id}");
>  >
>  > }
>  >
>  > I've used my link suggestion but it's just as applicable to a form
>  > setup like you have.
>  >
>  > BTW, in your views, you don't need to put  around every
>  > line. If you don't have any HTML markup to add then you can just open
>  > a block:
>  >
>  >   > echo $form->create(array('url'=>'/countries/process'));
>  >
>  > for($i =0; $i<$countries; $i++) {
>  >echo $form->hidden('Country'.$i.'.Country.id');
>  >echo $form->input('Country'.$i.'.Country.name');
>  >
>  > }
>  >
>  > echo $form->submit('Save', array('name'=>'save'));
>  > echo $form->end();
>  > ?>
>  >
>  > Otherwise, you're making the parser (and anyone who has to look at
>  > your code) work a lot harder than necessary ;-)
>
>
>
> >
>

--~--~-~--~~~---~--~~
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: Validation Problem

2008-04-23 Thread plinto

Thanks, I understand what you are saying but what I need is to be able
to edit mutliple items at once.
For example if I have to edit 20 countries, clicking on every one,
editing it and saving it would take me alot more time then selecting
the ones I need to edit and having them presented in 1 page to be
edited and saved.
I also need to validate them but, for example, being all
"Country.name" I don't know how to obtain this.

For the part about the parser, Thanks! I'm pretty new to php and
cakephp, but willing to learn.

On Apr 22, 6:49 pm, "b logica" <[EMAIL PROTECTED]> wrote:
> You might find it simpler to, instead creating a form, to put links
> around the country names pointing to an edit method. In the edit view,
> create one form to edit the table fields and one form to delete. So
> you have something like:
>
> Edit Canada
>
> echo $form->create('Country', array('action' => 'delete');
> echo $form->hidden('Country.id', array('value' => $some_var));
> echo $form->submit('delete');
> echo $form->end();
>
> echo $form->create('Country', array('action' => 'edit');
> ...
> echo $form->submit('edit');
> echo $form->end();
>
> This way, each action points directly to the corresponding method and
> you only have to deal with one item at a time. I realise that this may
> not be practical but it may work for you.
>
> Regarding $some_var above, your code appears to assume that the
> country IDs & names are going to line up with your counter var $i. I
> may be missing something but that looks odd to me. I'd think it's be
> better (if your $countries array is constructed as $id => $name) to do
> it with a while like so:
>
> foreach ($countries as $key => $name)
> {
>$html->link($name, "countries/edit/${id}");
>
> }
>
> I've used my link suggestion but it's just as applicable to a form
> setup like you have.
>
> BTW, in your views, you don't need to put  around every
> line. If you don't have any HTML markup to add then you can just open
> a block:
>
>  echo $form->create(array('url'=>'/countries/process'));
>
> for($i =0; $i<$countries; $i++) {
>echo $form->hidden('Country'.$i.'.Country.id');
>echo $form->input('Country'.$i.'.Country.name');
>
> }
>
> echo $form->submit('Save', array('name'=>'save'));
> echo $form->end();
> ?>
>
> Otherwise, you're making the parser (and anyone who has to look at
> your code) work a lot harder than necessary ;-)

--~--~-~--~~~---~--~~
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: Validation Problem

2008-04-22 Thread b logica

You might find it simpler to, instead creating a form, to put links
around the country names pointing to an edit method. In the edit view,
create one form to edit the table fields and one form to delete. So
you have something like:

Edit Canada

echo $form->create('Country', array('action' => 'delete');
echo $form->hidden('Country.id', array('value' => $some_var));
echo $form->submit('delete');
echo $form->end();

echo $form->create('Country', array('action' => 'edit');
...
echo $form->submit('edit');
echo $form->end();

This way, each action points directly to the corresponding method and
you only have to deal with one item at a time. I realise that this may
not be practical but it may work for you.

Regarding $some_var above, your code appears to assume that the
country IDs & names are going to line up with your counter var $i. I
may be missing something but that looks odd to me. I'd think it's be
better (if your $countries array is constructed as $id => $name) to do
it with a while like so:

foreach ($countries as $key => $name)
{
   $html->link($name, "countries/edit/${id}");
}

I've used my link suggestion but it's just as applicable to a form
setup like you have.

BTW, in your views, you don't need to put  around every
line. If you don't have any HTML markup to add then you can just open
a block:

create(array('url'=>'/countries/process'));

for($i =0; $i<$countries; $i++) {
   echo $form->hidden('Country'.$i.'.Country.id');
   echo $form->input('Country'.$i.'.Country.name');
}

echo $form->submit('Save', array('name'=>'save'));
echo $form->end();
?>

Otherwise, you're making the parser (and anyone who has to look at
your code) work a lot harder than necessary ;-)

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

2007-03-03 Thread Grant Cox

Use $form->error() instead of $html->tagErrorMsg() in 1.2


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



SOLVED. Re: Validation problem with multiple select boxes

2007-02-17 Thread Norman

Well, I got it. Mea maxima culpa.
In the controller, I was setting the select[Model] array with only one
index. Instead of:

if(empty($this->data['Model']['Model'])) { $this->data['Model']
['Model'] = null; }
$this->set('selectedModels', $this->data['Model']['Model']);

I was trying:

if(empty($this->data['Model'])) { $this->data['Model'] = null; }
$this->set('selectedAreas', $this->data['Model']);

This was bombing out at the _selectedArray method of the controller
class. After some hours scattering var_dumps here and there, the
problem became obvious. Hope with time and experience I start to get
these kind of stupid mistakes faster. Or avoid them.
Norman

On 16 fev, 20:36, "Norman" <[EMAIL PROTECTED]> wrote:
> Forget about my previous post, and my sincere apologies to Evan Sagge,
> his fine piece of code have no connection with my misery. I "baked"
> from ground up the models, controllers and views for the tables
> involved and the vanilla CakePHP validation is presenting the same
> behavior with multiple select listboxes. If any field does not
> validate, the multiple selects loose their selected options.
>
> Norman
>
> On 16 fev, 20:06, "Norman" <[EMAIL PROTECTED]> wrote:
>
> > One thing I am sure about: This problem is not related with the
> > "vanilla" CakePHP 1.1 validation. Im using "Evan's CakePHP Validation
> > Technique 2.0" (http://blog.evansagge.com/2006/12/28/evans-cakephp-
> > validation-technique-20/) and Im pretty sure theres a bug at the
> > validation class causing this behavior with multiple select boxes. But
> > I was not able to find it.
>
> > Norman
>
> > On 16 fev, 12:34, "Norman" <[EMAIL PROTECTED]> wrote:
>
> > > I have some views for a model with a mix of fields, two of these


--~--~-~--~~~---~--~~
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: Validation problem with multiple select boxes

2007-02-16 Thread Norman

Forget about my previous post, and my sincere apologies to Evan Sagge,
his fine piece of code have no connection with my misery. I "baked"
from ground up the models, controllers and views for the tables
involved and the vanilla CakePHP validation is presenting the same
behavior with multiple select listboxes. If any field does not
validate, the multiple selects loose their selected options.

Norman

On 16 fev, 20:06, "Norman" <[EMAIL PROTECTED]> wrote:
> One thing I am sure about: This problem is not related with the
> "vanilla" CakePHP 1.1 validation. Im using "Evan's CakePHP Validation
> Technique 2.0" (http://blog.evansagge.com/2006/12/28/evans-cakephp-
> validation-technique-20/) and Im pretty sure theres a bug at the
> validation class causing this behavior with multiple select boxes. But
> I was not able to find it.
>
> Norman
>
> On 16 fev, 12:34, "Norman" <[EMAIL PROTECTED]> wrote:
>
> > I have some views for a model with a mix of fields, two of these


--~--~-~--~~~---~--~~
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: Validation problem with multiple select boxes

2007-02-16 Thread Norman

One thing I am sure about: This problem is not related with the
"vanilla" CakePHP 1.1 validation. Im using "Evan's CakePHP Validation
Technique 2.0" (http://blog.evansagge.com/2006/12/28/evans-cakephp-
validation-technique-20/) and Im pretty sure theres a bug at the
validation class causing this behavior with multiple select boxes. But
I was not able to find it.

Norman

On 16 fev, 12:34, "Norman" <[EMAIL PROTECTED]> wrote:
> I have some views for a model with a mix of fields, two of these


--~--~-~--~~~---~--~~
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: Validation problem

2006-10-04 Thread Matt Adams

milicic.marko wrote:

> I need to validte my model in that way to forbide inserting two posts
> with same Title.
> OK. This is not an REGEX type of validation so I suppose I must use
> some callback function.
> I used beforeSave() CB function and returned false if I detect that
> post with that title already exists.
> But, what I'm supposed to do in order to force cake to behave like it
> was an regex type validation failure...
> 
> I want to use  $html->tagErrorMsg to present error message

I much prefer enforcing this sort of model-integrity issue in the 
database by using a UNIQUE index on the column in question.

This approach only works if what you're saying is true in all cases, of 
course.


Cheers,

Matt

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



Re: Validation problem

2006-10-03 Thread milicic.marko

Yeah it helped.
Tnx dude


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



Re: Validation problem

2006-10-02 Thread Sohei Okamoto
In beforeSave(), before returning false, you can do$this->invalidate($field_name);To me, beforeValidate() seems a little more logical place to put that, though.Hope it works for you.Sohei


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