help with uploadedFile validation rule

2015-09-17 Thread Raul Magdalena Catala
hello,

i can not understand how uploadedFile validation rule works, 
http://api.cakephp.org/3.0/class-Cake.Validation.Validation.html#_uploadedFile

can someone help me with and example, expanding below code?

$validator
   ->add('image', ['rule' => ['uploadedFile, 


thanks

-- 
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/d/optout.


Re: Handle validation rule message inside controller

2015-02-23 Thread Andras Kende
http://book.cakephp.org/2.0/en/models/data-validation/validating-data-from-the-controller.html

First, set the data to the model:
$this-ModelName-set($this-request-data);

Then, to check if the data validates, use the validates method of the model, 
which will return true if it validates and false if it doesn’t:
if ($this-ModelName-validates()) {
// it validated logic
} else {
// didn’t validate logic
$errors = $this-ModelName-validationErrors;
}

Andras

 On Feb 21, 2015, at 12:50 AM, giuseppe giorgio gioz...@gmail.com wrote:
 
 Hi there, i've start to learn cake php yesterday, and i have a question. I've 
 declared validation array inside my model class like:
 
 
 public $validate = array(
 'username' = array(
 'alphaNumeric' = array(
 'rule' = 'alphaNumeric',
 'required' = true,
 'message' = 'username required'
  ),
  'unique' = array(
 'rule' = 'isUnique',
 'required' = 'create',
 'message' = 'Username already used'
  )
 ));
 
 
 When i add a new record to my database by using add(), everithing works fine, 
 and alert message are showed automatically. How can i intercept this error 
 message firing inside add() controller function? because if a message is 
 fired, i would perform an action (and not simply show message)
 
 -- 
 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/d/optout.

-- 
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/d/optout.


Handle validation rule message inside controller

2015-02-23 Thread giuseppe giorgio
Hi there, i've start to learn cake php yesterday, and i have a question. 
I've declared validation array inside my model class like:


public $validate = array(
'username' = array(
'alphaNumeric' = array(
'rule' = 'alphaNumeric',
'required' = true,
'message' = 'username required'
 ),
 'unique' = array(
'rule' = 'isUnique',
'required' = 'create',
'message' = 'Username already used'
 )
));


When i add a new record to my database by using add(), everithing works 
fine, and alert message are showed automatically. How can i intercept this 
error message firing inside add() controller function? because if a message 
is fired, i would perform an action (and not simply show message)

-- 
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/d/optout.


Re: cake3 validation rule not performed

2014-11-12 Thread José Lorenzo
What do you mean with the validator ignores? What is the data that you 
are trying to validate and what is the result?

On Tuesday, November 11, 2014 5:03:19 PM UTC+1, cesar calvo wrote:

 Hi people, I have this validation rules in UsersTable.
 The validator ignores the -add(password, lenght) sentence.
 The issue is when I try to create or update a record.

 Best regards --cesar

 public function validationDefault(Validator $validator) {
 return $validator
 -validatePresence('username', 'create')
 -notEmpty('username', __('This field is required.'))
 -add('username', [
 'valid' = [
 'rule' = 'email', 
 'message' = __('This field requires a valid email 
 address.')
 ],
 'unique' = [
 'rule' = 'validateUnique', 
 'provider' = 'table', 
 'message' = __('This field must be unique.')
 ]
 ])
 -validatePresence('password', 'create')
 -notEmpty('password', __('This field is required.'))
 -add('password', [
 'length' = [
 'rule' = ['minLength', 8],
 'message' = __('Password must be at least {0} 
 characters long.', 8),
 ]
 ])
 ;
 }


-- 
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/d/optout.


Re: cake3 validation rule not performed

2014-11-12 Thread cesar calvo
The login form is very similar to that used in the blog tutorial. 
I can see that there is no link to the LOGIN form with associated model.
ADD and EDIT actions perform validation over username but not over password 
field.
With ignore I mean that the model validation rules do not apply. 

public function login() {
if ($this-request-is('post')) {
$user = $this-Auth-identify();
if ($user) {
$this-Auth-setUser($user);
return $this-redirect($this-Auth-redirectUrl());
}
$this-Flash-error(__('Invalid username or password.'));
}
}

public function add() {
$user = $this-Users-newEntity($this-request-data);
if ($this-request-is('post')) {
if ($this-Users-save($user)) {
//mail connection...
$this-Flash-success(__('A message has been sent to your 
email address.'));
return $this-redirect(['action' = 'login']);
}
$this-Flash-error(__('Unable to save your data.'));
}
$this-set(compact('user'));
}

public function edit() {
$user = $this-Users-get($this-Auth-user('id'));
if ($this-request-is(['post', 'put'])) {
$this-Users-patchEntity($user, ['password' = 
$this-request-data('password')]);
if ($this-Users-save($user)) {
$this-Flash-success(__('Your data has been updated.'));
return $this-redirect(['action' = 'index']);
}
$this-Flash-error(__('Unable to update your data.'));
}
$this-set(compact('user'));
}

//login.ctp
?=
$this-Form-create(),
$this-Form-input('username', ['label' = __('Username'), 'required' 
= true, 'placeholder' = __('E-mail address'),]),
$this-Form-input('password', ['label' = __('Password'), 'required' 
= true, 'value' = false]),
$this-Form-button(__('Submit')),
$this-Form-end()
?

//add.ctp
?=
$this-Form-create($user),
$this-Form-input('username', ['label' = __('Username'), 
'placeholder' = __('E-mail address')]),
$this-Form-input('password', ['label' = __('Password'), 'value' = 
false]),
$this-Form-button(__('Submit')),
$this-Form-end()
?

//edit.ctp
?=
$this-Form-create($user),
$this-Form-input('username', ['label' = __('Username'), 'disabled' 
= true]),
$this-Form-input('password', ['label' = __('Password'), 'value' = 
false]),
$this-Form-button(__('Submit')),
$this-Form-end();
?

El miércoles, 12 de noviembre de 2014 07:30:41 UTC-2, José Lorenzo escribió:

 What do you mean with the validator ignores? What is the data that you 
 are trying to validate and what is the result?

 On Tuesday, November 11, 2014 5:03:19 PM UTC+1, cesar calvo wrote:

 Hi people, I have this validation rules in UsersTable.
 The validator ignores the -add(password, lenght) sentence.
 The issue is when I try to create or update a record.

 Best regards --cesar

 public function validationDefault(Validator $validator) {
 return $validator
 -validatePresence('username', 'create')
 -notEmpty('username', __('This field is required.'))
 -add('username', [
 'valid' = [
 'rule' = 'email', 
 'message' = __('This field requires a valid email 
 address.')
 ],
 'unique' = [
 'rule' = 'validateUnique', 
 'provider' = 'table', 
 'message' = __('This field must be unique.')
 ]
 ])
 -validatePresence('password', 'create')
 -notEmpty('password', __('This field is required.'))
 -add('password', [
 'length' = [
 'rule' = ['minLength', 8],
 'message' = __('Password must be at least {0} 
 characters long.', 8),
 ]
 ])
 ;
 }



-- 
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/d/optout.


Re: cake3 validation rule not performed

2014-11-12 Thread José Lorenzo
If you have a _setPassword() function in your entity, that function will be 
called before validating the data. That means that the length of the 
password will be much larger than the original passed password. In those 
cases it is better to not validate using the table, but create a validator 
in the controller and validate the data that way.

On Wednesday, November 12, 2014 12:27:22 PM UTC+1, cesar calvo wrote:

 The login form is very similar to that used in the blog tutorial. 
 I can see that there is no link to the LOGIN form with associated model.
 ADD and EDIT actions perform validation over username but not over 
 password field.
 With ignore I mean that the model validation rules do not apply. 

 public function login() {
 if ($this-request-is('post')) {
 $user = $this-Auth-identify();
 if ($user) {
 $this-Auth-setUser($user);
 return $this-redirect($this-Auth-redirectUrl());
 }
 $this-Flash-error(__('Invalid username or password.'));
 }
 }

 public function add() {
 $user = $this-Users-newEntity($this-request-data);
 if ($this-request-is('post')) {
 if ($this-Users-save($user)) {
 //mail connection...
 $this-Flash-success(__('A message has been sent to your 
 email address.'));
 return $this-redirect(['action' = 'login']);
 }
 $this-Flash-error(__('Unable to save your data.'));
 }
 $this-set(compact('user'));
 }

 public function edit() {
 $user = $this-Users-get($this-Auth-user('id'));
 if ($this-request-is(['post', 'put'])) {
 $this-Users-patchEntity($user, ['password' = 
 $this-request-data('password')]);
 if ($this-Users-save($user)) {
 $this-Flash-success(__('Your data has been updated.'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to update your data.'));
 }
 $this-set(compact('user'));
 }

 //login.ctp
 ?=
 $this-Form-create(),
 $this-Form-input('username', ['label' = __('Username'), 'required' 
 = true, 'placeholder' = __('E-mail address'),]),
 $this-Form-input('password', ['label' = __('Password'), 'required' 
 = true, 'value' = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //add.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'placeholder' = __('E-mail address')]),
 $this-Form-input('password', ['label' = __('Password'), 'value' = 
 false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //edit.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 'disabled' 
 = true]),
 $this-Form-input('password', ['label' = __('Password'), 'value' = 
 false]),
 $this-Form-button(__('Submit')),
 $this-Form-end();
 ?

 El miércoles, 12 de noviembre de 2014 07:30:41 UTC-2, José Lorenzo 
 escribió:

 What do you mean with the validator ignores? What is the data that you 
 are trying to validate and what is the result?

 On Tuesday, November 11, 2014 5:03:19 PM UTC+1, cesar calvo wrote:

 Hi people, I have this validation rules in UsersTable.
 The validator ignores the -add(password, lenght) sentence.
 The issue is when I try to create or update a record.

 Best regards --cesar

 public function validationDefault(Validator $validator) {
 return $validator
 -validatePresence('username', 'create')
 -notEmpty('username', __('This field is required.'))
 -add('username', [
 'valid' = [
 'rule' = 'email', 
 'message' = __('This field requires a valid email 
 address.')
 ],
 'unique' = [
 'rule' = 'validateUnique', 
 'provider' = 'table', 
 'message' = __('This field must be unique.')
 ]
 ])
 -validatePresence('password', 'create')
 -notEmpty('password', __('This field is required.'))
 -add('password', [
 'length' = [
 'rule' = ['minLength', 8],
 'message' = __('Password must be at least {0} 
 characters long.', 8),
 ]
 ])
 ;
 }



-- 
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/d/optout.

Re: cake3 validation rule not performed

2014-11-12 Thread cesar calvo
Indeed I have _setPassword in the Entity.

protected function _setPassword($password) {
if (!empty($password)) {
return (new DefaultPasswordHasher)-hash($password);
}
return $password;
}

El miércoles, 12 de noviembre de 2014 09:56:57 UTC-2, José Lorenzo escribió:

 If you have a _setPassword() function in your entity, that function will 
 be called before validating the data. That means that the length of the 
 password will be much larger than the original passed password. In those 
 cases it is better to not validate using the table, but create a validator 
 in the controller and validate the data that way.

 On Wednesday, November 12, 2014 12:27:22 PM UTC+1, cesar calvo wrote:

 The login form is very similar to that used in the blog tutorial. 
 I can see that there is no link to the LOGIN form with associated model.
 ADD and EDIT actions perform validation over username but not over 
 password field.
 With ignore I mean that the model validation rules do not apply. 

 public function login() {
 if ($this-request-is('post')) {
 $user = $this-Auth-identify();
 if ($user) {
 $this-Auth-setUser($user);
 return $this-redirect($this-Auth-redirectUrl());
 }
 $this-Flash-error(__('Invalid username or password.'));
 }
 }

 public function add() {
 $user = $this-Users-newEntity($this-request-data);
 if ($this-request-is('post')) {
 if ($this-Users-save($user)) {
 //mail connection...
 $this-Flash-success(__('A message has been sent to your 
 email address.'));
 return $this-redirect(['action' = 'login']);
 }
 $this-Flash-error(__('Unable to save your data.'));
 }
 $this-set(compact('user'));
 }

 public function edit() {
 $user = $this-Users-get($this-Auth-user('id'));
 if ($this-request-is(['post', 'put'])) {
 $this-Users-patchEntity($user, ['password' = 
 $this-request-data('password')]);
 if ($this-Users-save($user)) {
 $this-Flash-success(__('Your data has been updated.'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to update your data.'));
 }
 $this-set(compact('user'));
 }

 //login.ctp
 ?=
 $this-Form-create(),
 $this-Form-input('username', ['label' = __('Username'), 'required' 
 = true, 'placeholder' = __('E-mail address'),]),
 $this-Form-input('password', ['label' = __('Password'), 'required' 
 = true, 'value' = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //add.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'placeholder' = __('E-mail address')]),
 $this-Form-input('password', ['label' = __('Password'), 'value' = 
 false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //edit.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 'disabled' 
 = true]),
 $this-Form-input('password', ['label' = __('Password'), 'value' = 
 false]),
 $this-Form-button(__('Submit')),
 $this-Form-end();
 ?

 El miércoles, 12 de noviembre de 2014 07:30:41 UTC-2, José Lorenzo 
 escribió:

 What do you mean with the validator ignores? What is the data that you 
 are trying to validate and what is the result?

 On Tuesday, November 11, 2014 5:03:19 PM UTC+1, cesar calvo wrote:

 Hi people, I have this validation rules in UsersTable.
 The validator ignores the -add(password, lenght) sentence.
 The issue is when I try to create or update a record.

 Best regards --cesar

 public function validationDefault(Validator $validator) {
 return $validator
 -validatePresence('username', 'create')
 -notEmpty('username', __('This field is required.'))
 -add('username', [
 'valid' = [
 'rule' = 'email', 
 'message' = __('This field requires a valid email 
 address.')
 ],
 'unique' = [
 'rule' = 'validateUnique', 
 'provider' = 'table', 
 'message' = __('This field must be unique.')
 ]
 ])
 -validatePresence('password', 'create')
 -notEmpty('password', __('This field is required.'))
 -add('password', [
 'length' = [
 'rule' = ['minLength', 8],
 'message' = __('Password must be at least {0} 
 characters long.', 8),
 ]
 ])
 ;
 }



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

Re: cake3 validation rule not performed

2014-11-12 Thread José Lorenzo
Then use a validator in the controller instead of validating how data looks 
like in the table. Validation in the table is meant for data integrity, not 
so much how data looks like.

On Wednesday, November 12, 2014 1:06:25 PM UTC+1, cesar calvo wrote:

 Indeed I have _setPassword in the Entity.

 protected function _setPassword($password) {
 if (!empty($password)) {
 return (new DefaultPasswordHasher)-hash($password);
 }
 return $password;
 }

 El miércoles, 12 de noviembre de 2014 09:56:57 UTC-2, José Lorenzo 
 escribió:

 If you have a _setPassword() function in your entity, that function will 
 be called before validating the data. That means that the length of the 
 password will be much larger than the original passed password. In those 
 cases it is better to not validate using the table, but create a validator 
 in the controller and validate the data that way.

 On Wednesday, November 12, 2014 12:27:22 PM UTC+1, cesar calvo wrote:

 The login form is very similar to that used in the blog tutorial. 
 I can see that there is no link to the LOGIN form with associated model.
 ADD and EDIT actions perform validation over username but not over 
 password field.
 With ignore I mean that the model validation rules do not apply. 

 public function login() {
 if ($this-request-is('post')) {
 $user = $this-Auth-identify();
 if ($user) {
 $this-Auth-setUser($user);
 return $this-redirect($this-Auth-redirectUrl());
 }
 $this-Flash-error(__('Invalid username or password.'));
 }
 }

 public function add() {
 $user = $this-Users-newEntity($this-request-data);
 if ($this-request-is('post')) {
 if ($this-Users-save($user)) {
 //mail connection...
 $this-Flash-success(__('A message has been sent to 
 your email address.'));
 return $this-redirect(['action' = 'login']);
 }
 $this-Flash-error(__('Unable to save your data.'));
 }
 $this-set(compact('user'));
 }

 public function edit() {
 $user = $this-Users-get($this-Auth-user('id'));
 if ($this-request-is(['post', 'put'])) {
 $this-Users-patchEntity($user, ['password' = 
 $this-request-data('password')]);
 if ($this-Users-save($user)) {
 $this-Flash-success(__('Your data has been updated.'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to update your data.'));
 }
 $this-set(compact('user'));
 }

 //login.ctp
 ?=
 $this-Form-create(),
 $this-Form-input('username', ['label' = __('Username'), 
 'required' = true, 'placeholder' = __('E-mail address'),]),
 $this-Form-input('password', ['label' = __('Password'), 
 'required' = true, 'value' = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //add.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'placeholder' = __('E-mail address')]),
 $this-Form-input('password', ['label' = __('Password'), 'value' 
 = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //edit.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'disabled' = true]),
 $this-Form-input('password', ['label' = __('Password'), 'value' 
 = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end();
 ?

 El miércoles, 12 de noviembre de 2014 07:30:41 UTC-2, José Lorenzo 
 escribió:

 What do you mean with the validator ignores? What is the data that 
 you are trying to validate and what is the result?

 On Tuesday, November 11, 2014 5:03:19 PM UTC+1, cesar calvo wrote:

 Hi people, I have this validation rules in UsersTable.
 The validator ignores the -add(password, lenght) sentence.
 The issue is when I try to create or update a record.

 Best regards --cesar

 public function validationDefault(Validator $validator) {
 return $validator
 -validatePresence('username', 'create')
 -notEmpty('username', __('This field is required.'))
 -add('username', [
 'valid' = [
 'rule' = 'email', 
 'message' = __('This field requires a valid email 
 address.')
 ],
 'unique' = [
 'rule' = 'validateUnique', 
 'provider' = 'table', 
 'message' = __('This field must be unique.')
 ]
 ])
 -validatePresence('password', 'create')
 -notEmpty('password', __('This field is required.'))
 -add('password', [
 'length' = [
 'rule' = ['minLength', 8],
 'message' = __('Password must be at least {0} 
 

Re: cake3 validation rule not performed

2014-11-12 Thread cesar calvo
Perhaps reusable validators 
http://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-reusable-validators
 
is one solution.

Why username in login form not validates email rule? Presence and notEmpty 
are validates and show related message but email rule is not applied!. I 
think this only work on create or update context.

//model
return $validator
-validatePresence('username')
-notEmpty('username', __('This field is required.'))
-add('username', [
'valid' = [
'rule' = 'email', 
'message' = __('This field requires a valid email 
address.')
]
]);

//controller
if ($this-request-is('post')) {
$user = $this-Auth-identify();
if ($user) {
$this-Auth-setUser($user);
return $this-redirect($this-Auth-redirectUrl());
}
$this-Flash-error(__('Invalid username or password.'));
}
$this-set('user', $this-Users-newEntity());

//view
$this-Form-create($user),
$this-Form-input('username', ['label' = __('Username'), 
'placeholder' = __('E-mail address'),]),
$this-Form-input('password', ['label' = __('Password'), 'value' = 
false]),
$this-Form-button(__('Submit')),
$this-Form-end()

El miércoles, 12 de noviembre de 2014 11:23:59 UTC-2, José Lorenzo escribió:

 Then use a validator in the controller instead of validating how data 
 looks like in the table. Validation in the table is meant for data 
 integrity, not so much how data looks like.

 On Wednesday, November 12, 2014 1:06:25 PM UTC+1, cesar calvo wrote:

 Indeed I have _setPassword in the Entity.

 protected function _setPassword($password) {
 if (!empty($password)) {
 return (new DefaultPasswordHasher)-hash($password);
 }
 return $password;
 }

 El miércoles, 12 de noviembre de 2014 09:56:57 UTC-2, José Lorenzo 
 escribió:

 If you have a _setPassword() function in your entity, that function will 
 be called before validating the data. That means that the length of the 
 password will be much larger than the original passed password. In those 
 cases it is better to not validate using the table, but create a validator 
 in the controller and validate the data that way.

 On Wednesday, November 12, 2014 12:27:22 PM UTC+1, cesar calvo wrote:

 The login form is very similar to that used in the blog tutorial. 
 I can see that there is no link to the LOGIN form with associated model.
 ADD and EDIT actions perform validation over username but not over 
 password field.
 With ignore I mean that the model validation rules do not apply. 

 public function login() {
 if ($this-request-is('post')) {
 $user = $this-Auth-identify();
 if ($user) {
 $this-Auth-setUser($user);
 return $this-redirect($this-Auth-redirectUrl());
 }
 $this-Flash-error(__('Invalid username or password.'));
 }
 }

 public function add() {
 $user = $this-Users-newEntity($this-request-data);
 if ($this-request-is('post')) {
 if ($this-Users-save($user)) {
 //mail connection...
 $this-Flash-success(__('A message has been sent to 
 your email address.'));
 return $this-redirect(['action' = 'login']);
 }
 $this-Flash-error(__('Unable to save your data.'));
 }
 $this-set(compact('user'));
 }

 public function edit() {
 $user = $this-Users-get($this-Auth-user('id'));
 if ($this-request-is(['post', 'put'])) {
 $this-Users-patchEntity($user, ['password' = 
 $this-request-data('password')]);
 if ($this-Users-save($user)) {
 $this-Flash-success(__('Your data has been 
 updated.'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to update your data.'));
 }
 $this-set(compact('user'));
 }

 //login.ctp
 ?=
 $this-Form-create(),
 $this-Form-input('username', ['label' = __('Username'), 
 'required' = true, 'placeholder' = __('E-mail address'),]),
 $this-Form-input('password', ['label' = __('Password'), 
 'required' = true, 'value' = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //add.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'placeholder' = __('E-mail address')]),
 $this-Form-input('password', ['label' = __('Password'), 'value' 
 = false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()
 ?

 //edit.ctp
 ?=
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'disabled' = true]),
 $this-Form-input('password', ['label' = __('Password'), 'value' 
 = false]),
 $this-Form-button(__('Submit')),
 

Re: cake3 validation rule not performed

2014-11-12 Thread cesar calvo
SOLVED!!!, Thanks José Lorenzo

public function login() {
if ($this-request-is('post')) {
$user = $this-Users-newEntity($this-request-data);
if ($this-Users-validate($user)) {
$auth = $this-Auth-identify();
if ($auth) {
$this-Auth-setUser($auth);
return $this-redirect($this-Auth-redirectUrl());
}
$this-Flash-error(__('Invalid username or password.'));
}
$this-Flash-error(__('Please correct the errors below.'));
}
$this-set(compact('user'));
}



El miércoles, 12 de noviembre de 2014 12:13:25 UTC-2, cesar calvo escribió:

 Perhaps reusable validators 
 http://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-reusable-validators
  
 is one solution.

 Why username in login form not validates email rule? Presence and notEmpty 
 are validates and show related message but email rule is not applied!. I 
 think this only work on create or update context.

 //model
 return $validator
 -validatePresence('username')
 -notEmpty('username', __('This field is required.'))
 -add('username', [
 'valid' = [
 'rule' = 'email', 
 'message' = __('This field requires a valid email 
 address.')
 ]
 ]);

 //controller
 if ($this-request-is('post')) {
 $user = $this-Auth-identify();
 if ($user) {
 $this-Auth-setUser($user);
 return $this-redirect($this-Auth-redirectUrl());
 }
 $this-Flash-error(__('Invalid username or password.'));
 }
 $this-set('user', $this-Users-newEntity());

 //view
 $this-Form-create($user),
 $this-Form-input('username', ['label' = __('Username'), 
 'placeholder' = __('E-mail address'),]),
 $this-Form-input('password', ['label' = __('Password'), 'value' = 
 false]),
 $this-Form-button(__('Submit')),
 $this-Form-end()

 El miércoles, 12 de noviembre de 2014 11:23:59 UTC-2, José Lorenzo 
 escribió:

 Then use a validator in the controller instead of validating how data 
 looks like in the table. Validation in the table is meant for data 
 integrity, not so much how data looks like.

 On Wednesday, November 12, 2014 1:06:25 PM UTC+1, cesar calvo wrote:

 Indeed I have _setPassword in the Entity.

 protected function _setPassword($password) {
 if (!empty($password)) {
 return (new DefaultPasswordHasher)-hash($password);
 }
 return $password;
 }

 El miércoles, 12 de noviembre de 2014 09:56:57 UTC-2, José Lorenzo 
 escribió:

 If you have a _setPassword() function in your entity, that function 
 will be called before validating the data. That means that the length of 
 the password will be much larger than the original passed password. In 
 those cases it is better to not validate using the table, but create a 
 validator in the controller and validate the data that way.

 On Wednesday, November 12, 2014 12:27:22 PM UTC+1, cesar calvo wrote:

 The login form is very similar to that used in the blog tutorial. 
 I can see that there is no link to the LOGIN form with associated 
 model.
 ADD and EDIT actions perform validation over username but not over 
 password field.
 With ignore I mean that the model validation rules do not apply. 

 public function login() {
 if ($this-request-is('post')) {
 $user = $this-Auth-identify();
 if ($user) {
 $this-Auth-setUser($user);
 return $this-redirect($this-Auth-redirectUrl());
 }
 $this-Flash-error(__('Invalid username or password.'));
 }
 }

 public function add() {
 $user = $this-Users-newEntity($this-request-data);
 if ($this-request-is('post')) {
 if ($this-Users-save($user)) {
 //mail connection...
 $this-Flash-success(__('A message has been sent to 
 your email address.'));
 return $this-redirect(['action' = 'login']);
 }
 $this-Flash-error(__('Unable to save your data.'));
 }
 $this-set(compact('user'));
 }

 public function edit() {
 $user = $this-Users-get($this-Auth-user('id'));
 if ($this-request-is(['post', 'put'])) {
 $this-Users-patchEntity($user, ['password' = 
 $this-request-data('password')]);
 if ($this-Users-save($user)) {
 $this-Flash-success(__('Your data has been 
 updated.'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to update your data.'));
 }
 $this-set(compact('user'));
 }

 //login.ctp
 ?=
 $this-Form-create(),
 $this-Form-input('username', ['label' = __('Username'), 
 'required' = true, 'placeholder' = 

cake3 validation rule not performed

2014-11-11 Thread cesar calvo
Hi people, I have this validation rules in UsersTable.
The validator ignores the -add(password, lenght) sentence.
The issue is when I try to create or update a record.

Best regards --cesar

public function validationDefault(Validator $validator) {
return $validator
-validatePresence('username', 'create')
-notEmpty('username', __('This field is required.'))
-add('username', [
'valid' = [
'rule' = 'email', 
'message' = __('This field requires a valid email 
address.')
],
'unique' = [
'rule' = 'validateUnique', 
'provider' = 'table', 
'message' = __('This field must be unique.')
]
])
-validatePresence('password', 'create')
-notEmpty('password', __('This field is required.'))
-add('password', [
'length' = [
'rule' = ['minLength', 8],
'message' = __('Password must be at least {0} 
characters long.', 8),
]
])
;
}

-- 
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/d/optout.


Model validation rule in cake1.3

2013-04-20 Thread Chris
Hi guys,... 
is there a way to validate rule, NOT to submit if string consist , 
script, javascript etc,... 
here is my code: 

  'name' = array(
  'rule' = '/^\w+||script|java|javascript|$/',
  'required' = false,
  'allowEmpty' = false,
  'message' = 'forbidden entry',
), 

thanks in advance 
chris 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Cakephp validation rule fires on update, even with on='create' specified

2012-12-01 Thread Marius
Hi, 
I have an issue with a validation rule being fired on update, although I've 
specified on=create for it, you can see the whole description of the 
problem at 
http://stackoverflow.com/questions/13656055/cakephp-validation-rule-fires-on-update-even-with-on-create-specified
  

Anyone knows the solution for this?
Thanks in advance!

-- 
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 post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Force validation rule to run with empty fields in data set

2012-06-08 Thread Michael Gaiser
So I need to check that at least one field out of four is being set before
I will allow to save. The validation rule works great as long as you have
something sent to it, but since all the option fields have an empty slot,
it would be easy to pass an array with all the right bits of info for that
table except for one of the four ids. Since none of the four had data sent
to them, their validation rule never gets called and it allows it to save.
Any ideas how to get around this? I have tried to play around with the
'required' flag, but it really doesn't seem to be what I am really looking
for since it would require all four to be set before allowing it to save.
Any ideas? Thanks in advance.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Force validation rule to run with empty fields in data set

2012-06-08 Thread veganista
I have done this before in (1.3) but it wasn't a pretty solution.

If your using 2.2 you might want to take a look at this: 
http://book.cakephp.org/2.0/en/models/data-validation.html#dynamically-change-validation-rules

You could use that in the beforeValidate() callback of the model and choose 
what validation rules to add based on the data supplied.


On Friday, June 8, 2012 10:13:31 AM UTC+2, Michael wrote:

 So I need to check that at least one field out of four is being set before 
 I will allow to save. The validation rule works great as long as you have 
 something sent to it, but since all the option fields have an empty slot, 
 it would be easy to pass an array with all the right bits of info for that 
 table except for one of the four ids. Since none of the four had data sent 
 to them, their validation rule never gets called and it allows it to save. 
 Any ideas how to get around this? I have tried to play around with the 
 'required' flag, but it really doesn't seem to be what I am really looking 
 for since it would require all four to be set before allowing it to save. 
 Any ideas? Thanks in advance.


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Force validation rule to run with empty fields in data set

2012-06-08 Thread Michael Gaiser
I have added the validation rule already to the model and it works when
there is data supplied to it, but I still need a way to force it to run the
rule even if $this-request-data is empty when saving. I need to be able
to tell it to run the rule because even if that field is empty, there might
be another one that has the data. How do you get a rule to run even if the
field its attached to doesnt have any data? How do you detect that out of
the 4 possible links, none were selected to be saved?

On Fri, Jun 8, 2012 at 4:19 PM, veganista l...@nanothree.net wrote:

 I have done this before in (1.3) but it wasn't a pretty solution.

 If your using 2.2 you might want to take a look at this:
 http://book.cakephp.org/2.0/en/models/data-validation.html#dynamically-change-validation-rules

 You could use that in the beforeValidate() callback of the model and
 choose what validation rules to add based on the data supplied.



 On Friday, June 8, 2012 10:13:31 AM UTC+2, Michael wrote:

 So I need to check that at least one field out of four is being set
 before I will allow to save. The validation rule works great as long as you
 have something sent to it, but since all the option fields have an empty
 slot, it would be easy to pass an array with all the right bits of info for
 that table except for one of the four ids. Since none of the four had data
 sent to them, their validation rule never gets called and it allows it to
 save. Any ideas how to get around this? I have tried to play around with
 the 'required' flag, but it really doesn't seem to be what I am really
 looking for since it would require all four to be set before allowing it to
 save. Any ideas? Thanks in advance.

  --
 Our newest site for the community: CakePHP Video Tutorials
 http://tv.cakephp.org
 Check out the new CakePHP Questions site http://ask.cakephp.org and help
 others with their CakePHP related questions.


 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


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Force validation rule to run with empty fields in data set

2012-06-08 Thread Liam Linacre
I'm pretty sure i know what you are trying to do (in my application an
address model requires one of: flat_number, house_number or house_name).

In your before filter you can add and remove the validation rules based on
what data is available. Can you do a var_dump() of $this-request-data
that'll help me show you what i mean.

On Fri, Jun 8, 2012 at 10:58 PM, Michael Gaiser mjgai...@gmail.com wrote:

 I have added the validation rule already to the model and it works when
 there is data supplied to it, but I still need a way to force it to run the
 rule even if $this-request-data is empty when saving. I need to be able
 to tell it to run the rule because even if that field is empty, there might
 be another one that has the data. How do you get a rule to run even if the
 field its attached to doesnt have any data? How do you detect that out of
 the 4 possible links, none were selected to be saved?

 On Fri, Jun 8, 2012 at 4:19 PM, veganista l...@nanothree.net wrote:

 I have done this before in (1.3) but it wasn't a pretty solution.

 If your using 2.2 you might want to take a look at this:
 http://book.cakephp.org/2.0/en/models/data-validation.html#dynamically-change-validation-rules

 You could use that in the beforeValidate() callback of the model and
 choose what validation rules to add based on the data supplied.



 On Friday, June 8, 2012 10:13:31 AM UTC+2, Michael wrote:

 So I need to check that at least one field out of four is being set
 before I will allow to save. The validation rule works great as long as you
 have something sent to it, but since all the option fields have an empty
 slot, it would be easy to pass an array with all the right bits of info for
 that table except for one of the four ids. Since none of the four had data
 sent to them, their validation rule never gets called and it allows it to
 save. Any ideas how to get around this? I have tried to play around with
 the 'required' flag, but it really doesn't seem to be what I am really
 looking for since it would require all four to be set before allowing it to
 save. Any ideas? Thanks in advance.

  --
 Our newest site for the community: CakePHP Video Tutorials
 http://tv.cakephp.org
 Check out the new CakePHP Questions site http://ask.cakephp.org and help
 others with their CakePHP related questions.


 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


  --
 Our newest site for the community: CakePHP Video Tutorials
 http://tv.cakephp.org
 Check out the new CakePHP Questions site http://ask.cakephp.org and help
 others with their CakePHP related questions.


 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


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Force validation rule to run with empty fields in data set

2012-06-08 Thread Michael Gaiser
Its not in front of me at the moment, but I can mock up what I mean.

array(
  'Domain' = array(
'name' = 'Foo',
'parent_id' = '85'
  ),
  'Owner' = array(
'color' = '#123456',
'clan_id' = '32'
  )
)
This would be valid since clan_id (character_id, coterie_id  covenant_id
being the other valid choices) is set. My code handles this properly.


array(
  'Domain' = array(
'name' = 'Foo',
'parent_id' = '85'
  ),
  'Owner' = array(
'color' = '#123456',
'clan_id' = '32',
'character_id' = '71'
  )
)
This would fail because the Owner object has both a character and a clan
assigned to it and it can only have one for my purposes. My code also
handles this situation properly.


array(
  'Domain' = array(
'name' = 'Foo',
'parent_id' = '85'
  ),
  'Owner' = array(
'color' = '#123456'
  )
)
This should fail because I need atleast one of the four link id's to be
present, but because none of the 4 field id's isn't present in the dataset,
the rule isn't run. Normally you would just tell the field that its
required which would force it to throw an error if its empty, but being
empty isnt an issue if one of the other fields has data.

I can add and subtract rules from what I read in that docs, but they still
will not run if there isnt any data to trigger them.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


validation rule help

2011-12-12 Thread elogic
Hi All,

I have a database listing of properties down the page. Each property
row has a date selector and a time selector. I need to somehow
validate that if one of the dates is selected the time must be
selected before the bulk save can happen, if neither are selected it
cane be left blank and addressed later.

Any ideas how I can go about validating this?

The file names are as follows:

DATE - data[Property][777][entry_date]
TIME - data[Property][777][entry_time]

NOTE: 777 is the property ID.


Thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Best way to disable a specific validation rule

2011-06-30 Thread chris
I have a certain validation rule that I don't want to apply in one
particular cirumstance.
The rule is based on allowing a user to create something, if they are
the 'owner' of an assoicated model.

The rule works fine most of the time, but I want to override it for a
certain usertype. This user type has its own set of actions defined by
routes.

So, to disable the particular rule, I am doing this, in the action
'usertype_add'

unset($this-Model-validate['other_model_id']['userOwnsModel']);

Where userOwnsModel is a custom validation rule I have setup in the
model.

This seems to work fine, but feels a bit 'hacky'.

Is this an accepted soution in cakePHP, or are there any better ways
to handle this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Best way to disable a specific validation rule

2011-06-30 Thread scs
I'm pretty sure that's how it is described in the cake cookbook to do
it.




On Jun 30, 9:56 am, chris chris@internetlogistics.com wrote:
 I have a certain validation rule that I don't want to apply in one
 particular cirumstance.
 The rule is based on allowing a user to create something, if they are
 the 'owner' of an assoicated model.

 The rule works fine most of the time, but I want to override it for a
 certain usertype. This user type has its own set of actions defined by
 routes.

 So, to disable the particular rule, I am doing this, in the action
 'usertype_add'

 unset($this-Model-validate['other_model_id']['userOwnsModel']);

 Where userOwnsModel is a custom validation rule I have setup in the
 model.

 This seems to work fine, but feels a bit 'hacky'.

 Is this an accepted soution in cakePHP, or are there any better ways
 to handle this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

2010-09-30 Thread psybear83
Hi everybody

I have baked the following very straight-forward model:

class Post extends AppModel {
var $name = 'Post';
var $displayField = 'name';
var $validate = array(
'name' = array(
'notempty' = array(
'rule' = array('notempty')
),
),
);
}

It only needs a value for name to be saved.

Now I've written the following 3 tests:

  function testShouldNotBeValidWithEmptyName() {
$this-Post-create(array('name' = ''));
$this-assertFalse($this-Post-validates());
  }

  function testShouldNotBeValidWithoutName() {
$this-Post-create();
$this-assertFalse($this-Post-validates()); // Fails!
  }

  function testShouldNotBeValidWithNullName() {
$this-Post-create(array('name' = null));
$this-assertFalse($this-Post-validates());
  }

I expect all three of them to work, but the 2nd one fails! So why does
it validate when there truly is no value for the name field? Is this
really the way it should be, or is it a bug?

I'm on version 1.3.4.

Thanks for help
Josh

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: CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

2010-09-30 Thread euromark
actually it is NOT a bug
although many are not aware of that behavior :)

you need to make sure that the field is passed to the validation
otherwise it will be ignored

@see http://www.dereuromark.de/2010/09/21/saving-model-data-and-security/


On 30 Sep., 14:52, psybear83 psybea...@gmail.com wrote:
 Hi everybody

 I have baked the following very straight-forward model:

 class Post extends AppModel {
         var $name = 'Post';
         var $displayField = 'name';
         var $validate = array(
                 'name' = array(
                         'notempty' = array(
                                 'rule' = array('notempty')
                         ),
                 ),
         );

 }

 It only needs a value for name to be saved.

 Now I've written the following 3 tests:

   function testShouldNotBeValidWithEmptyName() {
     $this-Post-create(array('name' = ''));
     $this-assertFalse($this-Post-validates());
   }

   function testShouldNotBeValidWithoutName() {
     $this-Post-create();
     $this-assertFalse($this-Post-validates()); // Fails!
   }

   function testShouldNotBeValidWithNullName() {
     $this-Post-create(array('name' = null));
     $this-assertFalse($this-Post-validates());
   }

 I expect all three of them to work, but the 2nd one fails! So why does
 it validate when there truly is no value for the name field? Is this
 really the way it should be, or is it a bug?

 I'm on version 1.3.4.

 Thanks for help
 Josh

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: CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

2010-09-30 Thread Joshua Muheim
Thanks Euromark for your good hint. I certainly should read through
your blogs in the near future...

But do you know why CakePHP handles stuff this way? Looks very, very
unintuitive to me. With Ruby on Rails I had much better experiences
about stuff like this a few years ago (everything just seemed to work
the way I expected it although I didn't have much experience with it
then), and I'm sure today they even have progressed much farer...

It seems a bit sad to me that CakePHP clearly doesn't seem to be able
to come even close to the experience of RoR. Any yes, I know CakePHP
isn't RoR, and yes, I could switch (well actually, I can't)... Just my
2 c€nts...

On Thu, Sep 30, 2010 at 2:58 PM, euromark dereurom...@googlemail.com wrote:
 actually it is NOT a bug
 although many are not aware of that behavior :)

 you need to make sure that the field is passed to the validation
 otherwise it will be ignored

 @see http://www.dereuromark.de/2010/09/21/saving-model-data-and-security/


 On 30 Sep., 14:52, psybear83 psybea...@gmail.com wrote:
 Hi everybody

 I have baked the following very straight-forward model:

 class Post extends AppModel {
         var $name = 'Post';
         var $displayField = 'name';
         var $validate = array(
                 'name' = array(
                         'notempty' = array(
                                 'rule' = array('notempty')
                         ),
                 ),
         );

 }

 It only needs a value for name to be saved.

 Now I've written the following 3 tests:

   function testShouldNotBeValidWithEmptyName() {
     $this-Post-create(array('name' = ''));
     $this-assertFalse($this-Post-validates());
   }

   function testShouldNotBeValidWithoutName() {
     $this-Post-create();
     $this-assertFalse($this-Post-validates()); // Fails!
   }

   function testShouldNotBeValidWithNullName() {
     $this-Post-create(array('name' = null));
     $this-assertFalse($this-Post-validates());
   }

 I expect all three of them to work, but the 2nd one fails! So why does
 it validate when there truly is no value for the name field? Is this
 really the way it should be, or is it a bug?

 I'm on version 1.3.4.

 Thanks for help
 Josh

 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: CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

2010-09-30 Thread euromark
well, it is this way for rapid development
not for most secure web application :)

the second part is your job then
although i think my methods should find their way into the core
because they certainly help to achieve that.


On 30 Sep., 15:28, Joshua Muheim psybea...@gmail.com wrote:
 Thanks Euromark for your good hint. I certainly should read through
 your blogs in the near future...

 But do you know why CakePHP handles stuff this way? Looks very, very
 unintuitive to me. With Ruby on Rails I had much better experiences
 about stuff like this a few years ago (everything just seemed to work
 the way I expected it although I didn't have much experience with it
 then), and I'm sure today they even have progressed much farer...

 It seems a bit sad to me that CakePHP clearly doesn't seem to be able
 to come even close to the experience of RoR. Any yes, I know CakePHP
 isn't RoR, and yes, I could switch (well actually, I can't)... Just my
 2 c€nts...



 On Thu, Sep 30, 2010 at 2:58 PM, euromark dereurom...@googlemail.com wrote:
  actually it is NOT a bug
  although many are not aware of that behavior :)

  you need to make sure that the field is passed to the validation
  otherwise it will be ignored

  @seehttp://www.dereuromark.de/2010/09/21/saving-model-data-and-security/

  On 30 Sep., 14:52, psybear83 psybea...@gmail.com wrote:
  Hi everybody

  I have baked the following very straight-forward model:

  class Post extends AppModel {
          var $name = 'Post';
          var $displayField = 'name';
          var $validate = array(
                  'name' = array(
                          'notempty' = array(
                                  'rule' = array('notempty')
                          ),
                  ),
          );

  }

  It only needs a value for name to be saved.

  Now I've written the following 3 tests:

    function testShouldNotBeValidWithEmptyName() {
      $this-Post-create(array('name' = ''));
      $this-assertFalse($this-Post-validates());
    }

    function testShouldNotBeValidWithoutName() {
      $this-Post-create();
      $this-assertFalse($this-Post-validates()); // Fails!
    }

    function testShouldNotBeValidWithNullName() {
      $this-Post-create(array('name' = null));
      $this-assertFalse($this-Post-validates());
    }

  I expect all three of them to work, but the 2nd one fails! So why does
  it validate when there truly is no value for the name field? Is this
  really the way it should be, or is it a bug?

  I'm on version 1.3.4.

  Thanks for help
  Josh

  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: CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

2010-09-30 Thread Joshua Muheim
So rapid development sounds to me like developing without testing...
Not very promising. And it would be *much* more rapid when such basic
stuff was already taken care of, because every serious web app will
have to implement this.

On Thu, Sep 30, 2010 at 3:34 PM, euromark dereurom...@googlemail.com wrote:
 well, it is this way for rapid development
 not for most secure web application :)

 the second part is your job then
 although i think my methods should find their way into the core
 because they certainly help to achieve that.


 On 30 Sep., 15:28, Joshua Muheim psybea...@gmail.com wrote:
 Thanks Euromark for your good hint. I certainly should read through
 your blogs in the near future...

 But do you know why CakePHP handles stuff this way? Looks very, very
 unintuitive to me. With Ruby on Rails I had much better experiences
 about stuff like this a few years ago (everything just seemed to work
 the way I expected it although I didn't have much experience with it
 then), and I'm sure today they even have progressed much farer...

 It seems a bit sad to me that CakePHP clearly doesn't seem to be able
 to come even close to the experience of RoR. Any yes, I know CakePHP
 isn't RoR, and yes, I could switch (well actually, I can't)... Just my
 2 c€nts...



 On Thu, Sep 30, 2010 at 2:58 PM, euromark dereurom...@googlemail.com wrote:
  actually it is NOT a bug
  although many are not aware of that behavior :)

  you need to make sure that the field is passed to the validation
  otherwise it will be ignored

  @seehttp://www.dereuromark.de/2010/09/21/saving-model-data-and-security/

  On 30 Sep., 14:52, psybear83 psybea...@gmail.com wrote:
  Hi everybody

  I have baked the following very straight-forward model:

  class Post extends AppModel {
          var $name = 'Post';
          var $displayField = 'name';
          var $validate = array(
                  'name' = array(
                          'notempty' = array(
                                  'rule' = array('notempty')
                          ),
                  ),
          );

  }

  It only needs a value for name to be saved.

  Now I've written the following 3 tests:

    function testShouldNotBeValidWithEmptyName() {
      $this-Post-create(array('name' = ''));
      $this-assertFalse($this-Post-validates());
    }

    function testShouldNotBeValidWithoutName() {
      $this-Post-create();
      $this-assertFalse($this-Post-validates()); // Fails!
    }

    function testShouldNotBeValidWithNullName() {
      $this-Post-create(array('name' = null));
      $this-assertFalse($this-Post-validates());
    }

  I expect all three of them to work, but the 2nd one fails! So why does
  it validate when there truly is no value for the name field? Is this
  really the way it should be, or is it a bug?

  I'm on version 1.3.4.

  Thanks for help
  Josh

  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


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: CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

2010-09-30 Thread Dr. Loboto
'required' key serves not existent fields, false by default.

var $validate = array(
'name' = array(
'notempty' = array(
'rule' = array('notempty'),
'required' = true // this rule will
fail if data array do not have name key
),
),
);



On Sep 30, 7:52 pm, psybear83 psybea...@gmail.com wrote:
 Hi everybody

 I have baked the following very straight-forward model:

 class Post extends AppModel {
         var $name = 'Post';
         var $displayField = 'name';
         var $validate = array(
                 'name' = array(
                         'notempty' = array(
                                 'rule' = array('notempty')
                         ),
                 ),
         );

 }

 It only needs a value for name to be saved.

 Now I've written the following 3 tests:

   function testShouldNotBeValidWithEmptyName() {
     $this-Post-create(array('name' = ''));
     $this-assertFalse($this-Post-validates());
   }

   function testShouldNotBeValidWithoutName() {
     $this-Post-create();
     $this-assertFalse($this-Post-validates()); // Fails!
   }

   function testShouldNotBeValidWithNullName() {
     $this-Post-create(array('name' = null));
     $this-assertFalse($this-Post-validates());
   }

 I expect all three of them to work, but the 2nd one fails! So why does
 it validate when there truly is no value for the name field? Is this
 really the way it should be, or is it a bug?

 I'm on version 1.3.4.

 Thanks for help
 Josh

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: some phone validation rule problem

2010-08-05 Thread Dan Heberden
This was answered via email, but aparently google didn't get it in the
group so:

If the table is set to a numeric field (tinyint, smallint, int,
bigint) it will parse out the leading zero - the best would be a
varchar for how many characters you need. e.g. if you're storing your
numbers as 09+124-345-7890 then you want a varchar(15).

If you are storing completely numeric values and need leading zeros in
all cases, use sprintf:

$number = 91234567890;
$number = sprintf( %12d, $number); // 091234567890

$number = 191234567890; (already 12 digits long)
$number = sprintf( %12d, $number); // 191234567890

On Aug 4, 7:51 am, hoss7 hoss...@gmail.com wrote:
 @dan thank you,but i have little problem,when i want save '09' in
 table i dont have
 '09' i have '9'

 if i want user phone number dont start with 09 what i am must to do?

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


some phone validation rule problem

2010-08-04 Thread hoss7
my phone number start with 09

'mobile'=array(
'rule' = array('phone','09',null),
'message' = 'no'
)

my rule have error , what i am must to do for fix that?

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: some phone validation rule problem

2010-08-04 Thread hoss7
if i want user phone number dont start with 09 what i am must to do?

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: some phone validation rule problem

2010-08-04 Thread Dan Heberden
regex might be a better route:

'mobile' = array(
'rule' = '/^09/',
'message' = 'no
)


On Aug 4, 6:06 am, hoss7 hoss...@gmail.com wrote:
 if i want user phone number dont start with 09 what i am must to do?

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: some phone validation rule problem

2010-08-04 Thread hoss7
@dan thank you,but i have little problem,when i want save '09' in
table i dont have
'09' i have '9'

if i want user phone number dont start with 09 what i am must to do?

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


Stuck with a validation rule in secondary model

2010-07-12 Thread Ernesto
Hello.

i have 2 models

- Item hasMany Part

my Item::add() view is something like this

echo $form-input(code);
echo $form-input(description);
echo $form-input(require_length); //this is a boolean input
echo $form-input(require_width); //this is a boolean input
echo $form-input(Part.0.id);
echo $form-input(Part.0.length);
echo $form-input(Part.0.width);
echo $form-input(Part.1.id);
echo $form-input(Part.1.length);
echo $form-input(Part.1.width);
[...]

and so on

Part length should only be set if required by the item.
so i need a Part validation rule that check if in the current data
array Item::require_width is set or not.
how can i get the Item's data from Part model?

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: Stuck with a validation rule in secondary model

2010-07-12 Thread Ernesto
i solved using Classregistry::getObject(Item);

if there's any clever/lighter method let me know :P

On 12 Lug, 17:04, Ernesto e.fanz...@gmail.com wrote:
 Hello.

 i have 2 models

 - Item hasMany Part

 my Item::add() view is something like this

 echo $form-input(code);
 echo $form-input(description);
 echo $form-input(require_length); //this is a boolean input
 echo $form-input(require_width); //this is a boolean input
 echo $form-input(Part.0.id);
 echo $form-input(Part.0.length);
 echo $form-input(Part.0.width);
 echo $form-input(Part.1.id);
 echo $form-input(Part.1.length);
 echo $form-input(Part.1.width);
 [...]

 and so on

 Part length should only be set if required by the item.
 so i need a Part validation rule that check if in the current data
 array Item::require_width is set or not.
 how can i get the Item's data from Part model?

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: 'multiple' validation rule

2010-04-23 Thread WebbedIT
Thanks for that, always felt I should generate a ticket, but have
never done so before and seen so many tickets be rejected for not
being structured correctly etc that I kept putting it off.

Would have deflated me even more to go to the trouble of doing so with
test cases etc to just be told there are workarounds so we're not
resolving it at present.

However, to date I think this is my only beef with the core and the
dev team so they remain in my eyes demi-gods for producing such an
excellent open-source framework!!!

Paul

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: 'multiple' validation rule

2010-04-22 Thread Jamie
If you want the dev team's answer for why multiple validation
doesn't with with HABTM, then read the Lighthouse ticket I submitted:

http://cakephp.lighthouseapp.com/projects/42648/tickets/400-validation-of-habtm-data-needed

Mark Story basically just says this:

You can always validate join table data separately, or use
beforeSave() beforeValidate() logic to do validation on habtm data.
Moving to enhancement as while I think being able to validate habtm
associations would be nice, there are a few existing options for it.

... which I think is a bit of a cop out. But oh well.


On Apr 21, 1:50 pm, WebbedIT p...@webbedit.co.uk wrote:
 I have posted and taken part in multiple threads involving the
 'multiple' rule and eventually applied my own core hack to get it
 working.  Others have came up with alternatives that massage the data
 array so save and validation works, I think there's even something in
 the bakery about it.

 http://groups.google.com/group/cake-php/browse_thread/thread/33909430...

 http://groups.google.com/group/cake-php/browse_thread/thread/c61e95ba...

 http://groups.google.com/group/cake-php/browse_thread/thread/2191de25...

 http://groups.google.com/group/cake-php/browse_thread/thread/d899231d...

 http://bakery.cakephp.org/articles/view/quick-fix-for-habtm-validation

 Maybe this time someone from the dev team will chime in with an answer
 as to why this does not work when using the conventions?

 Paul.

 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: 'multiple' validation rule

2010-04-21 Thread cricket
On Apr 21, 12:54 am, Jeremy Burns jeremybu...@me.com wrote:
 Might it be something to do with the field name? What happens if you rename 
 it to election_office?

ElectionOffice is the model name.

I got the error msg to show up properly, though. I debugged $form-
validationErrors:

Array
(
[Election] = Array
(
[ElectionOffice] = Please select at least one Office
)

)

So, $form-error('Election.ElectionOffice') does the trick.

But it still won't save if an Office is selected but that validation
rule is present. I can't figure out how to debug what's going on when
that rule is encountered. The data comes in like:

Array
(
[ElectionOffice] = Array
(
[ElectionOffice] = Array
(
[0] = 1
[1] = 2
[2] = 3
[3] = 4
[4] = 5
)
)
[Election] = Array
(
[deadline] = 2010-04-29
)
)

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: 'multiple' validation rule

2010-04-21 Thread John Andersen
I think that Jeremy was on the right track! As the form expects a
field/column, then should the field not be named as ElectionOffice.id,
so that it points to a column in table!?
Maybe give it a try! You actually had the .id attached in your first
post!
Enjoy,
   John

On Apr 21, 8:44 pm, cricket zijn.digi...@gmail.com wrote:
 On Apr 21, 12:54 am, Jeremy Burns jeremybu...@me.com wrote:

  Might it be something to do with the field name? What happens if you rename 
  it to election_office?

 ElectionOffice is the model name.

 I got the error msg to show up properly, though. I debugged $form-

 validationErrors:

 Array
 (
     [Election] = Array
         (
             [ElectionOffice] = Please select at least one Office
         )

 )

 So, $form-error('Election.ElectionOffice') does the trick.

 But it still won't save if an Office is selected but that validation
 rule is present. I can't figure out how to debug what's going on when
 that rule is encountered. The data comes in like:

 Array
 (
     [ElectionOffice] = Array
         (
             [ElectionOffice] = Array
                 (
                     [0] = 1
                     [1] = 2
                     [2] = 3
                     [3] = 4
                     [4] = 5
                 )
         )
     [Election] = Array
         (
             [deadline] = 2010-04-29
         )
 )

 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: 'multiple' validation rule

2010-04-21 Thread cricket
On Apr 21, 1:56 pm, John Andersen j.andersen...@gmail.com wrote:
 I think that Jeremy was on the right track! As the form expects a
 field/column, then should the field not be named as ElectionOffice.id,
 so that it points to a column in table!?
 Maybe give it a try! You actually had the .id attached in your first
 post!

When I do $form-select('ElectionOffice.id', ...) validation fails. If
I then name the validation rule ''ElectionOffice.id' it also fails.
I've also tried 'Election.ElectionOffice.id' and
'ElectionOffice.ElectionOffice.id'.

Gotta love poorly documented features! I guess I'll have to stick with
doing it manually.

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: 'multiple' validation rule

2010-04-21 Thread WebbedIT
I have posted and taken part in multiple threads involving the
'multiple' rule and eventually applied my own core hack to get it
working.  Others have came up with alternatives that massage the data
array so save and validation works, I think there's even something in
the bakery about it.

http://groups.google.com/group/cake-php/browse_thread/thread/3390943040e2ded9

http://groups.google.com/group/cake-php/browse_thread/thread/c61e95ba6c2001d7

http://groups.google.com/group/cake-php/browse_thread/thread/2191de252d65beae

http://groups.google.com/group/cake-php/browse_thread/thread/d899231d9490905d

http://bakery.cakephp.org/articles/view/quick-fix-for-habtm-validation

Maybe this time someone from the dev team will chime in with an answer
as to why this does not work when using the conventions?

Paul.

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: 'multiple' validation rule

2010-04-21 Thread cricket
On Apr 21, 4:50 pm, WebbedIT p...@webbedit.co.uk wrote:
 I have posted and taken part in multiple threads involving the
 'multiple' rule and eventually applied my own core hack to get it
 working.  Others have came up with alternatives that massage the data
 array so save and validation works, I think there's even something in
 the bakery about it.

 http://groups.google.com/group/cake-php/browse_thread/thread/33909430...

 http://groups.google.com/group/cake-php/browse_thread/thread/c61e95ba...

 http://groups.google.com/group/cake-php/browse_thread/thread/2191de25...

 http://groups.google.com/group/cake-php/browse_thread/thread/d899231d...

 http://bakery.cakephp.org/articles/view/quick-fix-for-habtm-validation

 Maybe this time someone from the dev team will chime in with an answer
 as to why this does not work when using the conventions?

Thanks for the links. I read through them all, then implemented Alex's
fix. This works just fine (and I even understand what's going on--
always a bonus).

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


'multiple' validation rule

2010-04-20 Thread cricket
Cake 1.2.6

Can anyone explain how this is supposed to work? As is too often the
case, the cookbook example is very unclear. For one thing, how does
one specify which field this rule applies to?

This is what I have now (the 'ElectionOffice' rule):

class Election extends AppModel
{
var $hasMany = array('ElectionBallot');
var $hasAndBelongsToMany = array('ElectionOffice');

var $validate = array(
'deadline' = array(
'rule' = 'date',
'required' = true,
'allowEmpty' = false,
'message' = 'You must declare a deadline date.'
),
'ElectionOffice' = array(
'rule' = array('multiple', array('min' = 1)),
'required' = true,
'message' = 'Please select at least one Office'
)
);
}

ElectionsController:

public function admin_add()
{
if (!empty($this-data))
{
$this-Election-set($this-data);

if ($this-Election-save())
{
$this-flash(
'Election created',
array('action' = 'index')
);
}
}
$offices = $this-ElectionOffice-find('list');
$this-set(compact('offices'));
}

form:

?= $form-select(
'ElectionOffice.id',
$offices,
null,
array('multiple' = 'checkbox', 'checked' = true)
) ?

PS: 'checked' = true isn't working either. 'selected' didn't work and
I found a comment online saying to use 'checked'. What's the proper
param?

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: 'multiple' validation rule

2010-04-20 Thread cricket
Oh, poop! Never mind, it works now. Sorry for the noise.

On Apr 20, 11:30 pm, cricket zijn.digi...@gmail.com wrote:
 Cake 1.2.6

 Can anyone explain how this is supposed to work? As is too often the
 case, the cookbook example is very unclear. For one thing, how does
 one specify which field this rule applies to?

 This is what I have now (the 'ElectionOffice' rule):

 class Election extends AppModel
 {
         var $hasMany = array('ElectionBallot');
         var $hasAndBelongsToMany = array('ElectionOffice');

         var $validate = array(
                 'deadline' = array(
                         'rule' = 'date',
                         'required' = true,
                         'allowEmpty' = false,
                         'message' = 'You must declare a deadline date.'
                 ),
                 'ElectionOffice' = array(
                         'rule' = array('multiple', array('min' = 1)),
                         'required' = true,
                         'message' = 'Please select at least one Office'
                 )
         );

 }

 ElectionsController:

 public function admin_add()
 {
         if (!empty($this-data))
         {
                 $this-Election-set($this-data);

                 if ($this-Election-save())
                 {
                         $this-flash(
                                 'Election created',
                                 array('action' = 'index')
                         );
                 }
         }
         $offices = $this-ElectionOffice-find('list');
         $this-set(compact('offices'));

 }

 form:

 ?= $form-select(
         'ElectionOffice.id',
         $offices,
         null,
         array('multiple' = 'checkbox', 'checked' = true)
 ) ?

 PS: 'checked' = true isn't working either. 'selected' didn't work and
 I found a comment online saying to use 'checked'. What's the proper
 param?

 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: 'multiple' validation rule

2010-04-20 Thread cricket
On Apr 20, 11:33 pm, cricket zijn.digi...@gmail.com wrote:
 Oh, poop! Never mind, it works now. Sorry for the noise.


Poop, indeed. It's busted again. I had it working, but then saving
wasn't happening. Now I've got save() working, but this validation is
cocked up.

?= $form-select(
'ElectionOffice',
$offices,
null,
array('multiple' = 'checkbox', 'checked' = true)
) ?

?= $form-error('ElectionOffice') ?

Election model:
var $validate = array(
'deadline' = array(
'rule' = 'date',
'required' = true,
'allowEmpty' = false,
'message' = 'You must declare a deadline date.'
),
'ElectionOffice' = array(
'rule' = array('multiple', array('min' = 1)),
'required' = true,
'message' = 'Please select at least one Office'
)
);

If the 2nd rule is present, the save() doesn't work. Additionally, the
error message displays just the first letter, P. And I have to put
the call to $form-error() because nothing shows up, otherwise.

Criminy!

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: 'multiple' validation rule

2010-04-20 Thread Jeremy Burns
Might it be something to do with the field name? What happens if you rename it 
to election_office?

Jeremy Burns
jeremybu...@me.com
On 21 Apr 2010, at 05:47, cricket wrote:

 On Apr 20, 11:33 pm, cricket zijn.digi...@gmail.com wrote:
 Oh, poop! Never mind, it works now. Sorry for the noise.
 
 
 Poop, indeed. It's busted again. I had it working, but then saving
 wasn't happening. Now I've got save() working, but this validation is
 cocked up.
 
 ?= $form-select(
   'ElectionOffice',
   $offices,
   null,
   array('multiple' = 'checkbox', 'checked' = true)
 ) ?
 
 ?= $form-error('ElectionOffice') ?
 
 Election model:
 var $validate = array(
   'deadline' = array(
   'rule' = 'date',
   'required' = true,
   'allowEmpty' = false,
   'message' = 'You must declare a deadline date.'
   ),
   'ElectionOffice' = array(
   'rule' = array('multiple', array('min' = 1)),
   'required' = true,
   'message' = 'Please select at least one Office'
   )
 );
 
 If the 2nd rule is present, the save() doesn't work. Additionally, the
 error message displays just the first letter, P. And I have to put
 the call to $form-error() because nothing shows up, otherwise.
 
 Criminy!
 
 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: Data validation rule (between) never returns true

2010-03-25 Thread WebbedIT
Here are my user custom validation methods

function __validateConfirmPassword($field) {
  $valid = false;
  if ($this-data['User']['password'] ==
Security::hash(Configure::read('Security.salt') .
$field['password_confirm']) {
$valid = true;
  }
  return $valid;
}

function __validatePasswordLength($field, $reset = false) {
  $valid = false;
  if (strlen($this-data['User']['password_confirm']) = 8) {
$valid = true;
  }
  return $valid;
}

HTH

Paul.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Data validation rule (between) never returns true

2010-03-25 Thread WebbedIT
For reference here are the custom validation rules I use:

function __validateConfirmPassword($field) {
  $valid = false;
  if ($this-data['User']['password'] ==
Security::hash(Configure::read('Security.salt').
$field['password_confirm']) {
$valid = true;
  }
  return $valid;
}

function __validatePasswordLength($field) {
  $valid = false;
  if (strlen($this-data['User']['password_confirm']) = 8) {
$valid = true;
  }
  return $valid;
}

and my validate array:

var $validate = array(
  'user_group_id' = array('rule' = 'notEmpty'),
  'username' = array(
'isUnique' = array(
  'rule' = 'isUnique',
  'message' = 'Sorry, this username has been taken, please try
another',
  'last' = true
),
'validChars' = array(
  'rule' = '/^[a-z0-9_]{1,}$/i',
  'message' = 'Can only include letters, numbers and underscores'
)
  ),
  'password' = array(
'minLengthCreate' = array(
  'rule' = array('__validatePasswordLength'),
  'message' = 'Must be at least 8 characters long'
)
  ),
  'password_confirm' = array(
'notEmpty' = array(
  'rule' = array('notEmpty'),
  'message' = 'This field cannot be left blank',
  'on' = 'create',
  'last' = true
),
'confirm' = array(
  'rule' = array('__validateConfirmPassword'),
  'message' = 'Password confirmation does not match'
)
  )
);

Hope it's of some use to you,

Paul.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Data validation rule (between) never returns true

2010-03-24 Thread WebbedIT
most auth setups also have a password_confirm field and use that to
validate password length etc.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Data validation rule (between) never returns true

2010-03-24 Thread timstermatic
@Dr. Loboto Thanks for the answer. That does make sense to me.

@WebbedIT  It also makes sense that providing they match I can take
the confirm_password as the test for password length.

Cheers for the help.




On Mar 24, 9:13 am, WebbedIT p...@webbedit.co.uk wrote:
 most auth setups also have a password_confirm field and use that to
 validate password length etc.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Data validation rule (between) never returns true

2010-03-23 Thread timstermatic
Hi all,

Here is part of a validate array I have in a model:

  'username' = array(

'loginRule-1'=array('rule'='alphaNumeric','message'='Username
must be alphanumeric - no spaces.' ),
'loginRule-2'=array('rule' = 
array('between',5,15),'message'
= 'Username must be between 5 and 15 characters.'),
),
'email' = array('rule' = 'email','required' = true),
'password' = array(

'passwordRule-1'=array('rule'='alphaNumeric','message'='Password
must be alphanumeric - no spaces.' ),
'passwordRule-2' = array('rule' = array('between', 5,
15),'message' = 'Password must be between 5 to 15 characters' )
)

The final rule in the array passwordRule-2 always fails and returns
the message Password must be between 5 to 15 characters..

Does anyone have any pointers as to why this is happening.

TIA

Tim

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Data validation rule (between) never returns true

2010-03-23 Thread Dr. Loboto
If you use Auth password field is already hashed so it's length more
then 15 symbols.

On Mar 24, 1:39 am, timstermatic timsterma...@gmail.com wrote:
 Hi all,

 Here is part of a validate array I have in a model:

               'username' = array(
                     
 'loginRule-1'=array('rule'='alphaNumeric','message'='Username
 must be alphanumeric - no spaces.' ),
                     'loginRule-2'=array('rule' = 
 array('between',5,15),'message'
 = 'Username must be between 5 and 15 characters.'),
                 ),
                 'email' = array('rule' = 'email','required' = true),
                 'password' = array(
                         
 'passwordRule-1'=array('rule'='alphaNumeric','message'='Password
 must be alphanumeric - no spaces.' ),
                         'passwordRule-2' = array('rule' = array('between', 
 5,
 15),'message' = 'Password must be between 5 to 15 characters' )
                 )

 The final rule in the array passwordRule-2 always fails and returns
 the message Password must be between 5 to 15 characters..

 Does anyone have any pointers as to why this is happening.

 TIA

 Tim

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


tree behaviour and validation rule problem

2010-02-02 Thread emmexx
I wrote a simple model that acts as a tree behaviour.
The model has a myfield_id field that must follow these rules:
- if parent_id is empty (root) myfield_id can't be blank
- if parent_id is not empty myfield_id must be blank (children)

So I wrote a isUnique validation rule for myfield_id. And it seems to
works if I use the baked add and edit pages.

Then I created another page that uses a javascript widget (tafelTree)
to show the tree and to drag and drop around nodes.
In the controller I created a function that receives the id and the
(new) parent id of a node as a parameter. If node id 1234 with
parent_id 5432 becomes (in javascript) a children of node 8765 my
function receives 1234-8765.
I retrieve the record with:
$category = $this-Category-find('first',
   array('conditions' = array('Category.id' =1234))
);
and try to save it with:
$ret =  $this-Category-save(array('parent_id' = 8765));

This fails with a validation error for the isUnique rule.
I put a log line in the isUnique function (in cake/lib.../model.php)
to see what is the condition that creates the error and...

(
[or] = Array
(
[Category.myfield_id] =
)

[Category.id !=] = 1234
)

But this is the same condition that I found when saving that record
using the edit function (with no error).
So I don't understand why there's a validation error when the
condition is the same.

Any suggestion?

Thank you

   maxx

p.s. En passent... the childrenCount function doesn't work properly
with my data. It reports a number of nodes greater than the real
number. I verified and reordered my data but the results of the
function are still wrong.

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: tree behaviour and validation rule problem

2010-02-02 Thread John Andersen
As I can't see your full code from the moment you retrieve the
Category and until you try to save it, I can't be sure that you have
provided the Category.id at the time of saving the updated parent_id.

I just imagine that CakePHP actually may try to add a new record, in
which case the isUnique should fail.

Does this help?
Enjoy,
   John

On Feb 2, 11:09 am, emmexx emmeics...@gmail.com wrote:
 I wrote a simple model that acts as a tree behaviour.
 The model has a myfield_id field that must follow these rules:
 - if parent_id is empty (root) myfield_id can't be blank
 - if parent_id is not empty myfield_id must be blank (children)

 So I wrote a isUnique validation rule for myfield_id. And it seems to
 works if I use the baked add and edit pages.

 Then I created another page that uses a javascript widget (tafelTree)
 to show the tree and to drag and drop around nodes.
 In the controller I created a function that receives the id and the
 (new) parent id of a node as a parameter. If node id 1234 with
 parent_id 5432 becomes (in javascript) a children of node 8765 my
 function receives 1234-8765.
 I retrieve the record with:
 $category = $this-Category-find('first',
    array('conditions' = array('Category.id' =1234))
 );
 and try to save it with:
 $ret =  $this-Category-save(array('parent_id' = 8765));

 This fails with a validation error for the isUnique rule.
 I put a log line in the isUnique function (in cake/lib.../model.php)
 to see what is the condition that creates the error and...

 (
     [or] = Array
         (
             [Category.myfield_id] =
         )

     [Category.id !=] = 1234
 )

 But this is the same condition that I found when saving that record
 using the edit function (with no error).
 So I don't understand why there's a validation error when the
 condition is the same.

 Any suggestion?

 Thank you

    maxx

 p.s. En passent... the childrenCount function doesn't work properly
 with my data. It reports a number of nodes greater than the real
 number. I verified and reordered my data but the results of the
 function are still wrong.

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: tree behaviour and validation rule problem

2010-02-02 Thread emmexx

On 2 Feb, 15:45, John Andersen j.andersen...@gmail.com wrote:
 As I can't see your full code from the moment you retrieve the
 Category and until you try to save it, I can't be sure that you have
 provided the Category.id at the time of saving the updated parent_id.

 I just imagine that CakePHP actually may try to add a new record, in
 which case the isUnique should fail.

I developed my code starting from here:
http://realm3.com/articles/drag_and_drop_trees_with_cakephp
At the end of the page there's a save function and my code is almost
equal to that one.

$category = $this-Category-find('first', array('conditions' = array
(
   'Category.id' = $this_node_id)
));
$this-Category-set($category);
if (isset($category['Category']['id'])  $category['Category']
['parent_id'] !== $this_node_parent_id) {
$ret =  $this-Category-save(array('parent_id' =
$this_node_parent_id));
(the names of the variables are obvious.)

The original code used SetParent that, as you know, is deprecated
now.

I didn't use  $this-Category-id = 1234 before $this-Category-save
() because I presumed that find('first') would have the same effect
with the ActiveRecord approach. But I could be totally wrong on this.
And because, before adding the isUnique validation rule, my save
function did work.

Anyway, I just added $this-Category-id=1234; before $this-Category-
save() and the problem is still there. :-(

Thank you
maxx

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


getparentnode and custom validation rule problem

2010-01-29 Thread emmexx
I wrote a model that act as a tree (mymodel).
In mymodel.php file I coded some custom validation rule.
One of the rules is like the following:

function testmyfield($check) {
   $grandfather = $this-getparentnode($this-data['Category']
['parent_id']);
   if ($grandfather)
   {
  $condition=array('Category.id' = $grandfather['Category']
['id']);
  $ret=$this-field('afield', $condition);
  if ($ret)
 return false;
   }
   return true;
}

When this validation rule gets executed $this-data changes after
getparentnode().
Before it is an array with the values entered in the form.
After it is an array like the following:

[Category] = Array
(
[parent_id] = 23
)

[P1] = Array
(
)

(P1 is a model related to Category)

The record gets saved with some of the (required and not empty) fields
empty. :-(

I don't understand if this can be a bug or if I'm doing something
wrong or in the wrong place.

Thank you
   maxx

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: Need little help with a validation rule

2009-04-30 Thread Ernesto

Hi guys thx for the responses

@Brian
i already have the notEmptY rule on each field. But the rule will
fail is the field is not set.

@starkey
overriding model::save doesn't sound cake-ish to me... imo a custom
validation rule will be more coherent

@jstein
thx for the hint

On 30 Apr, 01:54, brian bally.z...@gmail.com wrote:
 I assumed the 'required'=true was obvious, given the parameters
 mentioned. I should have mentioned that, also.



 On Wed, Apr 29, 2009 at 6:27 PM, jstein jst...@image.dk wrote:

  On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote:
  Just use a rule (eg. notEmpty) for each of them. You'll get errors for
  whichever fields were not set.

  No, notEmpty will fail validation, if the field is present but
  empty. It will NOT fail, if the field is not set at all.

  If the field MUST be set, use 'required'=true (and still use the
  notEmpty rule, if empty values should not be allowed).

  Seehttp://book.cakephp.org/view/129/required

  I just learned the difference the hard way... ;-)

  I don't think the case when none of the fields are present can be
  handled by validation rules, but starkey has given a solution for
  this.

   Regards

     Jonathan
--~--~-~--~~~---~--~~
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: Different Validation Rule for Different Purpose?

2009-04-30 Thread starkey

You don't need to call model-validates for the login or set any
variables to dummy values.  Here is an article you should read:
http://bakery.cakephp.org/articles/view/simple-form-authentication-in-1-2-x-x


On Apr 29, 9:57 pm, yangsy...@gmail.com yangsy...@gmail.com wrote:
 Thanks for your answer. I understand the model validation is towards
 the model while not the form now.

 I still have some confusion. If at the login form, I only need to
 verify username is not null and do not contain special chars
 (alphaNumeric). What is the right way to do that in CakePHP?

 Currently, to use the existing validation infrastructure, before
 validation, I put firstname/lastname to dummy value before call $this-

 model-validates(). Is that workaround make sense?

 Best Regards,
 Yang Sun

 On Apr 30, 3:32 am, starkey starkey...@gmail.com wrote:

  I hope this answers your question:

  The validation is for the model (the database table) and not the
  form.  The error messages appear on the form which may make you think
  the validation rules are validating the data in the form... but it
  isn't.  The validation rules check the data before an insert or update
  to the table.

  Therefore, you only need the one rule to check the first/last/user
  names and the password.  When someone logs in you do a model-find()
  which doesn't go through the validation rules.

  Shawn

  On Apr 29, 4:25 am, yangsy...@gmail.com yangsy...@gmail.com wrote:

   Hi,

   I am not sure whether CakePHP suport different validation rules for
   the same model.

   My problem is to validate user.
   In the registration form, I have to validate username/password/
   firstname/lastname to be the correct value.
   But to the login form, I only need user to input username/password.

   If I specified the validation rules for the registration form in the
   user model. Then in the login form, I will always got error result
   because it is still checking rules for firstname/lastname.

   Does CakePHP provide some standard way to solve that? So I can say I
   want check 4 fields when do registration and only check 2 fields when
   do login.

   Thanks for your help.

   Best Regards,
   Yang Sun- Hide quoted text -

  - Show quoted text -
--~--~-~--~~~---~--~~
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: Need little help with a validation rule

2009-04-30 Thread Smelly Eddie

Ernesto:

I like to make custom validation methods when dealing with complex
relationships between fields.

http://edwardawebb.com/programming/php-programming/cakephp/validating-optional-fields-cakephp-dreaded-scenario

On Apr 30, 4:31 am, Ernesto e.fanz...@gmail.com wrote:
 Hi guys thx for the responses

 @Brian
 i already have the notEmptY rule on each field. But the rule will
 fail is the field is not set.

 @starkey
 overriding model::save doesn't sound cake-ish to me... imo a custom
 validation rule will be more coherent

 @jstein
 thx for the hint

 On 30 Apr, 01:54, brian bally.z...@gmail.com wrote:

  I assumed the 'required'=true was obvious, given the parameters
  mentioned. I should have mentioned that, also.

  On Wed, Apr 29, 2009 at 6:27 PM, jstein jst...@image.dk wrote:

   On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote:
   Just use a rule (eg. notEmpty) for each of them. You'll get errors for
   whichever fields were not set.

   No, notEmpty will fail validation, if the field is present but
   empty. It will NOT fail, if the field is not set at all.

   If the field MUST be set, use 'required'=true (and still use the
   notEmpty rule, if empty values should not be allowed).

   Seehttp://book.cakephp.org/view/129/required

   I just learned the difference the hard way... ;-)

   I don't think the case when none of the fields are present can be
   handled by validation rules, but starkey has given a solution for
   this.

    Regards

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



Need little help with a validation rule

2009-04-29 Thread Ernesto

Hello.

I have a model with 5 fields

model_id
parameter_A
parameter_B
parameter_C
parameter_D

if none of them are set - the model should ignore the record
if all of them are set - the model should save the record
if some of them are set -the model should return a validation error

what rule can i use?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Different Validation Rule for Different Purpose?

2009-04-29 Thread yangsy...@gmail.com

Hi,

I am not sure whether CakePHP suport different validation rules for
the same model.

My problem is to validate user.
In the registration form, I have to validate username/password/
firstname/lastname to be the correct value.
But to the login form, I only need user to input username/password.

If I specified the validation rules for the registration form in the
user model. Then in the login form, I will always got error result
because it is still checking rules for firstname/lastname.

Does CakePHP provide some standard way to solve that? So I can say I
want check 4 fields when do registration and only check 2 fields when
do login.

Thanks for your help.

Best Regards,
Yang Sun

--~--~-~--~~~---~--~~
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: Need little help with a validation rule

2009-04-29 Thread brian

Just use a rule (eg. notEmpty) for each of them. You'll get errors for
whichever fields were not set.

On Wed, Apr 29, 2009 at 9:43 AM, Ernesto e.fanz...@gmail.com wrote:

 Hello.

 I have a model with 5 fields

 model_id
 parameter_A
 parameter_B
 parameter_C
 parameter_D

 if none of them are set - the model should ignore the record
 if all of them are set - the model should save the record
 if some of them are set -the model should return a validation error

 what rule can i use?
 


--~--~-~--~~~---~--~~
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: Different Validation Rule for Different Purpose?

2009-04-29 Thread starkey

I hope this answers your question:

The validation is for the model (the database table) and not the
form.  The error messages appear on the form which may make you think
the validation rules are validating the data in the form... but it
isn't.  The validation rules check the data before an insert or update
to the table.

Therefore, you only need the one rule to check the first/last/user
names and the password.  When someone logs in you do a model-find()
which doesn't go through the validation rules.

Shawn


On Apr 29, 4:25 am, yangsy...@gmail.com yangsy...@gmail.com wrote:
 Hi,

 I am not sure whether CakePHP suport different validation rules for
 the same model.

 My problem is to validate user.
 In the registration form, I have to validate username/password/
 firstname/lastname to be the correct value.
 But to the login form, I only need user to input username/password.

 If I specified the validation rules for the registration form in the
 user model. Then in the login form, I will always got error result
 because it is still checking rules for firstname/lastname.

 Does CakePHP provide some standard way to solve that? So I can say I
 want check 4 fields when do registration and only check 2 fields when
 do login.

 Thanks for your help.

 Best Regards,
 Yang Sun
--~--~-~--~~~---~--~~
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: Need little help with a validation rule

2009-04-29 Thread starkey

In your model you can override the save() method to check if all
fields are empty.  If they are then ignore the record.  If one or more
are set then call parent::save()... using the validation rule Brian
mentioned.

On Apr 29, 9:43 am, Ernesto e.fanz...@gmail.com wrote:
 Hello.

 I have a model with 5 fields

 model_id
 parameter_A
 parameter_B
 parameter_C
 parameter_D

 if none of them are set - the model should ignore the record
 if all of them are set - the model should save the record
 if some of them are set -the model should return a validation error

 what rule can i use?
--~--~-~--~~~---~--~~
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: Need little help with a validation rule

2009-04-29 Thread jstein

On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote:
 Just use a rule (eg. notEmpty) for each of them. You'll get errors for
 whichever fields were not set.

No, notEmpty will fail validation, if the field is present but
empty. It will NOT fail, if the field is not set at all.

If the field MUST be set, use 'required'=true (and still use the
notEmpty rule, if empty values should not be allowed).

See http://book.cakephp.org/view/129/required

I just learned the difference the hard way... ;-)

I don't think the case when none of the fields are present can be
handled by validation rules, but starkey has given a solution for
this.

  Regards

Jonathan

--~--~-~--~~~---~--~~
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: Need little help with a validation rule

2009-04-29 Thread brian

I assumed the 'required'=true was obvious, given the parameters
mentioned. I should have mentioned that, also.

On Wed, Apr 29, 2009 at 6:27 PM, jstein jst...@image.dk wrote:

 On Apr 29, 6:00 pm, brian bally.z...@gmail.com wrote:
 Just use a rule (eg. notEmpty) for each of them. You'll get errors for
 whichever fields were not set.

 No, notEmpty will fail validation, if the field is present but
 empty. It will NOT fail, if the field is not set at all.

 If the field MUST be set, use 'required'=true (and still use the
 notEmpty rule, if empty values should not be allowed).

 See http://book.cakephp.org/view/129/required

 I just learned the difference the hard way... ;-)

 I don't think the case when none of the fields are present can be
 handled by validation rules, but starkey has given a solution for
 this.

  Regards

    Jonathan

 


--~--~-~--~~~---~--~~
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: Different Validation Rule for Different Purpose?

2009-04-29 Thread yangsy...@gmail.com

Thanks for your answer. I understand the model validation is towards
the model while not the form now.

I still have some confusion. If at the login form, I only need to
verify username is not null and do not contain special chars
(alphaNumeric). What is the right way to do that in CakePHP?

Currently, to use the existing validation infrastructure, before
validation, I put firstname/lastname to dummy value before call $this-
model-validates(). Is that workaround make sense?

Best Regards,
Yang Sun

On Apr 30, 3:32 am, starkey starkey...@gmail.com wrote:
 I hope this answers your question:

 The validation is for the model (the database table) and not the
 form.  The error messages appear on the form which may make you think
 the validation rules are validating the data in the form... but it
 isn't.  The validation rules check the data before an insert or update
 to the table.

 Therefore, you only need the one rule to check the first/last/user
 names and the password.  When someone logs in you do a model-find()
 which doesn't go through the validation rules.

 Shawn

 On Apr 29, 4:25 am, yangsy...@gmail.com yangsy...@gmail.com wrote:



  Hi,

  I am not sure whether CakePHP suport different validation rules for
  the same model.

  My problem is to validate user.
  In the registration form, I have to validate username/password/
  firstname/lastname to be the correct value.
  But to the login form, I only need user to input username/password.

  If I specified the validation rules for the registration form in the
  user model. Then in the login form, I will always got error result
  because it is still checking rules for firstname/lastname.

  Does CakePHP provide some standard way to solve that? So I can say I
  want check 4 fields when do registration and only check 2 fields when
  do login.

  Thanks for your help.

  Best Regards,
  Yang Sun- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
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: Error message for the extension validation rule will not display

2009-03-08 Thread ryanam1

Thanks guys...

I didn't see that missing closing parentheses,

Unfortunately the error message still did not show but I figured it
out.

In my view I added the following line:
echo $form-error('imagename');



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



Error message for the extension validation rule will not display

2009-03-05 Thread ryanam1

Hi,

I am new to CakePHP and I am having trouble getting the extension
error message to display. The error message for the email rule
displays fine when someone enters an improperly formatted email and I
tried other examples of Cake's built in validation, they all seem to
work fine except for the extension validation.  Can someone please
tell me what I am doing wrong.

Here are the validation rules in my model:
  var $validate = array(
'imageupload' = array(
'rule' = array('extension', array('gif', 'jpeg', 'png',
'jpg'),
'message' = 'Please supply a valid image.'
)
)
,
'email'=array(
'rule'='email',
'message'='Please enter a proper email'
)
);


Here is the snippet code in the Controller:
   function add(){
if (!empty($this-data)) {

if($this-Student-save($this-data)){

$this-flash('Success','/add');
}
}
}

Finally the snippet code in my view:
?PHP
echo $form-create('Student',array('type' = 'file'));
echo $form-input('email');
echo $form-file('imageupload');
echo $form-end('Add');
?

Again, the display message for the email displays correctly so I know
that the validation is working at least somewhat.  The validation for
the file upload seems to operate correctly. If I try to upload a file
with a .DOC extension the save fails except that it does not display
the error message at all.

Please help what am I doing wrong?


--~--~-~--~~~---~--~~
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: Error message for the extension validation rule will not display

2009-03-05 Thread Dr. Loboto

'message' key-value should be in 'imageupload' array, not in 'rule'
one. You messed braces.

On Mar 5, 9:49 pm, ryanam1 ryan...@gmail.com wrote:
 Hi,

 I am new to CakePHP and I am having trouble getting the extension
 error message to display. The error message for the email rule
 displays fine when someone enters an improperly formatted email and I
 tried other examples of Cake's built in validation, they all seem to
 work fine except for the extension validation.  Can someone please
 tell me what I am doing wrong.

 Here are the validation rules in my model:
   var $validate = array(
     'imageupload' = array(
         'rule' = array('extension', array('gif', 'jpeg', 'png',
 'jpg'),
         'message' = 'Please supply a valid image.'
         )
         )
         ,
 'email'=array(
 'rule'='email',
 'message'='Please enter a proper email'
         )
     );

 Here is the snippet code in the Controller:
    function add(){
         if (!empty($this-data)) {

             if($this-Student-save($this-data)){

                 $this-flash('Success','/add');
             }
         }
     }

 Finally the snippet code in my view:
 ?PHP
 echo $form-create('Student',array('type' = 'file'));
 echo $form-input('email');
 echo $form-file('imageupload');
 echo $form-end('Add');
 ?

 Again, the display message for the email displays correctly so I know
 that the validation is working at least somewhat.  The validation for
 the file upload seems to operate correctly. If I try to upload a file
 with a .DOC extension the save fails except that it does not display
 the error message at all.

 Please help what am I doing wrong?
--~--~-~--~~~---~--~~
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: Error message for the extension validation rule will not display

2009-03-05 Thread Son Dat Giang
var $validate = array(
   'imageupload' = array(
   'rule' = array('extension', array('gif', 'jpeg', 'png',
'jpg'),
   'message' = 'Please supply a valid image.'
   )
   )
   ,
'email'=array(
'rule'='email',
'message'='Please enter a proper email'
   )
   );
should be like this

var $validate = array(
 'imageupload' = array(
'rule' = array('extension', array('gif',
'jpeg', 'png', 'jpg')),
'message' = 'Please supply a valid image.'
 ),
 'email'=array(
'rule'='email',
 'message'='Please enter a proper email'
 )
);
-
Best regards !
Giang Son Dat
Mobile: +84 988114164
Email giangson...@gmail.com, giangson...@yahoo.com


On Thu, Mar 5, 2009 at 6:37 PM, Dr. Loboto drlob...@gmail.com wrote:


 'message' key-value should be in 'imageupload' array, not in 'rule'
 one. You messed braces.

 On Mar 5, 9:49 pm, ryanam1 ryan...@gmail.com wrote:
  Hi,
 
  I am new to CakePHP and I am having trouble getting the extension
  error message to display. The error message for the email rule
  displays fine when someone enters an improperly formatted email and I
  tried other examples of Cake's built in validation, they all seem to
  work fine except for the extension validation.  Can someone please
  tell me what I am doing wrong.
 
  Here are the validation rules in my model:
var $validate = array(
  'imageupload' = array(
  'rule' = array('extension', array('gif', 'jpeg', 'png',
  'jpg'),
  'message' = 'Please supply a valid image.'
  )
  )
  ,
  'email'=array(
  'rule'='email',
  'message'='Please enter a proper email'
  )
  );
 
  Here is the snippet code in the Controller:
 function add(){
  if (!empty($this-data)) {
 
  if($this-Student-save($this-data)){
 
  $this-flash('Success','/add');
  }
  }
  }
 
  Finally the snippet code in my view:
  ?PHP
  echo $form-create('Student',array('type' = 'file'));
  echo $form-input('email');
  echo $form-file('imageupload');
  echo $form-end('Add');
  ?
 
  Again, the display message for the email displays correctly so I know
  that the validation is working at least somewhat.  The validation for
  the file upload seems to operate correctly. If I try to upload a file
  with a .DOC extension the save fails except that it does not display
  the error message at all.
 
  Please help what am I doing wrong?
 


--~--~-~--~~~---~--~~
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 rule with or

2009-02-11 Thread Smelly_Eddie

Henrik:

Seems like a pretty common need doesn't it.  The solution is pretty
simple.

You call the same validation rule for every related field.

$validate=
array(
'field1'=array('rule'='dependentFields'),
'field2'=array('rule'='dependentFields')
)


Then the method

function dependenFields()
{
$return=false;

logic based on fields to do the comparison etc.

// if dependencies pass
$return=true;


//otherwise unique errors
$return=You provided your Company Name, but forgot Phone

}

and those messages ()if your logic is right) will show only under the
failing boxes.

I will post the full details in an article on my site which is not
quite complete (and I am at work right now :/).  Check back tonight
perhaps.
}

On Feb 10, 4:35 am, WebbedIT p...@webbedit.co.uk wrote:
 I do not believe there are any built-in validation rules to do this so
 you need to specify your own custom validation method such as:

 function __validateFieldDependancy($data, $field1, $field2) {
   // return false if ThisModelName.field1 and ThisModelName.field2 are
 empty
   return empty($this-data[$this-name][$field1'])  empty($this-data
 [$this-name][$field2]) ? false : true;

 }

 This would go in your model and would be called by the following
 validation rule:

 var $validate = array(
   'field_name' = array(
     'rule' = array('__validateFieldDependancy', 'fieldName1',
 'fieldName2'),
     'message' = 'Your error message'
   )
 )

 Not sure if it is neccessary to make this method private (named
 starting with double underscores) but thought it was more secure to do
 so.

 There is probably a better way to test both fields are empty ... happy
 for people to better educate me on this as I'm self-taught with PHP.

 If you are going to use this type of validation rule regularly across
 multiple models it may be worth aking it available to all models by
 placing it in /app/app_model.php

 Hope this helps,

 Paul (WebbedIT)
--~--~-~--~~~---~--~~
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 rule with or

2009-02-11 Thread WebbedIT

Sounds like a more elegant approach than mine .. look forward to the
article :)
--~--~-~--~~~---~--~~
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 rule with or

2009-02-10 Thread WebbedIT

I do not believe there are any built-in validation rules to do this so
you need to specify your own custom validation method such as:

function __validateFieldDependancy($data, $field1, $field2) {
  // return false if ThisModelName.field1 and ThisModelName.field2 are
empty
  return empty($this-data[$this-name][$field1'])  empty($this-data
[$this-name][$field2]) ? false : true;
}

This would go in your model and would be called by the following
validation rule:

var $validate = array(
  'field_name' = array(
'rule' = array('__validateFieldDependancy', 'fieldName1',
'fieldName2'),
'message' = 'Your error message'
  )
)

Not sure if it is neccessary to make this method private (named
starting with double underscores) but thought it was more secure to do
so.

There is probably a better way to test both fields are empty ... happy
for people to better educate me on this as I'm self-taught with PHP.

If you are going to use this type of validation rule regularly across
multiple models it may be worth aking it available to all models by
placing it in /app/app_model.php

Hope this helps,

Paul (WebbedIT)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Validation rule with or

2009-02-09 Thread Henrik Gemal

I have a form where you have to enter either (firstname AND
lastname AND phone) OR (companyname AND phone)

how do I make a validate rule like that?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Need help with custom validation rule atLeastOneField

2008-12-22 Thread Ernesto

hello.

i can't figure out how to code this rule.

i have a simple users table with some fields.

i need at least one field (Name or Surname)  != blank

Here's my Validate() array

$this-User-validate = array(
Name = array(
atLeastOneField = array(
rule = array(atLeastOneField,  array(Name,  
Surname))
)
),
Surname = array(
atLeastOneField = array(
rule = array(atLeastOneField,  array(Name,  
Surname))
)
),
);
--~--~-~--~~~---~--~~
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 rule works locally, but not on server

2008-12-18 Thread Smelly_Eddie

I believe this is based on the version of PHP your machines are
running. (4 vs 5)

I also think there is a submitted ticket for the issue but I have the
time to search.

Google  alphanumeric issue in Cakephp and Im sure you'll find the
details.




On Dec 17, 3:00 pm, RyOnLife ryan.mckil...@gmail.com wrote:
 This one has me completely stumped!

 The validation rule I've pasted below works fine on my local machine, but
 when I test a user registration on my server, it kicks the Letters and
 numbers only error message, even if the input is valid.

 Both local and server are running Cake 1.2.0.7692 RC3 and PHP 5.2.6.

     'username' = array(
       'alphanumeric' = array(
         'rule' = 'alphaNumeric',
         'message' = 'Letters and numbers only',
       ),
       'unique' = array(
         'rule' = 'isUnique',
         'message' = 'This username is taken'
       ),
       'between' = array(
         'rule' = array('between', 3, 15),
         'message' = 'Between 3-15 characters',
         'required' = true,
         'allowEmpty' = false        
       )      
     )

 Any ideas? Thanks.
 --
 View this message in 
 context:http://n2.nabble.com/validation-rule-works-locally%2C-but-not-on-serv...
 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 rule works locally, but not on server

2008-12-18 Thread RyOnLife

Thanks. That helped. Issued discussed here:
http://groups.google.com/group/cake-php/browse_thread/thread/0040ac0b744181d5/
I ended up using a custom validation rule.



On Dec 18, 10:26 am, Smelly_Eddie ollit...@gmail.com wrote:
 I believe this is based on the version of PHP your machines are
 running. (4 vs 5)

 I also think there is a submitted ticket for the issue but I have the
 time to search.

 Google  alphanumeric issue in Cakephp and Im sure you'll find the
 details.

 On Dec 17, 3:00 pm, RyOnLife ryan.mckil...@gmail.com wrote:

  This one has me completely stumped!

  The validation rule I've pasted below works fine on my local machine, but
  when I test a user registration on my server, it kicks the Letters and
  numbers only error message, even if the input is valid.

  Both local and server are running Cake 1.2.0.7692 RC3 and PHP 5.2.6.

      'username' = array(
        'alphanumeric' = array(
          'rule' = 'alphaNumeric',
          'message' = 'Letters and numbers only',
        ),
        'unique' = array(
          'rule' = 'isUnique',
          'message' = 'This username is taken'
        ),
        'between' = array(
          'rule' = array('between', 3, 15),
          'message' = 'Between 3-15 characters',
          'required' = true,
          'allowEmpty' = false        
        )      
      )

  Any ideas? Thanks.
  --
  View this message in 
  context:http://n2.nabble.com/validation-rule-works-locally%2C-but-not-on-serv...
  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
-~--~~~~--~~--~--~---



validation rule works locally, but not on server

2008-12-17 Thread RyOnLife


This one has me completely stumped!

The validation rule I've pasted below works fine on my local machine, but
when I test a user registration on my server, it kicks the Letters and
numbers only error message, even if the input is valid.

Both local and server are running Cake 1.2.0.7692 RC3 and PHP 5.2.6.

'username' = array(
  'alphanumeric' = array(
'rule' = 'alphaNumeric',
'message' = 'Letters and numbers only',
  ),
  'unique' = array(
'rule' = 'isUnique',
'message' = 'This username is taken'
  ),
  'between' = array(
'rule' = array('between', 3, 15),
'message' = 'Between 3-15 characters',
'required' = true,
'allowEmpty' = false
  )  
)

Any ideas? Thanks.
-- 
View this message in context: 
http://n2.nabble.com/validation-rule-works-locally%2C-but-not-on-server-tp1669513p1669513.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: multiple custom error messages for a single validation rule - is it possible ?

2008-11-24 Thread jitka (poLK)

Why not have several validation rules for one field?

var $validate = array(
'val1' = array(
'required' = array(
'rule' = VALID_NOT_EMPTY,
'required' = true,
'allowEmpty' = false,
'last' = true,
'message' = ''
),
'format' = array(
'rule' = array('val1'),
'last' = true,
'message' = 'yyy'
),
'is_unique' = array(
'rule' = array('isUnique'),
'message' = 'z'
),
.
),
.
);

If this 'generic' and proposed approach is not good for you, you can
allways (from model) call $this-invalidate('field', 'Error message'),
but keep in mind that error messages are better to keep in views, then
in models ('M' layer doesn't need to know about messages for humans,
they are supposed to live in human interface - 'V' layer of MVC app).
--~--~-~--~~~---~--~~
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: multiple custom error messages for a single validation rule - is it possible ?

2008-11-24 Thread Malcolm Krugger

Yes several rules per field was the way to go

But my custom validation would contact a remote server and then
display an error message appropriately

So I thought I would save on those remote calls if for single
validation rule I had the facility for displaying different error
messages

Also I tried $this-invalidate('field', 'Error message') in my custom
validation function but only the default error message still displays

Thanks

Malcolm

P.S as an added note can you please post an example with custom
validation where the error message is in the VIEWS and NOt in the
MODEL ?

On Nov 24, 1:50 pm, jitka (poLK) [EMAIL PROTECTED] wrote:
 Why not have several validation rules for one field?

--~--~-~--~~~---~--~~
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: multiple custom error messages for a single validation rule - is it possible ?

2008-11-24 Thread jitka (poLK)

 Yes several rules per field was the way to go

 But my custom validation would contact a remote server and then
 display an error message appropriately

 So I thought I would save on those remote calls if for single
 validation rule I had the facility for displaying different error
 messages

 Also I tried $this-invalidate('field', 'Error message') in my custom
 validation function but only the default error message still displays

If you will invalidate field val1 from inside validation method val1()
AND return false, your custom message will be overwritten with default
one, specified in your validation rule. You might want to implement
beforeValidate() callback in your model instead of validation rule,
like:

function beforeValidate() {
if (your condition) {
$this-invalidate('val1', 'Custom error message');
return false;
}

return true;
}

With this code, and
echo $form-input('val1'); // field input and error
or
echo $form-error('val1'); // field error
in view, your custom error message will be displayed.

 P.S as an added note can you please post an example with custom
 validation where the error message is in the VIEWS and NOt in the
 MODEL ?

http://book.cakephp.org/view/198/options-error
--~--~-~--~~~---~--~~
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: multiple custom error messages for a single validation rule - is it possible ?

2008-11-24 Thread jitka (poLK)


 P.S as an added note can you please post an example with custom
 validation where the error message is in the VIEWS and NOt in the
 MODEL ?

Or even better http://book.cakephp.org/view/133/Multiple-Rules-per-Field
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



multiple custom error messages for a single validation rule - is it possible ?

2008-11-23 Thread Malcolm Krugger

Say I have the following rule in my validation array in my Model

'val1' = array(
'rule' = 'val1',
'message' = 'some problem with username'
)



Now in function

function val1 ($value)

{

NOw I want to return 3 different error messages based on $value
[username]... is it possible ?

Whenever I return false I always get  'some problem with username'
 as the error message


}

Is there a facility in cakephp where I can specify multiple custom
error message for a single validation rule ??

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



Add property last = true to every validation rule

2008-11-20 Thread Ernesto

Hello i'm back again :P

My new goal is to automatically set last = true in every
validation rule of every model.

here's my actual code (that doesn't work T_T)

?php
class AppModel extends Model {
function beforeValidate() {
foreach ($this-validate as $field) {
foreach ($field as $rule) {
$rule[last] = true;
}
}
return true;
}
}
?

i can't find out where's the error
--~--~-~--~~~---~--~~
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: Add property last = true to every validation rule

2008-11-20 Thread ORCC



 ?php
 class AppModel extends Model {
 function beforeValidate() {
 foreach ($this-validate as $field) {
 foreach ($field as $rule) {
 $rule[last] = true;

It seems that your error comes from a misunderstanding of the foreach
constructor in PHP.

The foreach iteration creates a _copy_ of each element of the array
(the value returned by the each function) when iterates,  hence the
code block inside the foreach works with the copy of the array element
instead of the actual array value.

 Try using references, as is explained in the PHP Manual
foreach ($this-validate as $field) {
foreach ($field as $rule) {

}
}

And study the documentation:
http://www.php.net/foreach
http://php.net/manual/en/function.each.php


--~--~-~--~~~---~--~~
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: Add property last = true to every validation rule

2008-11-20 Thread Ernesto

u're right. now everything works :)

thank you very much

On 20 Nov, 22:31, ORCC [EMAIL PROTECTED] wrote:
  ?php
          class AppModel extends Model {
                  function beforeValidate() {
                          foreach ($this-validate as $field) {
                                  foreach ($field as $rule) {
                                          $rule[last] = true;

 It seems that your error comes from a misunderstanding of the foreach
 constructor in PHP.

 The foreach iteration creates a _copy_ of each element of the array
 (the value returned by the each function) when iterates,  hence the
 code block inside the foreach works with the copy of the array element
 instead of the actual array value.

  Try using references, as is explained in the PHP Manual
 foreach ($this-validate as $field) {
     foreach ($field as $rule) {

     }

 }

 And study the 
 documentation:http://www.php.net/foreachhttp://php.net/manual/en/function.each.php
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



validation rule help

2008-11-17 Thread ♫ killerBird

Hi  All,

I am stuck with the problem bellow :

there is one drop down which let users select different type of
submition e.g : weburl , blog comment , video comment etc.
based on the above selection i need to show some specific fields to
the user like when they select weburl i will show them one text field
named enter url while on the other hand when they select blog
comment there will be a textarea named comment description instead
of  enter url .
I have used jQuery (hiding div based on the selection) to do this in
my view . Now i want to know how do i use validation in the model to
do this ..
The validation rule is working perfectly

var $validate = array(
'contribution_url' = array(
'rule' = 'url',
'message' = 'Make sure you enter a valid URL (starts 
with http://
or https://)'
)
);

but if i just specify a validation rule for the enter url textfield
then it is automatically get called when users have selected blog
comment  or video comment (the enter url field is not even been
shown to the user).

what i want is the validation should called only when the field is
there.
is there a way to do this or using Jquery it is not possible ?
, sorry if i am asking stupid 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validation rule help

2008-11-17 Thread teknoid

probably allowEmpty=true, so when the field has no value it doesn't
trigger validation

On Nov 17, 10:33 am, ♫ killerBird [EMAIL PROTECTED] wrote:
 Hi  All,

 I am stuck with the problem bellow :

 there is one drop down which let users select different type of
 submition e.g : weburl , blog comment , video comment etc.
 based on the above selection i need to show some specific fields to
 the user like when they select weburl i will show them one text field
 named enter url while on the other hand when they select blog
 comment there will be a textarea named comment description instead
 of  enter url .
 I have used jQuery (hiding div based on the selection) to do this in
 my view . Now i want to know how do i use validation in the model to
 do this ..
 The validation rule is working perfectly

 var $validate = array(
                 'contribution_url' = array(
                         'rule' = 'url',
                         'message' = 'Make sure you enter a valid URL (starts 
 with http://
 or https://)'
                 )
         );

 but if i just specify a validation rule for the enter url textfield
 then it is automatically get called when users have selected blog
 comment  or video comment (the enter url field is not even been
 shown to the user).

 what i want is the validation should called only when the field is
 there.
 is there a way to do this or using Jquery it is not possible ?
 , sorry if i am asking stupid 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validation rule help

2008-11-17 Thread ♫ killerBird

thanks teknoid .. allowEmpty is working but when user select the
weburl type the field should not be left blank.


On Nov 17, 8:35 pm, teknoid [EMAIL PROTECTED] wrote:
 probably allowEmpty=true, so when the field has no value it doesn't
 trigger validation

 On Nov 17, 10:33 am, ♫ killerBird [EMAIL PROTECTED] wrote:

  Hi  All,

  I am stuck with the problem bellow :

  there is one drop down which let users select different type of
  submition e.g : weburl , blog comment , video comment etc.
  based on the above selection i need to show some specific fields to
  the user like when they select weburl i will show them one text field
  named enter url while on the other hand when they select blog
  comment there will be a textarea named comment description instead
  of  enter url .
  I have used jQuery (hiding div based on the selection) to do this in
  my view . Now i want to know how do i use validation in the model to
  do this ..
  The validation rule is working perfectly

  var $validate = array(
                  'contribution_url' = array(
                          'rule' = 'url',
                          'message' = 'Make sure you enter a valid URL 
  (starts with http://
  or https://)'
                  )
          );

  but if i just specify a validation rule for the enter url textfield
  then it is automatically get called when users have selected blog
  comment  or video comment (the enter url field is not even been
  shown to the user).

  what i want is the validation should called only when the field is
  there.
  is there a way to do this or using Jquery it is not possible ?
  , sorry if i am asking stupid 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Built-in validation rule to check for multiple fields?

2008-11-05 Thread si-mon

Hi all,

In my application, I need to insert records in the following pattern:
--- Source Country, Destination Country, Duration, Cost ---
In which, I need to check isUnique for the combination of Source
Country and Destination Country.
But, I only know to give isUnique for a single field in the
$validate array of the specific model.

So, my question is:
Is there any built-in validation rule to check for multiple fields?
OR
Do I need to create a custom function to resolve this 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
-~--~~~~--~~--~--~---



Help with validation rule in behaviour

2008-11-05 Thread Marcus Silva

Hi guys,

I am completely stuck and cannot figure out what I am doing wrong.

I have created a custom Upload behaviour but I cannot get the
following validation rule to work.

Just after the setup function in the behaviour I call this function
_create_validation_rule($model){} which sets the validation rules,
for my suprise nothing happens.  When I call the function from inside
the beforeValidate function it works, but Cake display the following
error:

Warning (2): preg_match() expects parameter 2 to be string, array
given [CORE\cake\libs\validation.php, line 877]

When I checked the validation.php and pr ( )  the second paramenter it
showed the file array:
Array
(
[filename] = Array
(
[name] =
[type] =
[tmp_name] =
[error] = 4
[size] = 0
)

)

I must be doing something wrong somewhere, just don't know where and
how to fix it.

Any help would very much appreciated.

Many thanks in advance.


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



Make a validation rule be valid only in a certain date

2008-09-29 Thread mig_akira


Hello!

Is there a way to make a validation rule be applied only within a certain
date? For examplo, in 10/10/2008 the rule will be used, but next day,
10/11/2008, the rule will not be used. The way I need it, there are two
rules, one of them would be used for two days, and the other one will be
used for only one day, and both of them starts at the same day.

The rule is simple, just an 'equalTO' with a warning message. 

For example, in day 1, if the string submited in a form is equalTo
whatever or to wherever, then the rule will be applied. In day 2, the
rule will be applied only to wherever. And in day 3, no rule will be
applied. 

Thanks!
-- 
View this message in context: 
http://www.nabble.com/Make-a-validation-rule-be-valid-only-in-a-certain-date-tp19727816p19727816.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Model Validation Rule Builder

2008-07-04 Thread Eric

I created a new way of creating validation rules for models, which I
think is kind of slick, but I don't really think the way I have it
working is very cake-like and I need some advice on how best it
should be implemented.

Right now in a model I am doing the following to add my RuleBuilder

?php
require_once('validation/RuleBuilder.php');

class Company extends AppModel{
...
var $validate = array()
...
function beforeValidate()
{
$field_name = new ValidationField('name');
$field_name-addRule(new AlphaNumSpaceRule(true, false));

$field_contactName = new ValidationField('contact_name');
$field_contactName-addRule(new AlphaNumSpaceRule(true, false));

$field_phoneNumber = new ValidationField('contact_number');
$field_phoneNumber-addRule(new PhoneNumberRule());

$this-validate = array_merge($field_name-
getFieldAsArray(),
  
$field_contactName-getFieldAsArray(),
  
$field_phoneNumber-getFieldAsArray());
}

What the code is doing is really just building the validates array by
using the builder design pattern. The good part is that adding
validation rules to your model is easy, it is simple to add multiple
validation rules to a field, and any custom validation rules (i.e. the
AlphaNumSpaceRule) you create are shared among all of the models.

My question is, should I be using a behavior, or is it ok, from a cake
perspective, to just go with my current implementation?

BTW, I think I can use $array1 += $array2 etc... instead of
array_merge which should help performance but I have not tried it yet.

Thanks in advance!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



A simple validation rule not working correctly

2008-01-30 Thread Reny

Hi all,
I'm using the last beta release and I have this problem:
I have in my model that validation rules

var $validate = array(
'password' = array(
'alphanumeric'  = array(
'rule'  = 'alphanumeric',
'message'   = 'Only alphanumeric 
allowed',
),
'required'  = array(
'rule'  = 
VALID_NOT_EMPTY,
'message'   = 'This field 
cannot be
empty',
)
)
);

why if I submit form with empty field it's pass validation
why if I pass non alphanum ie \  it's pass validation

I have really no idea :(.

Thanks all.

--~--~-~--~~~---~--~~
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: A simple validation rule not working correctly

2008-01-30 Thread grigri

var $validate = array(
  'password' = array(
'rule' = 'alphanumeric',
'required' = true,
'allowEmpty' = false
  )
);

'required' means that the form field must be submitted, i.e. you can't
add/update this model without specifying that field.

'allowEmpty' means that if the field is present, it must not be blank.

On Jan 30, 12:40 pm, Marcin Jaworski [EMAIL PROTECTED] wrote:
 Try this:

 var $validate = array(
 'password' = array(
 'rule' = 'alphanumeric',
 'required' = true
 )
 );

 On 30 Sty, 11:06, Reny [EMAIL PROTECTED] wrote:

  Hi all,
  I'm using the last beta release and I have this problem:
  I have in my model that validation rules

  var $validate = array(
  'password' = array(
  'alphanumeric'  = array(
  'rule'  = 'alphanumeric',
  'message'   = 'Only 
  alphanumeric allowed',
  ),
  'required'  = array(
  'rule'  = 
  VALID_NOT_EMPTY,
  'message'   = 'This 
  field cannot be
  empty',
  )
  )
  );

  why if I submit form with empty field it's pass validation
  why if I pass non alphanum ie \  it's pass validation

  I have really no idea :(.

  Thanks all.
--~--~-~--~~~---~--~~
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: A simple validation rule not working correctly

2008-01-30 Thread Marcin Jaworski

Try this:

var $validate = array(
'password' = array(
'rule' = 'alphanumeric',
'required' = true
)
);

On 30 Sty, 11:06, Reny [EMAIL PROTECTED] wrote:
 Hi all,
 I'm using the last beta release and I have this problem:
 I have in my model that validation rules

 var $validate = array(
 'password' = array(
 'alphanumeric'  = array(
 'rule'  = 'alphanumeric',
 'message'   = 'Only alphanumeric 
 allowed',
 ),
 'required'  = array(
 'rule'  = 
 VALID_NOT_EMPTY,
 'message'   = 'This 
 field cannot be
 empty',
 )
 )
 );

 why if I submit form with empty field it's pass validation
 why if I pass non alphanum ie \  it's pass validation

 I have really no idea :(.

 Thanks all.
--~--~-~--~~~---~--~~
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: A simple validation rule not working correctly

2008-01-30 Thread Reny

On 30 Gen, 13:45, grigri [EMAIL PROTECTED] wrote:
 var $validate = array(
   'password' = array(
 'rule' = 'alphanumeric',
 'required' = true,
 'allowEmpty' = false
   )
 );

ok, thanks, my password arrive in controller (and in model validation
also) not blank, beacuse, I think, I use Auth component: password
arrive in hash format.

If usefull for other I implemented this solution:

i wrote a custom validation:

MODEL:
var $validate = array(
'password' = array(
'unique' = array('rule' = 'validatePassword')),
);



function validatePassword($data) {
$valid = true;
if ($this-data['Utente']['password'] ==
Security::hash(Configure::read('Security.salt') . )) {
$valid = false;
}
return $valid;
}


For cakephp guru: if I wrong tell me :)

regards
Reny


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



Model-validates() ignores 'on'='created' option of validation rule?

2007-12-03 Thread Serge Rodovnichenko

Model validation rule (checkUnique method got from tempdocs :-) ):
=
var $validate = array(
'name' = array(
'on'='create',
'rule' = array('checkUnique'),
'message' = 'Name is not unique!',
'allowEmpty' = false,
),
=

$Model-data

data[Model][id]=3;
data[Model][name]='A name';


When I call Model-validates() in my controller, it fails (name isn't
unique), but Model-save() works fine.
--~--~-~--~~~---~--~~
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: Unexpected behaviour in 'required' validation rule (v 1.2)

2007-09-20 Thread bujanga

Here is an example of a working rule with a required condition.

var $validate = array(
'owner_id'  = array(
'number'= array(
'rule'  = array('numeric'),
'on'= 'create',
'required' = true,
'allowEmpty' = false,
'message'   = 'Owner ID must exist!'
)
)
);

On 9/19/07, Farez [EMAIL PROTECTED] wrote:

 thanks grigri. seems to be working fine for me without 'allowEmpty'.
 but the 'required' rule is still a mystery to me.



 On Sep 19, 9:40 am, grigri [EMAIL PROTECTED] wrote:
  I ran into this too - you need to add the 'allowEmpty' attribute too:
 
  'email' = array('rule'=VALID_NOT_EMPTY, 'allowEmpty' = true)
 
  On Sep 18, 1:51 pm, Farez [EMAIL PROTECTED] wrote:
 
   Hi,
 
   I'm wondering if I'm doing something wrong here (have searched docs,
   sources and archives and can't find an answer).
 
   The 'required' rule seems to be broken as it still reports an error
   even when the field is not empty. The rule I have is:
 
   'email' = array('rule'='required')
 
   I traced this to this part of the code in Model:invalidFields():
 
   if (method_exists($this, $rule)) {
   $ruleParams[] = array_diff_key($validator, $default);
   $valid = call_user_func_array(array($this, $rule), 
   $ruleParams);} elseif (method_exists($Validation, $rule)) {
 
   $valid = call_user_func_array(array($Validation, $rule),
   $ruleParams);} elseif (!is_array($validator['rule'])) {
 
   $valid = preg_match($rule, $data[$fieldName]);
 
   }
 
   where it always lands on the preg_match(...) line in the last
   condition, where it tries to preg_match() $rule which has a value of
   'required', against the data field.
 
   Anyway, I tried using a pattern instead of 'required' and it works,
   like this:
 
   'email' = array('rule'=VALID_NOT_EMPTY)
 
   ... but I'm wondering if the 'required' rule is working in 1.2?
 
   Cheers,
   Farez


 


--~--~-~--~~~---~--~~
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: Unexpected behaviour in 'required' validation rule (v 1.2)

2007-09-20 Thread Farez

Thanks bujanga. I'll give that a try.

Farez

On Sep 20, 9:13 pm, bujanga [EMAIL PROTECTED] wrote:
 Here is an example of a working rule with a required condition.

 var $validate = array(
 'owner_id'  = array(
 'number'= array(
 'rule'  = array('numeric'),
 'on'= 'create',
 'required' = true,
 'allowEmpty' = false,
 'message'   = 'Owner ID must exist!'
 )
 )
 );

 On 9/19/07, Farez [EMAIL PROTECTED] wrote:



  thanks grigri. seems to be working fine for me without 'allowEmpty'.
  but the 'required' rule is still a mystery to me.

  On Sep 19, 9:40 am, grigri [EMAIL PROTECTED] wrote:
   I ran into this too - you need to add the 'allowEmpty' attribute too:

   'email' = array('rule'=VALID_NOT_EMPTY, 'allowEmpty' = true)

   On Sep 18, 1:51 pm, Farez [EMAIL PROTECTED] wrote:

Hi,

I'm wondering if I'm doing something wrong here (have searched docs,
sources and archives and can't find an answer).

The 'required' rule seems to be broken as it still reports an error
even when the field is not empty. The rule I have is:

'email' = array('rule'='required')

I traced this to this part of the code in Model:invalidFields():

if (method_exists($this, $rule)) {
$ruleParams[] = array_diff_key($validator, $default);
$valid = call_user_func_array(array($this, $rule), 
$ruleParams);} elseif (method_exists($Validation, $rule)) {

$valid = call_user_func_array(array($Validation, $rule),
$ruleParams);} elseif (!is_array($validator['rule'])) {

$valid = preg_match($rule, $data[$fieldName]);

}

where it always lands on the preg_match(...) line in the last
condition, where it tries to preg_match() $rule which has a value of
'required', against the data field.

Anyway, I tried using a pattern instead of 'required' and it works,
like this:

'email' = array('rule'=VALID_NOT_EMPTY)

... but I'm wondering if the 'required' rule is working in 1.2?

Cheers,
Farez


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



  1   2   >