Mutliple validation not working

2016-03-19 Thread Marcus James
Hi,

I am using cakephp version 3, i am trying to add multiple validation but
its not working on password field

$validator = new Validator();
   $validator
->requirePresence('email', 'create')
->notEmpty('email',['message'=>__('Please enter email
address.')])
->add('email', 'email', ['rule' => 'email', 'message'=>__('Please enter
valid email address.')])
->add('email', 'unique', ['rule' => 'validateUnique',
'provider' => 'table','message'=>__('This Email is already taken.')])
->requirePresence('password','create')
->add('password', [
'length' => [
'rule' => ['minLength', 6],
'message' => 'Password need to be at least 6 characters long',
])
   ->notEmpty('password',['message'=>__('Please enter
password.')])
->add('password','length',['rule' => ['minLength',6],'message' =>
__('Password should be minimum 6 character long.')])
->requirePresence('repassword', 'create')
->notEmpty('repassword',['message'=>__('Please enter Confirm Password.')])
->add('repassword','customLength',[
'rule' => function($value, $context) {
if (trim($context['repassword']) !=
trim($context['password'])) {
return false;
}else{
return true;
}
return false;
},
'message' => __('Password and confirm password did not
matched.'),
]);
return $validator;


Thanks,
Marcus

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.


Re: Form: hasMany fields table validation not working

2016-02-29 Thread Paulo Terra
Ok, thank you very much! I am sorry that I didn't realize this singular and
plural detail.

Thank you very much!

Paulo

2016-02-29 11:36 GMT-03:00 Dakota :

> Not a problem, glad that worked for you.
>
> For future reference, you can usually get nearly instant help on the IRC
> channel (
> http://webchat.freenode.net/?channels=cakephp&uio=MT1mYWxzZSY5PXRydWUmMTE9MjQ2b8),
> depending on who is online of course. Stackoverflow is also usually more
> active than the group.
>
> On Monday, 29 February 2016 16:31:11 UTC+2, Paulo Terra wrote:
>>
>> Great! It Works! Thank you Dakota!
>>
>> 2016-02-29 11:15 GMT-03:00 Dakota :
>>
>>> Hi Paulo,
>>>
>>> Your form field for address zipcode field is in the wrong format.
>>> http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-inputs-for-associated-data
>>> shows the correct format for each type of relation. Basically, instead of
>>> doing
>>> $this->Form->input('address.zipcode');
>>>
>>> You need to do instead do:
>>> $this->Form->input('addresses.0.zipcode');
>>>
>>> For hasMany relations, the key is always plural and you need to specify
>>> a numeric index.
>>>
>>>
>>>
>>> On Sunday, 28 February 2016 22:07:32 UTC+2, Paulo Terra wrote:

 Hi,

 I have 3 tables: User, Buyer and Address:

 User hasMany Address
 User hasOne Buyer
 Address belongsTo User
 Buyer belongsTo User

 In the User form (Users/add.ctp):

 echo $this->Form->input('name',['label' => __('Nome')]);
 echo $this->Form->input('buyer.cpf',['label' => __('CPF')]);
 echo $this->Form->input('address.zipcode');



 UsersTable.php:

 $this->hasMany('Addresses', [
 'foreignKey' => 'user_id'
 ]);

 $this->hasOne('Buyers', [
 'foreignKey' => 'user_id'
 ]);



 BuyersTable.php:

 $this->table('buyers');
 $this->displayField('id');
 $this->primaryKey('id');
 $this->belongsTo('Users', [
 'foreignKey' => 'user_id',
 'joinType' => 'INNER'
 ]);


 AddressTable.php:

 $this->table('addresses');
 $this->displayField('id');
 $this->primaryKey('id');
 $this->belongsTo('Users', [
 'foreignKey' => 'user_id',
 'joinType' => 'INNER'
 ]);



 The field "cpf" from Buyer is recognized by cake as it´s Model is shown
 in the include path:


- *Model*(array)
   - *0*APP/Model/Table/UsersTable.php
   - *1*APP/Model/Entity/User.php
   - *2*APP/Model/Table/SurveysTable.php
   - *3*APP/Model/Table/BuyersTable.php
   - *4*APP/Model/Entity/Buyer.php
   - *5*APP/Model/Entity/Survey.php

 And "cpf" is also a "not null" field, whitch is properly verifyed in
 cake when I save.

 The problem is the "zipcode" field in "Address". It´s is also a
 required field but it is not validated from cake. And, as can be seen, it
 is not loaded in Model list.

 But when I change the relation Address relation from "hasMany" to
 "hasOne" it works (it also validade required field when I save).


 UsersTable.php:

 $this->hasOne('Addresses', [
 'foreignKey' => 'user_id'
 ]);

 $this->hasOne('Buyers', [
 'foreignKey' => 'user_id'
 ]);



- *Model*(array)
   - *0*APP/Model/Table/UsersTable.php
   - *1*APP/Model/Entity/User.php
   - *2*APP/Model/Table/SurveysTable.php
   - *3*APP/Model/Table/BuyersTable.php
   - *4*APP/Model/Entity/Buyer.php
   - *5*APP/Model/Table/AddressesTable.php
   - *6*APP/Model/Entity/Address.php
   - *7*APP/Model/Entity/Survey.php



 Does anyone has a clue about what is happening?

 --
>>> Sign up for our Newsletter for updates.
>>> http://cakephp.org/newsletter/signup
>>>
>>> We will soon be closing this Google Group. But don't worry, we have
>>> something better coming. Stay tuned for an updated from the CakePHP Team
>>> soon.
>>>
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Follow us on Twitter http://twitter.com/CakePHP
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "CakePHP" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/cake-php/M8MwE8p8SZc/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> cake-php+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> Sign up for our Newsletter for updates.
> http://cakephp.org/newsletter/signup
>
> We will soon be closing this Google Group. But don't worry, we have
> something better coming. S

Re: Form: hasMany fields table validation not working

2016-02-29 Thread Dakota
Not a problem, glad that worked for you.

For future reference, you can usually get nearly instant help on the IRC 
channel 
(http://webchat.freenode.net/?channels=cakephp&uio=MT1mYWxzZSY5PXRydWUmMTE9MjQ2b8),
 
depending on who is online of course. Stackoverflow is also usually more 
active than the group.

On Monday, 29 February 2016 16:31:11 UTC+2, Paulo Terra wrote:
>
> Great! It Works! Thank you Dakota!
>
> 2016-02-29 11:15 GMT-03:00 Dakota >:
>
>> Hi Paulo,
>>
>> Your form field for address zipcode field is in the wrong format. 
>> http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-inputs-for-associated-data
>>  
>> shows the correct format for each type of relation. Basically, instead of 
>> doing 
>> $this->Form->input('address.zipcode');
>>
>> You need to do instead do:
>> $this->Form->input('addresses.0.zipcode');
>>
>> For hasMany relations, the key is always plural and you need to specify a 
>> numeric index.
>>
>>
>>
>> On Sunday, 28 February 2016 22:07:32 UTC+2, Paulo Terra wrote:
>>>
>>> Hi,
>>>
>>> I have 3 tables: User, Buyer and Address:
>>>
>>> User hasMany Address
>>> User hasOne Buyer
>>> Address belongsTo User
>>> Buyer belongsTo User
>>>
>>> In the User form (Users/add.ctp):
>>>
>>> echo $this->Form->input('name',['label' => __('Nome')]);
>>> echo $this->Form->input('buyer.cpf',['label' => __('CPF')]);
>>> echo $this->Form->input('address.zipcode');
>>>
>>>
>>>
>>> UsersTable.php:
>>>
>>> $this->hasMany('Addresses', [
>>> 'foreignKey' => 'user_id'
>>> ]);
>>> 
>>> $this->hasOne('Buyers', [
>>> 'foreignKey' => 'user_id'
>>> ]);
>>>
>>>
>>>
>>> BuyersTable.php:
>>>
>>> $this->table('buyers');
>>> $this->displayField('id');
>>> $this->primaryKey('id');
>>> $this->belongsTo('Users', [
>>> 'foreignKey' => 'user_id',
>>> 'joinType' => 'INNER'
>>> ]);
>>>
>>>
>>> AddressTable.php:
>>>
>>> $this->table('addresses');
>>> $this->displayField('id');
>>> $this->primaryKey('id');
>>> $this->belongsTo('Users', [
>>> 'foreignKey' => 'user_id',
>>> 'joinType' => 'INNER'
>>> ]);
>>>
>>>
>>>
>>> The field "cpf" from Buyer is recognized by cake as it´s Model is shown 
>>> in the include path:
>>>
>>>
>>>- *Model*(array)
>>>   - *0*APP/Model/Table/UsersTable.php
>>>   - *1*APP/Model/Entity/User.php
>>>   - *2*APP/Model/Table/SurveysTable.php
>>>   - *3*APP/Model/Table/BuyersTable.php
>>>   - *4*APP/Model/Entity/Buyer.php
>>>   - *5*APP/Model/Entity/Survey.php
>>>
>>> And "cpf" is also a "not null" field, whitch is properly verifyed in 
>>> cake when I save.
>>>
>>> The problem is the "zipcode" field in "Address". It´s is also a required 
>>> field but it is not validated from cake. And, as can be seen, it is not 
>>> loaded in Model list.
>>>
>>> But when I change the relation Address relation from "hasMany" to 
>>> "hasOne" it works (it also validade required field when I save).
>>>
>>>
>>> UsersTable.php:
>>>
>>> $this->hasOne('Addresses', [
>>> 'foreignKey' => 'user_id'
>>> ]);
>>> 
>>> $this->hasOne('Buyers', [
>>> 'foreignKey' => 'user_id'
>>> ]);
>>>
>>>
>>>
>>>- *Model*(array)
>>>   - *0*APP/Model/Table/UsersTable.php
>>>   - *1*APP/Model/Entity/User.php
>>>   - *2*APP/Model/Table/SurveysTable.php
>>>   - *3*APP/Model/Table/BuyersTable.php
>>>   - *4*APP/Model/Entity/Buyer.php
>>>   - *5*APP/Model/Table/AddressesTable.php
>>>   - *6*APP/Model/Entity/Address.php
>>>   - *7*APP/Model/Entity/Survey.php
>>>
>>>
>>>
>>> Does anyone has a clue about what is happening?
>>>
>>> -- 
>> Sign up for our Newsletter for updates.
>> http://cakephp.org/newsletter/signup
>>  
>> We will soon be closing this Google Group. But don't worry, we have 
>> something better coming. Stay tuned for an updated from the CakePHP Team 
>> soon.
>>  
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Follow us on Twitter http://twitter.com/CakePHP
>> --- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "CakePHP" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/cake-php/M8MwE8p8SZc/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> cake-php+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe f

Re: Form: hasMany fields table validation not working

2016-02-29 Thread Paulo Terra
Great! It Works! Thank you Dakota!

2016-02-29 11:15 GMT-03:00 Dakota :

> Hi Paulo,
>
> Your form field for address zipcode field is in the wrong format.
> http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-inputs-for-associated-data
> shows the correct format for each type of relation. Basically, instead of
> doing
> $this->Form->input('address.zipcode');
>
> You need to do instead do:
> $this->Form->input('addresses.0.zipcode');
>
> For hasMany relations, the key is always plural and you need to specify a
> numeric index.
>
>
>
> On Sunday, 28 February 2016 22:07:32 UTC+2, Paulo Terra wrote:
>>
>> Hi,
>>
>> I have 3 tables: User, Buyer and Address:
>>
>> User hasMany Address
>> User hasOne Buyer
>> Address belongsTo User
>> Buyer belongsTo User
>>
>> In the User form (Users/add.ctp):
>>
>> echo $this->Form->input('name',['label' => __('Nome')]);
>> echo $this->Form->input('buyer.cpf',['label' => __('CPF')]);
>> echo $this->Form->input('address.zipcode');
>>
>>
>>
>> UsersTable.php:
>>
>> $this->hasMany('Addresses', [
>> 'foreignKey' => 'user_id'
>> ]);
>>
>> $this->hasOne('Buyers', [
>> 'foreignKey' => 'user_id'
>> ]);
>>
>>
>>
>> BuyersTable.php:
>>
>> $this->table('buyers');
>> $this->displayField('id');
>> $this->primaryKey('id');
>> $this->belongsTo('Users', [
>> 'foreignKey' => 'user_id',
>> 'joinType' => 'INNER'
>> ]);
>>
>>
>> AddressTable.php:
>>
>> $this->table('addresses');
>> $this->displayField('id');
>> $this->primaryKey('id');
>> $this->belongsTo('Users', [
>> 'foreignKey' => 'user_id',
>> 'joinType' => 'INNER'
>> ]);
>>
>>
>>
>> The field "cpf" from Buyer is recognized by cake as it´s Model is shown
>> in the include path:
>>
>>
>>- *Model*(array)
>>   - *0*APP/Model/Table/UsersTable.php
>>   - *1*APP/Model/Entity/User.php
>>   - *2*APP/Model/Table/SurveysTable.php
>>   - *3*APP/Model/Table/BuyersTable.php
>>   - *4*APP/Model/Entity/Buyer.php
>>   - *5*APP/Model/Entity/Survey.php
>>
>> And "cpf" is also a "not null" field, whitch is properly verifyed in cake
>> when I save.
>>
>> The problem is the "zipcode" field in "Address". It´s is also a required
>> field but it is not validated from cake. And, as can be seen, it is not
>> loaded in Model list.
>>
>> But when I change the relation Address relation from "hasMany" to
>> "hasOne" it works (it also validade required field when I save).
>>
>>
>> UsersTable.php:
>>
>> $this->hasOne('Addresses', [
>> 'foreignKey' => 'user_id'
>> ]);
>>
>> $this->hasOne('Buyers', [
>> 'foreignKey' => 'user_id'
>> ]);
>>
>>
>>
>>- *Model*(array)
>>   - *0*APP/Model/Table/UsersTable.php
>>   - *1*APP/Model/Entity/User.php
>>   - *2*APP/Model/Table/SurveysTable.php
>>   - *3*APP/Model/Table/BuyersTable.php
>>   - *4*APP/Model/Entity/Buyer.php
>>   - *5*APP/Model/Table/AddressesTable.php
>>   - *6*APP/Model/Entity/Address.php
>>   - *7*APP/Model/Entity/Survey.php
>>
>>
>>
>> Does anyone has a clue about what is happening?
>>
>> --
> Sign up for our Newsletter for updates.
> http://cakephp.org/newsletter/signup
>
> We will soon be closing this Google Group. But don't worry, we have
> something better coming. Stay tuned for an updated from the CakePHP Team
> soon.
>
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Follow us on Twitter http://twitter.com/CakePHP
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "CakePHP" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/cake-php/M8MwE8p8SZc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> cake-php+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.


Re: Form: hasMany fields table validation not working

2016-02-29 Thread Dakota
Hi Paulo,

Your form field for address zipcode field is in the wrong 
format. 
http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-inputs-for-associated-data
 
shows the correct format for each type of relation. Basically, instead of 
doing 
$this->Form->input('address.zipcode');

You need to do instead do:
$this->Form->input('addresses.0.zipcode');

For hasMany relations, the key is always plural and you need to specify a 
numeric index.


On Sunday, 28 February 2016 22:07:32 UTC+2, Paulo Terra wrote:
>
> Hi,
>
> I have 3 tables: User, Buyer and Address:
>
> User hasMany Address
> User hasOne Buyer
> Address belongsTo User
> Buyer belongsTo User
>
> In the User form (Users/add.ctp):
>
> echo $this->Form->input('name',['label' => __('Nome')]);
> echo $this->Form->input('buyer.cpf',['label' => __('CPF')]);
> echo $this->Form->input('address.zipcode');
>
>
>
> UsersTable.php:
>
> $this->hasMany('Addresses', [
> 'foreignKey' => 'user_id'
> ]);
> 
> $this->hasOne('Buyers', [
> 'foreignKey' => 'user_id'
> ]);
>
>
>
> BuyersTable.php:
>
> $this->table('buyers');
> $this->displayField('id');
> $this->primaryKey('id');
> $this->belongsTo('Users', [
> 'foreignKey' => 'user_id',
> 'joinType' => 'INNER'
> ]);
>
>
> AddressTable.php:
>
> $this->table('addresses');
> $this->displayField('id');
> $this->primaryKey('id');
> $this->belongsTo('Users', [
> 'foreignKey' => 'user_id',
> 'joinType' => 'INNER'
> ]);
>
>
>
> The field "cpf" from Buyer is recognized by cake as it´s Model is shown in 
> the include path:
>
>
>- *Model*(array)
>   - *0*APP/Model/Table/UsersTable.php
>   - *1*APP/Model/Entity/User.php
>   - *2*APP/Model/Table/SurveysTable.php
>   - *3*APP/Model/Table/BuyersTable.php
>   - *4*APP/Model/Entity/Buyer.php
>   - *5*APP/Model/Entity/Survey.php
>
> And "cpf" is also a "not null" field, whitch is properly verifyed in cake 
> when I save.
>
> The problem is the "zipcode" field in "Address". It´s is also a required 
> field but it is not validated from cake. And, as can be seen, it is not 
> loaded in Model list.
>
> But when I change the relation Address relation from "hasMany" to "hasOne" 
> it works (it also validade required field when I save).
>
>
> UsersTable.php:
>
> $this->hasOne('Addresses', [
> 'foreignKey' => 'user_id'
> ]);
> 
> $this->hasOne('Buyers', [
> 'foreignKey' => 'user_id'
> ]);
>
>
>
>- *Model*(array)
>   - *0*APP/Model/Table/UsersTable.php
>   - *1*APP/Model/Entity/User.php
>   - *2*APP/Model/Table/SurveysTable.php
>   - *3*APP/Model/Table/BuyersTable.php
>   - *4*APP/Model/Entity/Buyer.php
>   - *5*APP/Model/Table/AddressesTable.php
>   - *6*APP/Model/Entity/Address.php
>   - *7*APP/Model/Entity/Survey.php
>
>
>
> Does anyone has a clue about what is happening?
>
>

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.


Form: hasMany fields table validation not working

2016-02-28 Thread Paulo Terra
Hi,

I have 3 tables: User, Buyer and Address:

User hasMany Address
User hasOne Buyer
Address belongsTo User
Buyer belongsTo User

In the User form (Users/add.ctp):

echo $this->Form->input('name',['label' => __('Nome')]);
echo $this->Form->input('buyer.cpf',['label' => __('CPF')]);
echo $this->Form->input('address.zipcode');



UsersTable.php:

$this->hasMany('Addresses', [
'foreignKey' => 'user_id'
]);

$this->hasOne('Buyers', [
'foreignKey' => 'user_id'
]);



BuyersTable.php:

$this->table('buyers');
$this->displayField('id');
$this->primaryKey('id');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);


AddressTable.php:

$this->table('addresses');
$this->displayField('id');
$this->primaryKey('id');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);



The field "cpf" from Buyer is recognized by cake as it´s Model is shown in 
the include path:


   - *Model*(array)
  - *0*APP/Model/Table/UsersTable.php
  - *1*APP/Model/Entity/User.php
  - *2*APP/Model/Table/SurveysTable.php
  - *3*APP/Model/Table/BuyersTable.php
  - *4*APP/Model/Entity/Buyer.php
  - *5*APP/Model/Entity/Survey.php
   
And "cpf" is also a "not null" field, whitch is properly verifyed in cake 
when I save.

The problem is the "zipcode" field in "Address". It´s is also a required 
field but it is not validated from cake. And, as can be seen, it is not 
loaded in Model list.

But when I change the relation Address relation from "hasMany" to "hasOne" 
it works (it also validade required field when I save).


UsersTable.php:

$this->hasOne('Addresses', [
'foreignKey' => 'user_id'
]);

$this->hasOne('Buyers', [
'foreignKey' => 'user_id'
]);



   - *Model*(array)
  - *0*APP/Model/Table/UsersTable.php
  - *1*APP/Model/Entity/User.php
  - *2*APP/Model/Table/SurveysTable.php
  - *3*APP/Model/Table/BuyersTable.php
  - *4*APP/Model/Entity/Buyer.php
  - *5*APP/Model/Table/AddressesTable.php
  - *6*APP/Model/Entity/Address.php
  - *7*APP/Model/Entity/Survey.php
   


Does anyone has a clue about what is happening?

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.


Re: Bug: flaws in email validation/sending

2016-01-31 Thread euromark
Please open a ticket at https://github.com/cakephp/cakephp/issues
This is just a discission board, not a bug tracker.

Mark


Am Samstag, 30. Januar 2016 05:33:10 UTC+1 schrieb Kim:
>
>
>- CakePHP's email validation allows non-ASCII letter characters, e.g. 
>á, in the  local part of the email address (by the \p{L} unicode category 
>construct). This should not be allowed, see 
>https://en.wikipedia.org/wiki/Email_address#Local_part.
>- It also allows non-ASCII letter characters in the domain part. This 
>allows Internationalized Domain Names (IDN). The problem here lies in the 
>fact that this is not supported by the SmtpTransport. An SMTP client 
> should 
>convert them to so called punycode ASCII, according to 
>https://lists.exim.org/lurker/message/20140812.120609.bf764769.en.html. 
>MTA exim does not accept the SMTP sequence. By the way, conversion to 
>punycode can be done by PHP's idn_to_ascii().
>
> This issues have been tested in the current 2.7 branch, but a quick code 
> inspection confirms that they are also present in the master branch. As a 
> workaround I have switched back to validation by PHP's filter_var(), used 
> in a wrapper validation method.
>
> The first issue can be fixed easily, although the right RFCs have to be 
> consulted. For the second issue, we have to decide if we support IDN for 
> email and if we do, support it (maybe not only in the SmtpTransport).
>

-- 
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 https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Bug: flaws in email validation/sending

2016-01-29 Thread Kim

   
   - CakePHP's email validation allows non-ASCII letter characters, e.g. á, 
   in the  local part of the email address (by the \p{L} unicode category 
   construct). This should not be allowed, see 
   https://en.wikipedia.org/wiki/Email_address#Local_part.
   - It also allows non-ASCII letter characters in the domain part. This 
   allows Internationalized Domain Names (IDN). The problem here lies in the 
   fact that this is not supported by the SmtpTransport. An SMTP client should 
   convert them to so called punycode ASCII, according to 
   https://lists.exim.org/lurker/message/20140812.120609.bf764769.en.html. 
   MTA exim does not accept the SMTP sequence. By the way, conversion to 
   punycode can be done by PHP's idn_to_ascii().
   
This issues have been tested in the current 2.7 branch, but a quick code 
inspection confirms that they are also present in the master branch. As a 
workaround I have switched back to validation by PHP's filter_var(), used 
in a wrapper validation method.

The first issue can be fixed easily, although the right RFCs have to be 
consulted. For the second issue, we have to decide if we support IDN for 
email and if we do, support it (maybe not only in the SmtpTransport).

-- 
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 https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


hasmany validation and save data in a form, best approach

2015-12-29 Thread Raul Magdalena Catala
hello,
lets say that i have a form that represents an invoice and the invoice 
items. the invoice has many invoice items relation.
the form has some inputs for the invoice, and 10 rows with inputs for the 
invoice items: item code, item qty, item price, etc...
Not always all the 10 rows are filled with invoice items and you do not 
wants that the validation rules be applied to these rows that are not used.
the question is, what is the best approach to accomplish this?

-- 
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 https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


validation for multiply table in single view

2015-11-15 Thread Dhingani Yatin
hello

how can i set validation for multiple table in cakephp 3.x my field is

Form->input('Downloads.DownloadContents.image_text',array('label' => 
false,'div'=>false,'type'=>'text','class'=>'form-control','placeholder'=>'Title'));
 
?>

please give me solution for set validation in that type for situation

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.


cakephp 3 validation

2015-09-25 Thread Dhingani Yatin
Hello,

How can i set validation without page refresh in cakephp 3

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


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.


Table's save() fails, where to get the error message? (other than validation errors)

2015-09-14 Thread Ernesto Borio
I can't find in the documentation how to collect error messages (other than 
validation errors) for when a table's save() or delete() fail, how is it 
done?

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


saveMany validation not working correctly

2015-07-06 Thread Javi


I'm trying to do this With last 2.x CakePHP version, I'm trying to do a 
upload multiple file form with validations but not working...

*DocsController.php (action add)*

if ($this->request->is('post')) {
if ($this->Doc->saveMany($this->request->data, array('deep' => true))) {
$this->Session->setFlash(__('Ok'));
} else {
debug($this->Doc->validationErrors); die();
$this->Session->setFlash(__('Error'));
}
$this->redirect($this->referer());}

*add.ctp*

Form->create('Doc', array('type' => 'file'));
echo $this->Form->input('files.', array(
'label' => __("New document",true),'type' => 'file', 
'div' => 'input text no',
'multiple' => 'multiple',
'required' => true,));
echo $this->Form->end('Upload');?>

*Doc.php*

class Doc extends AppModel {

public $belongsTo = array(
'Project' => array(
'className' => 'Project',
'foreignKey' => 'project_id',
)
);

public $validate = array(
'files' => array(
'rule' => array('extension', array('pdf')),
'required' => false,
'allowEmpty' => true,
'message' => 'Only pdf files' 
),
);}

*Arrays*

*This error is OK:*

Array(
[Doc] => Array
(
[files] => Array
(
[0] => Array
(
[name] => images.jpeg
[type] => image/jpeg
[tmp_name] => /private/var/tmp/phpSqerRI
[error] => 0
[size] => 5740
)

)

)
)
/app/Controller/DocsController.php (line 112)
array(
'Doc' => array(
'files' => array(
(int) 0 => 'Only pdf files'
)
))

*This is the problem:*

Array(
[Doc] => Array
(
[files] => Array
    (
    [0] => Array
(
[name] => 4_54718093804437603.pdf
[type] => application/pdf
[tmp_name] => /private/var/tmp/phpCfUUDx
[error] => 0
[size] => 1441232
)

)

)
)
/app/Controller/DocsController.php (line 112)
array(
'Doc' => array())

It's PDF, so OK but validation returns array

Why return array if no broke rules??

Thanks in advance, sorry for my english.

-- 
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: Validation Example

2015-07-01 Thread joserafael

Use 'message'. For more information visit: 
http://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-validators

El viernes, 26 de junio de 2015, 7:17:53 (UTC-4:30), Kingston Abraham 
escribió:
>
> How will the error messages in validator will appear. Is there any live 
> example to see
>

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


Validation Example

2015-06-26 Thread Kingston Abraham
How will the error messages in validator will appear. Is there any live 
example to see

-- 
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: Cakephp 3.x Validation Error issue

2015-05-15 Thread José Lorenzo
I would use StackOverflow and tag the question as cakephp-2 or cakephp-3.0

Offering help here has become increasingly difficult for me

On Friday, May 15, 2015 at 3:35:39 PM UTC+2, Thomas wrote:
>
> What is a best way to get answers of my issues? I am not getting any 
> solution from last 20 days
>
> On Wednesday, May 6, 2015 at 5:17:36 PM UTC+5:30, Thomas wrote:
>>
>> Hello Experts,
>>
>> any update?
>>
>> On Wednesday, April 22, 2015 at 4:00:20 AM UTC+5:30, Cake Developer wrote:
>>>
>>> Hi,
>>>
>>> I am facing issue on form input validations errors. my input fields are 
>>> following
>>>
>>> $this->Form->input('FormElements.text.1.title', ['type'=>'text', 
>>> 'label'=>false, 'class'=>'form-control']);
>>>
>>> $this->Form->input('FormElements.text.2.title', ['type'=>'text', 
>>> 'label'=>false, 'class'=>'form-control']);
>>>
>>> $this->Form->input('FormElements.textarea.1.description', 
>>> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>>>
>>> $this->Form->input('FormElements.textarea.2.description', 
>>> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>>>
>>> Please help me anyone to apply validation rules and display errors.
>>>
>>> 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 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: Cakephp 3.x Validation Error issue

2015-05-15 Thread Thomas
What is a best way to get answers of my issues? I am not getting any 
solution from last 20 days

On Wednesday, May 6, 2015 at 5:17:36 PM UTC+5:30, Thomas wrote:
>
> Hello Experts,
>
> any update?
>
> On Wednesday, April 22, 2015 at 4:00:20 AM UTC+5:30, Cake Developer wrote:
>>
>> Hi,
>>
>> I am facing issue on form input validations errors. my input fields are 
>> following
>>
>> $this->Form->input('FormElements.text.1.title', ['type'=>'text', 
>> 'label'=>false, 'class'=>'form-control']);
>>
>> $this->Form->input('FormElements.text.2.title', ['type'=>'text', 
>> 'label'=>false, 'class'=>'form-control']);
>>
>> $this->Form->input('FormElements.textarea.1.description', 
>> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>>
>> $this->Form->input('FormElements.textarea.2.description', 
>> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>>
>> Please help me anyone to apply validation rules and display errors.
>>
>> 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 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: Cakephp 3.x Validation Error issue

2015-05-06 Thread Thomas
Hello Experts,

any update?

On Wednesday, April 22, 2015 at 4:00:20 AM UTC+5:30, Cake Developer wrote:
>
> Hi,
>
> I am facing issue on form input validations errors. my input fields are 
> following
>
> $this->Form->input('FormElements.text.1.title', ['type'=>'text', 
> 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.text.2.title', ['type'=>'text', 
> 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.textarea.1.description', 
> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.textarea.2.description', 
> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>
> Please help me anyone to apply validation rules and display errors.
>
> 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 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: Cakephp 3.x Validation Error issue

2015-04-23 Thread Cake Developer
Hi John,

I am working on form builder here you can see the image

https://www.dropbox.com/s/tefh2auwqy97g10/form_builder.png?dl=0

It is working in cakephp 2.x fine. here are answers of your questions.

*Have you studied the CakePHP book?*
yes I read the cakephp 3.x cook book

*What have you tried?*
In cakephp 2.x I have written validations like following but I have no idea 
how to try multiple index validation in cakephp 3.x

Cakephp 2.x Form fields are 
$this->Form->input('FormElement.text.1.title', ['type'=>'text', 
'label'=>false, 'class'=>'form-control']);

$this->Form->input('FormElement.text.2.title', ['type'=>'text', 
'label'=>false, 'class'=>'form-control']);

Cakephp 2.x Model Validations are

public $validate = array(
   'text'=> array(
'mustNotEmpty'=>array(
'rule' => 'checkForText',
'message'=> '',
'last'=>true)
),
'textarea'=> array(
'mustNotEmpty'=>array(
'rule' => 'checkForTextarea',
'message'=> '',
'last'=>true)
)
);
function checkForText() {
if(!empty($this->data['FormElement']['text'])) {
foreach($this->data['FormElement']['text'] as $key=>$val) {
if(empty($val['title'])) {
$this->validationErrors['text'][$key]['title'] = "Please enter title";
}
}
}
return true;
}
function checkForTextarea() {
if(!empty($this->data['FormElement']['textarea'])) {
foreach($this->data['FormElement']['textarea'] as $key=>$val) {
if(empty($val['title'])) {
$this->validationErrors['textarea'][$key]['title'] = "Please enter title";
}
}
}
return true;
}

so the validation work like a charm on multi index input 
fields 'FormElement.text.1.title' etc. The form fields are dynamically 
added.
I am not getting any clue to convert this code in cakephp 3.x

*What does not work?*
In cakephp 3.x I have tried so far.

Cakephp 3.x Form fields are 
$this->Form->input('FormElements.text.1.title', ['type'=>'text', 
'label'=>false, 'class'=>'form-control']);

$this->Form->input('FormElements.text.2.title', ['type'=>'text', 
'label'=>false, 'class'=>'form-control']);

Cakephp 3.x Model Validations are

public function validationForFormElements($validator) {
$validator
->add('text', [
'mustNotEmpty'=>[
'rule'=>'checkForText',
'provider'=>'table',
'message'=>''
]
])
->add('textarea', [
'mustNotEmpty'=>[
'rule'=>'checkForTextarea',
'provider'=>'table',
'message'=>''
]
]);
return $validator;
}
function checkForText($value, $context) {
if(!empty($context['data']['text'])) {
foreach($context['data']['text'] as $key=>$val) {
if(empty($val['title'])) {
*I have no idea how add validation error on particular index*
}
}
}
return true;
}
function checkForTextarea($value, $context) {
if(!empty($context['data']['textarea'])) {
foreach($context['data']['textarea'] as $key=>$val) {
if(empty($val['title'])) {
*I have no idea how add validation error on particular index*
}
}
}
return true;
}

*Do you get any error messages?*
I did not get any error messages

Please let me know if anything is not clear.

On Thursday, April 23, 2015 at 10:30:23 PM UTC+5:30, John Andersen wrote:
>
> Please provide more information and also real life examples of your form 
> code, so that we may better be able to help.
>
> Have you studied the CakePHP book?
> What have you tried?
> What does not work?
> Do you get any error messages?
>
> Please show the validation code you have tried, the code for the form and 
> whatever else that may help us understand your problem.
>
> Kind regards
> John Aage Andersen
>
> On Wednesday, 22 April 2015 01:30:20 UTC+3, Cake Developer wrote:
>>
>> Hi,
>>
>> I am facing issue on form input validations errors. my input fields are 
>> following
>>
>> $this->Form->input('FormElements.text.1.title', ['type'=>'text', 
>> 'label'=>false, 'class'=>'form-control']);
>>
>> $this->Form->input('FormElements.text.2.title', ['type'=>'text', 
>> 'label'=>false, 'class'=>'form-control']);
>>
>> $this->Form->input('FormElements.textarea.1.description', 
>> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>>
>> $this->Form->input('FormElements.textarea.2.description', 
>> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>>
>> Please help me anyone to apply validation rules and display errors.
>>
>> 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 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: Cakephp 3.x Validation Error issue

2015-04-23 Thread John Andersen
Please provide more information and also real life examples of your form 
code, so that we may better be able to help.

Have you studied the CakePHP book?
What have you tried?
What does not work?
Do you get any error messages?

Please show the validation code you have tried, the code for the form and 
whatever else that may help us understand your problem.

Kind regards
John Aage Andersen

On Wednesday, 22 April 2015 01:30:20 UTC+3, Cake Developer wrote:
>
> Hi,
>
> I am facing issue on form input validations errors. my input fields are 
> following
>
> $this->Form->input('FormElements.text.1.title', ['type'=>'text', 
> 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.text.2.title', ['type'=>'text', 
> 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.textarea.1.description', 
> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.textarea.2.description', 
> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>
> Please help me anyone to apply validation rules and display errors.
>
> 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 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: Cakephp 3.x Validation Error issue

2015-04-22 Thread Cake Developer
Hi Experts,

any help?

On Wednesday, April 22, 2015 at 4:00:20 AM UTC+5:30, Cake Developer wrote:
>
> Hi,
>
> I am facing issue on form input validations errors. my input fields are 
> following
>
> $this->Form->input('FormElements.text.1.title', ['type'=>'text', 
> 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.text.2.title', ['type'=>'text', 
> 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.textarea.1.description', 
> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>
> $this->Form->input('FormElements.textarea.2.description', 
> ['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);
>
> Please help me anyone to apply validation rules and display errors.
>
> 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 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.


Cakephp 3.x Validation Error issue

2015-04-21 Thread Cake Developer
Hi,

I am facing issue on form input validations errors. my input fields are 
following

$this->Form->input('FormElements.text.1.title', ['type'=>'text', 
'label'=>false, 'class'=>'form-control']);

$this->Form->input('FormElements.text.2.title', ['type'=>'text', 
'label'=>false, 'class'=>'form-control']);

$this->Form->input('FormElements.textarea.1.description', 
['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);

$this->Form->input('FormElements.textarea.2.description', 
['type'=>'textarea', 'label'=>false, 'class'=>'form-control']);

Please help me anyone to apply validation rules and display errors.

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 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: [Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread Willem
It worked thanks!

On Monday, April 13, 2015 at 6:18:36 PM UTC+2, John Andersen wrote:
>
> The validation in your model points to a field named "image", but the view 
> you have points to a field named "submittedFile" :)
> Which is the correct one?
> Enjoy, John
>
> On Monday, 13 April 2015 11:17:13 UTC+3, Willem wrote:
>>
>> I have a model "Attachment" which Belongs to another model (hasMany 
>> Attachment). 
>>
>> In model Attachment I put a validator (from the Cake helpbook) to check 
>> against filetypes. After saveAssociated i would expect an error if uploaded 
>> a .txt file, but the model is save successfully?
>>
>> *Add.ctp* 
>>
>> for($i=0;$i<1;$i++)
>> {
>> ?>
>> 
>> > echo $this->Form->file('Attachment.'.$i.'.submittedfile');
>> ?>
>> 
>> > }
>>
>>
>>
>> *Attachment model:*
>>
>> > App::uses('AppModel', 'Model');
>>
>> class Attachment extends AppModel {
>>
>> public $belongsTo = 'CollectionRequest';
>>
>> public $validate = array(
>> 'image' => array(
>> 'rule' => array(
>> 'extension',
>> array('gif', 'jpeg', 'png', 'jpg')
>> ),
>> 'message' => 'Please supply a valid image.'
>> )
>> );
>>
>>
>> public function beforeSave($options = array()) {
>>
>> parent::beforeSave($options);
>> }
>>
>> public function beforeValidate($options = array()) {
>>
>> // ignore empty file - causes issues with form validation when 
>> file is empty and optional
>> if (!empty($this->data[$this->alias]['error']) &&
>> $this->data[$this->alias]['error']==4 &&
>> $this->data[$this->alias]['size']==0) {
>> unset($this->data[$this->alias]);
>> }
>>
>>
>> parent::beforeValidate($options);
>> }
>>
>> }
>>
>>
>> ?>
>>
>> *Controller*
>>
>>  if ($this->CollectionRequest->saveAssociated($this->request->data)) {
>> // All good
>> 
>> $this->Session->setFlash(__('CollectionRequest saved'));
>> return $this->redirect(array('action' => 'index'));
>> }
>>
>>
>> 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: [Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread Willem
Hi,

thanks, will try this ASAP. I got it mixed up thiking it was an 
alias/name/labe as in multiple validations per field. :-S





On Monday, April 13, 2015 at 6:18:36 PM UTC+2, John Andersen wrote:
>
> The validation in your model points to a field named "image", but the view 
> you have points to a field named "submittedFile" :)
> Which is the correct one?
> Enjoy, John
>
> On Monday, 13 April 2015 11:17:13 UTC+3, Willem wrote:
>>
>> I have a model "Attachment" which Belongs to another model (hasMany 
>> Attachment). 
>>
>> In model Attachment I put a validator (from the Cake helpbook) to check 
>> against filetypes. After saveAssociated i would expect an error if uploaded 
>> a .txt file, but the model is save successfully?
>>
>> *Add.ctp* 
>>
>> for($i=0;$i<1;$i++)
>> {
>> ?>
>> 
>> > echo $this->Form->file('Attachment.'.$i.'.submittedfile');
>> ?>
>> 
>> > }
>>
>>
>>
>> *Attachment model:*
>>
>> > App::uses('AppModel', 'Model');
>>
>> class Attachment extends AppModel {
>>
>> public $belongsTo = 'CollectionRequest';
>>
>> public $validate = array(
>> 'image' => array(
>> 'rule' => array(
>> 'extension',
>> array('gif', 'jpeg', 'png', 'jpg')
>> ),
>> 'message' => 'Please supply a valid image.'
>> )
>> );
>>
>>
>> public function beforeSave($options = array()) {
>>
>> parent::beforeSave($options);
>> }
>>
>> public function beforeValidate($options = array()) {
>>
>> // ignore empty file - causes issues with form validation when 
>> file is empty and optional
>> if (!empty($this->data[$this->alias]['error']) &&
>> $this->data[$this->alias]['error']==4 &&
>> $this->data[$this->alias]['size']==0) {
>> unset($this->data[$this->alias]);
>> }
>>
>>
>> parent::beforeValidate($options);
>> }
>>
>> }
>>
>>
>> ?>
>>
>> *Controller*
>>
>>  if ($this->CollectionRequest->saveAssociated($this->request->data)) {
>> // All good
>> 
>> $this->Session->setFlash(__('CollectionRequest saved'));
>> return $this->redirect(array('action' => 'index'));
>> }
>>
>>
>> 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: [Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread John Andersen
The validation in your model points to a field named "image", but the view 
you have points to a field named "submittedFile" :)
Which is the correct one?
Enjoy, John

On Monday, 13 April 2015 11:17:13 UTC+3, Willem wrote:
>
> I have a model "Attachment" which Belongs to another model (hasMany 
> Attachment). 
>
> In model Attachment I put a validator (from the Cake helpbook) to check 
> against filetypes. After saveAssociated i would expect an error if uploaded 
> a .txt file, but the model is save successfully?
>
> *Add.ctp* 
>
> for($i=0;$i<1;$i++)
> {
> ?>
> 
>  echo $this->Form->file('Attachment.'.$i.'.submittedfile');
> ?>
> 
>  }
>
>
>
> *Attachment model:*
>
>  App::uses('AppModel', 'Model');
>
> class Attachment extends AppModel {
>
> public $belongsTo = 'CollectionRequest';
>
> public $validate = array(
> 'image' => array(
> 'rule' => array(
> 'extension',
> array('gif', 'jpeg', 'png', 'jpg')
> ),
> 'message' => 'Please supply a valid image.'
> )
> );
>
>
> public function beforeSave($options = array()) {
>
> parent::beforeSave($options);
> }
>
> public function beforeValidate($options = array()) {
>
> // ignore empty file - causes issues with form validation when 
> file is empty and optional
> if (!empty($this->data[$this->alias]['error']) &&
> $this->data[$this->alias]['error']==4 &&
> $this->data[$this->alias]['size']==0) {
> unset($this->data[$this->alias]);
> }
>
>
> parent::beforeValidate($options);
> }
>
> }
>
>
> ?>
>
> *Controller*
>
>  if ($this->CollectionRequest->saveAssociated($this->request->data)) {
> // All good
> 
> $this->Session->setFlash(__('CollectionRequest saved'));
> return $this->redirect(array('action' => 'index'));
> }
>
>
> 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.


[Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread Willem
I have a model "Attachment" which Belongs to another model (hasMany 
Attachment). 

In model Attachment I put a validator (from the Cake helpbook) to check 
against filetypes. After saveAssociated i would expect an error if uploaded 
a .txt file, but the model is save successfully?

*Add.ctp* 

for($i=0;$i<1;$i++)
{
?>

Form->file('Attachment.'.$i.'.submittedfile');
?>

 array(
'rule' => array(
'extension',
array('gif', 'jpeg', 'png', 'jpg')
),
'message' => 'Please supply a valid image.'
)
);


public function beforeSave($options = array()) {

parent::beforeSave($options);
    }

public function beforeValidate($options = array()) {

// ignore empty file - causes issues with form validation when file 
is empty and optional
if (!empty($this->data[$this->alias]['error']) &&
$this->data[$this->alias]['error']==4 &&
$this->data[$this->alias]['size']==0) {
unset($this->data[$this->alias]);
}


parent::beforeValidate($options);
}

}


?>

*Controller*

 if ($this->CollectionRequest->saveAssociated($this->request->data)) {
// All good

$this->Session->setFlash(__('CollectionRequest saved'));
return $this->redirect(array('action' => 'index'));
}


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: File upload validation

2015-03-01 Thread Charles Beasley
I think we have a misunderstanding.  The code I sent you was for your
model.  The only thing that changes was you had some code in the
"afterValidate" function and I provided you with an alternative to do all
the legwork in the "beforeValidate" function.

If you use "beforeValidate" you can do all the photo uploading and
field-setting logic and return TRUE.   Alternatively, you can return FALSE
to prevent further validation if there is an error.

*NOTE:  If *beforeValidate* returns FALSE CakePHP will short-circuit and "*
validates()*" DOES NOT execute.  *

*NOTE:  If *beforeValidate* returns TRUE CakePHP will execute "*validates()*".
  **Performing the file upload in the *afterValidate* function is TOO LATE;
The Model has already attempted to validate your field "*photo*" and the
error is already set before *afterValidate* callback event is executed.*

*NOTE:  The function **afterValidate** is called by the ModelValidator
object inside the **errors* * function.  The ModelValidator **errors**
function performs tests all the fields, sets errors, and finally executes *
afterValidate* before returning.*

SEE: http://book.cakephp.org/2.0/en/models/callback-methods.html

Sincerely,

Charles A Beasley


On Sun, Mar 1, 2015 at 5:56 AM, Sam Clauw  wrote:

> Charles, thank you for the great effort!
> But is there no other option than move the validation into the controller
> instead of doing it in the model?
>
> The code I wrote only contains one single if/else and is very clear to me.
> Okay, it's not working so I'm not getting anywhere for the moment huh ;)
>
> Can you confirm that extension rule in CakePHP is validation the ['type']
> variable in the FILES array? If "yes", I realy don't understand why I keep
> getting validation errors on the validExtension rule :s
>
>  --
> 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.


Re: File upload validation

2015-03-01 Thread Sam Clauw
Charles, thank you for the great effort!
But is there no other option than move the validation into the controller 
instead of doing it in the model?

The code I wrote only contains one single if/else and is very clear to me. 
Okay, it's not working so I'm not getting anywhere for the moment huh ;)

Can you confirm that extension rule in CakePHP is validation the ['type'] 
variable in the FILES array? If "yes", I realy don't understand why I keep 
getting validation errors on the validExtension rule :s

-- 
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: File upload validation

2015-02-28 Thread Charles Beasley
You can get rid of the $unset_photo variable I didn't end up using it.

--Charles

On Sat, Feb 28, 2015 at 6:48 PM, Charles Beasley 
wrote:

> I'm sorry.. I replied quickly via cell phone.  A better response is as
> follows.
>
> Try the following code:
>
> 
>
> class Outlet extends CoasterCmsAppModel
>
> {
>
> public $validate = array(
>
> 'name' => array(
>
> 'rule' => 'notEmpty', // verplicht
>
> 'message' => 'Nameis required.',
>
> 'allowEmpty' => true
>
> ),
>
> 'intro' => array(
>
> 'rule' => 'notEmpty', // verplicht
>
> 'message' => 'Intro is required.'
>
> ),
>
> 'photo' => array(
>
> 'validFileSize' => array( // zelf gekozen naam van de regel
>
> 'rule' => array('filesize', '>', 0), // verplicht
>
> 'on' => 'create',
>
> 'message' => 'Photo is required.'
>
> )
>
> ),
>
> 'photoTemp' => array(
>
> 'validExtension' => array( // zelf gekozen naam van de regel
>
> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
> 'gif')),
>
> 'on' => 'create',
>
> 'message' => 'Photo has to contain a valid extension (jpg,
> jpeg, png or gif).'
>
> ),
>
> 'validExtension' => array( // zelf gekozen naam van de regel
>
> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
> 'gif')),
>
> 'allowEmpty' => true,
>
> 'on' => 'update',
>
> 'message' => 'Photo has to contain a valid extension (jpg,
> jpeg, png or gif).'
>
> )
>
> )
>
> );
>
>
>
> public function beforeValidate()
>
> {
>
> $unset_photo = false;
>
> if ( is_array( $this->data['Outlet']['photo'] ) ) {
>
> $filename = false;
>
> $tmp_filename = false;
>
> $unset_photo = true;
>
> $upload_path = WWW_ROOT .'img' . DS . 'outlets' . DS;
>
> if ( isset( $this->data['Outlet']['photo']['name'] ) ) {
>
> $filename = trim($this->data['Outlet']['photo']['name']);
>
> }
>
> if ( isset( $this->data['Outlet']['photo']['tmp_name'] ) ) {
>
> $tmp_filename =
> trim($this->data['Outlet']['photo']['tmp_name']);
>
> }
>
> if ( ! empty( $tmp_filename ) && ! empty( $filename ) ) {
>
> // Move the uploaded file to the new directory
>
> if(!move_uploaded_file($tmp_filename,  $upload_path
> basename($filename))) {
>
> /*
>
>  * Handle upload error and return FALSE; e.g.
>
>  * $this->validationErrors['Outlet']['photo'] =
> 'Failed to upload file ' . $filename;
>
>  */
>
> } else {
>
> $this->data['Outlet']['photo'] = $filename;  // SUCCESS
>
> }
>
> } else if ( ! empty( $this->data['Outlet']['photo'] ) ) ) {
>
> /*
>
>  * Handle Invalid input error and return FALSE; e.g.
>
>  *
>
>  *   $this->validationErrors['Outlet']['photo'] =
> 'Invalid input: photo tmp_name required';
>
>  *   $this->validationErrors['Outlet']['photo'] =
> 'Invalid input: photo name required';
>
>  */
>
> } else {
>
> /*
>
>  * Silently unset and ignore an empty array.
>
>  */
>
> unset($this->data['Outlet']['photo']);
>
> }
>
> }
>
> }
>
>
> ?>
>
>
> On Sat, Feb 28, 2015 at 6:24 PM, Charles Beasley 
> wrote:
>
>> I think you should change your function to beforeValidate
>> On Feb 28, 2015 5:54 PM, "Sam Clauw"  wrote:
>>
>>> Okay Charles , that makes sense so I changed my code:
>>>
>>> >>
>>>
>>> class Outlet extends CoasterCmsAppModel
>>> {
>>> public $validate = array(
>>> 'name' => array(
>>> 'rule' => 'notEmpty', // verplicht
>>> 'message' => 'Nameis required.',
>>> 'allowEmpty' => true
>>> ),
>>> 'intro' => array(
>>> 'rule' => 'notEmpty', // verplicht
>>> 'message' => 'Intro is required.'
>>> ),
>>> 'photo' => array(
>>> 'validFileSize' => array( // zelf gekozen naam van de regel
>>> 'rule' => array('filesize', '>', 0), // verplicht
>>> 'on' => 'create',
>>> 'message' => 'Photo is required.'
>>> )
>>> ),
>>> 'photoTemp' => array(
>>> 'validExtension' => array( // zelf gekozen naam van de regel
>>> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
>>> 'gif')),
>>> 'on' => 'create',
>>> 'message' => 'Photo has to contain a valid extension
>>> (jpg, jpeg, 

Re: File upload validation

2015-02-28 Thread Charles Beasley
I'm sorry.. I replied quickly via cell phone.  A better response is as
follows.

Try the following code:

 array(

'rule' => 'notEmpty', // verplicht

'message' => 'Nameis required.',

'allowEmpty' => true

),

'intro' => array(

'rule' => 'notEmpty', // verplicht

'message' => 'Intro is required.'

),

'photo' => array(

'validFileSize' => array( // zelf gekozen naam van de regel

'rule' => array('filesize', '>', 0), // verplicht

'on' => 'create',

'message' => 'Photo is required.'

)

),

'photoTemp' => array(

'validExtension' => array( // zelf gekozen naam van de regel

'rule' => array('extension', array('jpg', 'jpeg', 'png',
'gif')),

'on' => 'create',

'message' => 'Photo has to contain a valid extension (jpg,
jpeg, png or gif).'

),

'validExtension' => array( // zelf gekozen naam van de regel

'rule' => array('extension', array('jpg', 'jpeg', 'png',
'gif')),

'allowEmpty' => true,

'on' => 'update',

'message' => 'Photo has to contain a valid extension (jpg,
jpeg, png or gif).'

)

)

);



public function beforeValidate()

{

$unset_photo = false;

if ( is_array( $this->data['Outlet']['photo'] ) ) {

$filename = false;

$tmp_filename = false;

$unset_photo = true;

$upload_path = WWW_ROOT .'img' . DS . 'outlets' . DS;

if ( isset( $this->data['Outlet']['photo']['name'] ) ) {

$filename = trim($this->data['Outlet']['photo']['name']);

}

if ( isset( $this->data['Outlet']['photo']['tmp_name'] ) ) {

$tmp_filename =
trim($this->data['Outlet']['photo']['tmp_name']);

}

if ( ! empty( $tmp_filename ) && ! empty( $filename ) ) {

// Move the uploaded file to the new directory

if(!move_uploaded_file($tmp_filename,  $upload_path
basename($filename))) {

/*

 * Handle upload error and return FALSE; e.g.

 * $this->validationErrors['Outlet']['photo'] =
'Failed to upload file ' . $filename;

 */

} else {

$this->data['Outlet']['photo'] = $filename;  // SUCCESS

}

} else if ( ! empty( $this->data['Outlet']['photo'] ) ) ) {

/*

 * Handle Invalid input error and return FALSE; e.g.

 *

 *   $this->validationErrors['Outlet']['photo'] =  'Invalid
input: photo tmp_name required';

 *   $this->validationErrors['Outlet']['photo'] =  'Invalid
input: photo name required';

 */

} else {

/*

 * Silently unset and ignore an empty array.

 */

unset($this->data['Outlet']['photo']);

}

}

}


?>


On Sat, Feb 28, 2015 at 6:24 PM, Charles Beasley 
wrote:

> I think you should change your function to beforeValidate
> On Feb 28, 2015 5:54 PM, "Sam Clauw"  wrote:
>
>> Okay Charles , that makes sense so I changed my code:
>>
>> >
>>
>> class Outlet extends CoasterCmsAppModel
>> {
>> public $validate = array(
>> 'name' => array(
>> 'rule' => 'notEmpty', // verplicht
>> 'message' => 'Nameis required.',
>> 'allowEmpty' => true
>> ),
>> 'intro' => array(
>> 'rule' => 'notEmpty', // verplicht
>> 'message' => 'Intro is required.'
>> ),
>> 'photo' => array(
>> 'validFileSize' => array( // zelf gekozen naam van de regel
>> 'rule' => array('filesize', '>', 0), // verplicht
>> 'on' => 'create',
>> 'message' => 'Photo is required.'
>> )
>> ),
>> 'photoTemp' => array(
>> 'validExtension' => array( // zelf gekozen naam van de regel
>> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
>> 'gif')),
>> 'on' => 'create',
>> 'message' => 'Photo has to contain a valid extension
>> (jpg, jpeg, png or gif).'
>> ),
>> 'validExtension' => array( // zelf gekozen naam van de regel
>> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
>> 'gif')),
>> 'allowEmpty' => true,
>> 'on' => 'update',
>> 'message' => 'Photo has to contain a valid extension
>> (jpg, jpeg, png or gif).'
>> )
>> )
>> );
>>
>> public function beforeValidate()
>> {
>> $this->data['Outlet']['photoTemp'] = $this->data['

Re: File upload validation

2015-02-28 Thread Charles Beasley
I think you should change your function to beforeValidate
On Feb 28, 2015 5:54 PM, "Sam Clauw"  wrote:

> Okay Charles , that makes sense so I changed my code:
>
> 
>
> class Outlet extends CoasterCmsAppModel
> {
> public $validate = array(
> 'name' => array(
> 'rule' => 'notEmpty', // verplicht
> 'message' => 'Nameis required.',
> 'allowEmpty' => true
> ),
> 'intro' => array(
> 'rule' => 'notEmpty', // verplicht
> 'message' => 'Intro is required.'
> ),
> 'photo' => array(
> 'validFileSize' => array( // zelf gekozen naam van de regel
> 'rule' => array('filesize', '>', 0), // verplicht
> 'on' => 'create',
> 'message' => 'Photo is required.'
> )
> ),
> 'photoTemp' => array(
> 'validExtension' => array( // zelf gekozen naam van de regel
> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
> 'gif')),
> 'on' => 'create',
> 'message' => 'Photo has to contain a valid extension
> (jpg, jpeg, png or gif).'
> ),
> 'validExtension' => array( // zelf gekozen naam van de regel
> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
> 'gif')),
> 'allowEmpty' => true,
> 'on' => 'update',
> 'message' => 'Photo has to contain a valid extension
> (jpg, jpeg, png or gif).'
> )
> )
> );
>
> public function beforeValidate()
> {
> $this->data['Outlet']['photoTemp'] = $this->data['Outlet']['photo'
> ];
> $this->data['Outlet']['photo'] = $this->data['Outlet']['photoTemp'
> ]['name'];
> }
>
> public function afterValidate()
> {
> $filename = $this->data['Outlet']['photo'];
>
> if (!empty($filename)) {
> move_uploaded_file($this->data['Outlet']['photoTemp'][
> 'tmp_name'], WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);
> } else {
> unset($this->data['Outlet']['photo']);
> }
>
> unset($this->data['Outlet']['photoTemp']);
> }
> }
>
>
> However, I still get the error message that I should upload a file with a
> correct extension. It's just like 'allowEmpty' => true" isn't working at
> all.
> I quess in my case it's checking the value in $this->data['Outlet'][
> 'photoTemp']['type'] so what could possibly be the problem?
>
> --
> 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.


Re: File upload validation

2015-02-28 Thread Sam Clauw
Okay Charles , that makes sense so I changed my code:

 array(
'rule' => 'notEmpty', // verplicht
'message' => 'Nameis required.',
'allowEmpty' => true
),
'intro' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Intro is required.'
),
'photo' => array(
'validFileSize' => array( // zelf gekozen naam van de regel
'rule' => array('filesize', '>', 0), // verplicht
'on' => 'create',
'message' => 'Photo is required.'
)
),
'photoTemp' => array(
'validExtension' => array( // zelf gekozen naam van de regel
'rule' => array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'on' => 'create',
'message' => 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
),
'validExtension' => array( // zelf gekozen naam van de regel
'rule' => array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'allowEmpty' => true,
'on' => 'update',
'message' => 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
)
)
);

public function beforeValidate()
{
$this->data['Outlet']['photoTemp'] = $this->data['Outlet']['photo'];
$this->data['Outlet']['photo'] = $this->data['Outlet']['photoTemp'][
'name'];
}

public function afterValidate()
{
$filename = $this->data['Outlet']['photo'];

if (!empty($filename)) {
move_uploaded_file($this->data['Outlet']['photoTemp']['tmp_name'
], WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);
} else {
unset($this->data['Outlet']['photo']);
}

unset($this->data['Outlet']['photoTemp']);
}
}


However, I still get the error message that I should upload a file with a 
correct extension. It's just like 'allowEmpty' => true" isn't working at 
all.
I quess in my case it's checking the value in $this->data['Outlet'][
'photoTemp']['type'] so what could possibly be the problem?

-- 
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: File upload validation

2015-02-28 Thread Charles Beasley
Sam:

Based on your code the value for $this->data['Outlet']['photo'] is an array
instead of a string field indicated by $validate and "$this->set('photo',
 $filename)".  This suggests that the type for  $this->data['Outlet'][
'photo'] is transitioning from an array to a string.  You would have to
make sure that $this->data['Outlet']['photo'] contains a string value when
validate() is executed.  Is it possible that your afterValidate function is
supposed to be beforeValidate?

--Charles

On Sat, Feb 28, 2015 at 2:42 PM, Sam Clauw  wrote:

> I have a problem with my file upload validation in CakePHP.
>
> When I add a new record with an image upload field...
>
>- ... image should be required.
>- ... image file extension sould be jpg, png or gif.
>
> When I edit an existing record with an image upload field...
>
>- ... image is not required.
>- ... when image is choosen: image file extension sould be jpg, png or
>gif.
>
> Here's my best model code attempt so far:
>
> 
>
> class Outlet extends CoasterCmsAppModel
> {
> public $validate = array(
> 'name' => array(
> 'rule' => 'notEmpty', // verplicht
> 'message' => 'Name is required.',
> 'allowEmpty' => true
> ),
> 'intro' => array(
> 'rule' => 'notEmpty', // verplicht
> 'message' => 'Intro is required.'
> ),
> 'photo' => array(
> 'validFileSize' => array( // zelf gekozen naam van de regel
> 'rule' => array('filesize', '>', 0), // verplicht
> 'on' => 'create',
> 'message' => 'Photo is required.'
> ),
> 'validExtension' => array( // zelf gekozen naam van de regel
> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
> 'gif')),
> 'on' => 'create',
> 'message' => 'Photo has to contain a valid extension
> (jpg, jpeg, png or gif).'
> ),
> 'validExtension' => array( // zelf gekozen naam van de regel
> 'rule' => array('extension', array('jpg', 'jpeg', 'png',
> 'gif')),
> 'allowEmpty' => true,
> 'on' => 'update',
> 'message' => 'Photo has to contain a valid extension
> (jpg, jpeg, png or gif).'
> )
> )
> );
>
> public function afterValidate()
> {
> $filename = $this->data['Outlet']['photo']['name'];
>
> if (!empty($filename)) {
> move_uploaded_file($this->data['Outlet']['photo']['tmp_name'],
> WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);
>
> $this->set('photo', $filename);
> } else {
> unset($this->data['Outlet']['photo']);
> }
> }
> }
>
>
> The "add" validation works fine for me. But strange as it is, when I edit
> a record, I keep getting the error message "Photo has to contain a valid
> extension (jpg, jpeg, png or gif)."
> Somebody who can help me out of this? ;)
>
> --
> 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.


File upload validation

2015-02-28 Thread Sam Clauw
I have a problem with my file upload validation in CakePHP.

When I add a new record with an image upload field...

   - ... image should be required.
   - ... image file extension sould be jpg, png or gif.

When I edit an existing record with an image upload field...

   - ... image is not required.
   - ... when image is choosen: image file extension sould be jpg, png or 
   gif.

Here's my best model code attempt so far:

 array(
'rule' => 'notEmpty', // verplicht
'message' => 'Name is required.',
'allowEmpty' => true
),
'intro' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Intro is required.'
),
'photo' => array(
'validFileSize' => array( // zelf gekozen naam van de regel
'rule' => array('filesize', '>', 0), // verplicht
'on' => 'create',
'message' => 'Photo is required.'
),
'validExtension' => array( // zelf gekozen naam van de regel
'rule' => array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'on' => 'create',
'message' => 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
),
'validExtension' => array( // zelf gekozen naam van de regel
'rule' => array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'allowEmpty' => true,
'on' => 'update',
'message' => 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
)
)
);

public function afterValidate()
{
$filename = $this->data['Outlet']['photo']['name'];

if (!empty($filename)) {
move_uploaded_file($this->data['Outlet']['photo']['tmp_name'], 
WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);

$this->set('photo', $filename);
} else {
unset($this->data['Outlet']['photo']);
}
}
}


The "add" validation works fine for me. But strange as it is, when I edit a 
record, I keep getting the error message "Photo has to contain a valid 
extension (jpg, jpeg, png or gif)."
Somebody who can help me out of this? ;)

-- 
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: CakePHP-3 Plugins form validation messages and field values

2015-02-23 Thread Gaurav Kumar
Lorenzo,

I got the problem and the solution both. The problem was happening because 
of page reload. So now with the help of session i can fix that or I got 
modelless forms in cakephp which is also providing the solution. thanks for 
you help.

On Monday, February 23, 2015 at 1:57:41 PM UTC+5:30, José Lorenzo wrote:
>
> Can you show the code you are using? Use gist.github.com to show your 
> table class, controller and form code.
>
> On Thursday, February 19, 2015 at 7:19:22 AM UTC+1, Gaurav Kumar wrote:
>>
>> I have just created a CommentManager plugin. Created the comment form in 
>> post's view.ctp file and able to add the comments. But when the values of 
>> the comment form are wrong(email format is not proper or empty) then i am 
>> not getting the validation message in front of the respected fields and the 
>> values are not refilled.
>>
>> Also would like to know what would be the proper way to create a comment 
>> form inside a view file of posts.
>>
>

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


Re: CakePHP-3 Plugins form validation messages and field values

2015-02-23 Thread José Lorenzo
Can you show the code you are using? Use gist.github.com to show your table 
class, controller and form code.

On Thursday, February 19, 2015 at 7:19:22 AM UTC+1, Gaurav Kumar wrote:
>
> I have just created a CommentManager plugin. Created the comment form in 
> post's view.ctp file and able to add the comments. But when the values of 
> the comment form are wrong(email format is not proper or empty) then i am 
> not getting the validation message in front of the respected fields and the 
> values are not refilled.
>
> Also would like to know what would be the proper way to create a comment 
> form inside a view file of posts.
>

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


CakePHP-3 Plugins form validation messages and field values

2015-02-19 Thread Gaurav Kumar
I have just created a CommentManager plugin. Created the comment form in 
post's view.ctp file and able to add the comments. But when the values of 
the comment form are wrong(email format is not proper or empty) then i am 
not getting the validation message in front of the respected fields and the 
values are not refilled.

Also would like to know what would be the proper way to create a comment 
form inside a view file of posts.

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


[3.0] Validation, how to replace beforeValidate

2015-02-18 Thread RobertMei
Hi 

Until beforeValidate has been removed i kept logic like this in 
beforeValidate
 
public function beforeValidate(Event $event, Entity $entity) {
if( $entity->isNew() )
{
$businessType = $entity->customer->businessType;
if( $businessType == BusinessType::BUSINESS_TYPE_PERSON )
$entity->b2_type = B2Type::TYPE_B2C;
elseif( $businessType == BusinessType::BUSINESS_TYPE_COMPANY )
$entity->b2_type = B2Type::TYPE_B2B;
 if( $entity->dirty('products') )
{
$entity->premium_type = $entity->products[0]->premium_type;
$entity->premium_value = $entity->products[0]->premium_value;
}


I ve got a case where i just need to validate entity (i need deep named 
validations) and set errors (at entity level) - without saving.
Since there is no 
$table->validate($entity)
anymore, how can i achieve it?
How should my controller look like ?.
Do i have to completely rewrite all the logic now?

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


cakephp the rule validation function run twice

2015-02-08 Thread Celia Kessassi
whene i use this code it's repeat the function isExif_imagetype
'ProfileImage' => array(
   'rule'   => 'isExif_imagetype', // ou bien : 
array('nomRegle', 'parametre1', 'parametre2' ...)
 'message'=> 'Votre message d\'erreur'
   ),
, but whene i add 'on' => 'create', 
 it's does't repeat.
and for example whene i debug i got twice message. how to make it's run 
without repeating ??

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-10 Thread Lorne Dudley
Hi Mark !

OK, I have burned up enough time up on this.   It is not clear to me 
whether I am dealing with a plugin or a helper.  I did read up on 
Configure:: though, and that knowledge will be useful.  I got as far as 
tracing entry to your FormHelper, followed by entry to the cakePHP 
FormHelper, but the functions within your FormHelper never get called.  
Examination of your code suggests that the cakePHP helper should be calling 
functions within your helper ???  The FormConfig.novalidate value is 
visible globally though.  I have been unsuccessful in finding examples of 
similar installations and I have not seen any examples that extend native 
cakePHP code as yours seems to do in the documentation.

But the learning experience has been useful.

Regards

Lorne

On Friday, January 9, 2015 at 7:18:01 PM UTC-5, Lorne Dudley wrote:
>
> OK, I see this in your FormHelper.php version #L44
>
> use Cake\View\Helper\FormHelper as CakeFormHelper;
> class FormHelper extends CakeFormHelper
>
> So to answer my last question, it would appear that your FormHelper adds 
> the ability to inspect
> the "novalidate" option.
>
> Now I have to determine how to invoke your FormHelper.
>
> Regards
>
> Lorne
>
> On Friday, January 9, 2015 at 5:39:29 PM UTC-5, Lorne Dudley wrote:
>>
>> OK Mark !
>>
>> I am into the Configuration documentation and looking at bootstrap.php 
>> now.  I will attempt to get this loaded by myself.
>>
>> Can you answer two questions though ?  ( guess that is really three :-)  )
>>
>> Should I focus on your #L44 version ?
>>
>> If I get this working, does your FormHelper.php completely replace the 
>> function in /vendor/cakephp/cakephp/src/View/Helper/FormHelper.php ?
>>
>> Regards
>>
>> Lorne
>>
>> On Friday, January 9, 2015 at 2:45:21 PM UTC-5, euromark wrote:
>>>
>>> Lorne
>>> you can actually set a config on the user side when using sth similar I 
>>> did in my plugin (since 2.x).
>>>
>>> You can either use my Tools plugin directly, or copy and paste the 
>>> relevant part:
>>>
>>> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L16
>>>
>>> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L44
>>>
>>> You can disable it globally or locally via
>>> Configure::write('FormConfig.novalidate', 'true');
>>>
>>> then :)
>>>
>>> No need to mess with any templates in this case.
>>> Mark
>>>
>>>
>>> Am Freitag, 9. Januar 2015 17:50:54 UTC+1 schrieb Lorne Dudley:
>>>>
>>>> Hello José
>>>>
>>>> Thanks for the reference.  If I interpret the manual properly, I think 
>>>> it wants me to store the custom widget under the 
>>>> /vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  
>>>>
>>>> If this is correct then would the custom widget be wiped out every time 
>>>> I did a "composer update" ? 
>>>>
>>>>  I found this to be the case when I had managed to default the form 
>>>> submission to "formnovalidate " using a different technique under the 
>>>> /vendor structure. 
>>>>
>>>>  In the FormHelper.php function widget() I added the line 
>>>> unset($data['required']); // turn off HTML5 browser validation 
>>>> after the line
>>>> unset($data['secure']);
>>>>
>>>> This was replace to the original (or updated) version when I did the 
>>>> "composer update".
>>>>
>>>> What I was really hoping for was perhaps a method of setting a /config 
>>>> option on the user side.
>>>>
>>>> Regards
>>>>
>>>> Lorne
>>>>
>>>> On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>>>>>
>>>>> I have finally found the method to turn off browser validation so that 
>>>>> cakePHP can take control of the validation instead.  
>>>>>   
>>>>> This works for me.  
>>>>>   
>>>>> Form->button(__('Submit'), array('formnovalidate' => 
>>>>> true)) ?>  
>>>>>   
>>>>> Rather than do this for every Form, is there any way to set this 
>>>>> option for Forms globally on the user side ?  
>>>>>   
>>>>> Regards
>>>>>
>>>>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread Lorne Dudley
OK, I see this in your FormHelper.php version #L44

use Cake\View\Helper\FormHelper as CakeFormHelper;
class FormHelper extends CakeFormHelper

So to answer my last question, it would appear that your FormHelper adds 
the ability to inspect
the "novalidate" option.

Now I have to determine how to invoke your FormHelper.

Regards

Lorne

On Friday, January 9, 2015 at 5:39:29 PM UTC-5, Lorne Dudley wrote:
>
> OK Mark !
>
> I am into the Configuration documentation and looking at bootstrap.php 
> now.  I will attempt to get this loaded by myself.
>
> Can you answer two questions though ?  ( guess that is really three :-)  )
>
> Should I focus on your #L44 version ?
>
> If I get this working, does your FormHelper.php completely replace the 
> function in /vendor/cakephp/cakephp/src/View/Helper/FormHelper.php ?
>
> Regards
>
> Lorne
>
> On Friday, January 9, 2015 at 2:45:21 PM UTC-5, euromark wrote:
>>
>> Lorne
>> you can actually set a config on the user side when using sth similar I 
>> did in my plugin (since 2.x).
>>
>> You can either use my Tools plugin directly, or copy and paste the 
>> relevant part:
>>
>> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L16
>>
>> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L44
>>
>> You can disable it globally or locally via
>> Configure::write('FormConfig.novalidate', 'true');
>>
>> then :)
>>
>> No need to mess with any templates in this case.
>> Mark
>>
>>
>> Am Freitag, 9. Januar 2015 17:50:54 UTC+1 schrieb Lorne Dudley:
>>>
>>> Hello José
>>>
>>> Thanks for the reference.  If I interpret the manual properly, I think 
>>> it wants me to store the custom widget under the 
>>> /vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  
>>>
>>> If this is correct then would the custom widget be wiped out every time 
>>> I did a "composer update" ? 
>>>
>>>  I found this to be the case when I had managed to default the form 
>>> submission to "formnovalidate " using a different technique under the 
>>> /vendor structure. 
>>>
>>>  In the FormHelper.php function widget() I added the line 
>>> unset($data['required']); // turn off HTML5 browser validation 
>>> after the line
>>> unset($data['secure']);
>>>
>>> This was replace to the original (or updated) version when I did the 
>>> "composer update".
>>>
>>> What I was really hoping for was perhaps a method of setting a /config 
>>> option on the user side.
>>>
>>> Regards
>>>
>>> Lorne
>>>
>>> On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>>>>
>>>> I have finally found the method to turn off browser validation so that 
>>>> cakePHP can take control of the validation instead.  
>>>>   
>>>> This works for me.  
>>>>   
>>>> Form->button(__('Submit'), array('formnovalidate' => 
>>>> true)) ?>  
>>>>   
>>>> Rather than do this for every Form, is there any way to set this option 
>>>> for Forms globally on the user side ?  
>>>>   
>>>> Regards
>>>>
>>>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread Lorne Dudley
OK Mark !

I am into the Configuration documentation and looking at bootstrap.php 
now.  I will attempt to get this loaded by myself.

Can you answer two questions though ?  ( guess that is really three :-)  )

Should I focus on your #L44 version ?

If I get this working, does your FormHelper.php completely replace the 
function in /vendor/cakephp/cakephp/src/View/Helper/FormHelper.php ?

Regards

Lorne

On Friday, January 9, 2015 at 2:45:21 PM UTC-5, euromark wrote:
>
> Lorne
> you can actually set a config on the user side when using sth similar I 
> did in my plugin (since 2.x).
>
> You can either use my Tools plugin directly, or copy and paste the 
> relevant part:
>
> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L16
>
> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L44
>
> You can disable it globally or locally via
> Configure::write('FormConfig.novalidate', 'true');
>
> then :)
>
> No need to mess with any templates in this case.
> Mark
>
>
> Am Freitag, 9. Januar 2015 17:50:54 UTC+1 schrieb Lorne Dudley:
>>
>> Hello José
>>
>> Thanks for the reference.  If I interpret the manual properly, I think it 
>> wants me to store the custom widget under the 
>> /vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  
>>
>> If this is correct then would the custom widget be wiped out every time I 
>> did a "composer update" ? 
>>
>>  I found this to be the case when I had managed to default the form 
>> submission to "formnovalidate " using a different technique under the 
>> /vendor structure. 
>>
>>  In the FormHelper.php function widget() I added the line 
>> unset($data['required']); // turn off HTML5 browser validation 
>> after the line
>> unset($data['secure']);
>>
>> This was replace to the original (or updated) version when I did the 
>> "composer update".
>>
>> What I was really hoping for was perhaps a method of setting a /config 
>> option on the user side.
>>
>> Regards
>>
>> Lorne
>>
>> On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>>>
>>> I have finally found the method to turn off browser validation so that 
>>> cakePHP can take control of the validation instead.  
>>>   
>>> This works for me.  
>>>   
>>> Form->button(__('Submit'), array('formnovalidate' => 
>>> true)) ?>  
>>>   
>>> Rather than do this for every Form, is there any way to set this option 
>>> for Forms globally on the user side ?  
>>>   
>>> Regards
>>>
>>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread euromark
Never mind my solution then. It would need a little bit more knowledge of 
how CakePHP works.
Even though it would exactly do what you want to.

Try to read the wiki documentation and study the plugin code more, that 
might clarify it a bit.
But note that this is an extended FormHelper, not the core one.


Am Freitag, 9. Januar 2015 22:11:03 UTC+1 schrieb Lorne Dudley:
>
> Hello Mark !
>
> Thanks for this.  At first glance I do not see any difference between the 
> #L16 and the #L44 version.
>
> I have loaded the #L44 version as /src/View/Helper/FornHelper.php.
>
> I do not know where to place
> Configure::write('FormConfig.novalidate', 'true');
>
> I'm a cakePHP novice. Can you give me more detailed instruction ?
> What I would like to achieve is to have the "novalidate" active for any 
> forms that might appear in the application.
>
> How and where do I set up "Configure::write('FormConfig.novalidate', 
> 'true');" so that it is called only on start-up ?
>
> Regards
>
> Lorne
>
> On Friday, January 9, 2015 at 2:45:21 PM UTC-5, euromark wrote:
>>
>> Lorne
>> you can actually set a config on the user side when using sth similar I 
>> did in my plugin (since 2.x).
>>
>> You can either use my Tools plugin directly, or copy and paste the 
>> relevant part:
>>
>> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L16
>>
>> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L44
>>
>> You can disable it globally or locally via
>> Configure::write('FormConfig.novalidate', 'true');
>>
>> then :)
>>
>> No need to mess with any templates in this case.
>> Mark
>>
>>
>> Am Freitag, 9. Januar 2015 17:50:54 UTC+1 schrieb Lorne Dudley:
>>>
>>> Hello José
>>>
>>> Thanks for the reference.  If I interpret the manual properly, I think 
>>> it wants me to store the custom widget under the 
>>> /vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  
>>>
>>> If this is correct then would the custom widget be wiped out every time 
>>> I did a "composer update" ? 
>>>
>>>  I found this to be the case when I had managed to default the form 
>>> submission to "formnovalidate " using a different technique under the 
>>> /vendor structure. 
>>>
>>>  In the FormHelper.php function widget() I added the line 
>>> unset($data['required']); // turn off HTML5 browser validation 
>>> after the line
>>> unset($data['secure']);
>>>
>>> This was replace to the original (or updated) version when I did the 
>>> "composer update".
>>>
>>> What I was really hoping for was perhaps a method of setting a /config 
>>> option on the user side.
>>>
>>> Regards
>>>
>>> Lorne
>>>
>>> On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>>>>
>>>> I have finally found the method to turn off browser validation so that 
>>>> cakePHP can take control of the validation instead.  
>>>>   
>>>> This works for me.  
>>>>   
>>>> Form->button(__('Submit'), array('formnovalidate' => 
>>>> true)) ?>  
>>>>   
>>>> Rather than do this for every Form, is there any way to set this option 
>>>> for Forms globally on the user side ?  
>>>>   
>>>> Regards
>>>>
>>>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread Lorne Dudley
Hello Mark !

Thanks for this.  At first glance I do not see any difference between the 
#L16 and the #L44 version.

I have loaded the #L44 version as /src/View/Helper/FornHelper.php.

I do not know where to place
Configure::write('FormConfig.novalidate', 'true');

I'm a cakePHP novice. Can you give me more detailed instruction ?
What I would like to achieve is to have the "novalidate" active for any 
forms that might appear in the application.

How and where do I set up "Configure::write('FormConfig.novalidate', 'true'
);" so that it is called only on start-up ?

Regards

Lorne

On Friday, January 9, 2015 at 2:45:21 PM UTC-5, euromark wrote:
>
> Lorne
> you can actually set a config on the user side when using sth similar I 
> did in my plugin (since 2.x).
>
> You can either use my Tools plugin directly, or copy and paste the 
> relevant part:
>
> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L16
>
> https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L44
>
> You can disable it globally or locally via
> Configure::write('FormConfig.novalidate', 'true');
>
> then :)
>
> No need to mess with any templates in this case.
> Mark
>
>
> Am Freitag, 9. Januar 2015 17:50:54 UTC+1 schrieb Lorne Dudley:
>>
>> Hello José
>>
>> Thanks for the reference.  If I interpret the manual properly, I think it 
>> wants me to store the custom widget under the 
>> /vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  
>>
>> If this is correct then would the custom widget be wiped out every time I 
>> did a "composer update" ? 
>>
>>  I found this to be the case when I had managed to default the form 
>> submission to "formnovalidate " using a different technique under the 
>> /vendor structure. 
>>
>>  In the FormHelper.php function widget() I added the line 
>> unset($data['required']); // turn off HTML5 browser validation 
>> after the line
>> unset($data['secure']);
>>
>> This was replace to the original (or updated) version when I did the 
>> "composer update".
>>
>> What I was really hoping for was perhaps a method of setting a /config 
>> option on the user side.
>>
>> Regards
>>
>> Lorne
>>
>> On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>>>
>>> I have finally found the method to turn off browser validation so that 
>>> cakePHP can take control of the validation instead.  
>>>   
>>> This works for me.  
>>>   
>>> Form->button(__('Submit'), array('formnovalidate' => 
>>> true)) ?>  
>>>   
>>> Rather than do this for every Form, is there any way to set this option 
>>> for Forms globally on the user side ?  
>>>   
>>> Regards
>>>
>>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread euromark
Lorne
you can actually set a config on the user side when using sth similar I did 
in my plugin (since 2.x).

You can either use my Tools plugin directly, or copy and paste the relevant 
part:
https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L16
https://github.com/dereuromark/cakephp-tools/blob/cake3/src/View/Helper/FormHelper.php#L44

You can disable it globally or locally via
Configure::write('FormConfig.novalidate', 'true');

then :)

No need to mess with any templates in this case.
Mark


Am Freitag, 9. Januar 2015 17:50:54 UTC+1 schrieb Lorne Dudley:
>
> Hello José
>
> Thanks for the reference.  If I interpret the manual properly, I think it 
> wants me to store the custom widget under the 
> /vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  
>
> If this is correct then would the custom widget be wiped out every time I 
> did a "composer update" ? 
>
>  I found this to be the case when I had managed to default the form 
> submission to "formnovalidate " using a different technique under the 
> /vendor structure. 
>
>  In the FormHelper.php function widget() I added the line 
> unset($data['required']); // turn off HTML5 browser validation 
> after the line
> unset($data['secure']);
>
> This was replace to the original (or updated) version when I did the 
> "composer update".
>
> What I was really hoping for was perhaps a method of setting a /config 
> option on the user side.
>
> Regards
>
> Lorne
>
> On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>>
>> I have finally found the method to turn off browser validation so that 
>> cakePHP can take control of the validation instead.  
>>   
>> This works for me.  
>>   
>> Form->button(__('Submit'), array('formnovalidate' => 
>> true)) ?>  
>>   
>> Rather than do this for every Form, is there any way to set this option 
>> for Forms globally on the user side ?  
>>   
>> Regards
>>
>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread Lorne Dudley
Hello José

Thanks for the reference.  If I interpret the manual properly, I think it 
wants me to store the custom widget under the 
/vendor/cakephp/cakephp/src/View/Widget/ directory structure  ?  

If this is correct then would the custom widget be wiped out every time I 
did a "composer update" ? 

 I found this to be the case when I had managed to default the form 
submission to "formnovalidate " using a different technique under the 
/vendor structure. 

 In the FormHelper.php function widget() I added the line 
unset($data['required']); // turn off HTML5 browser validation 
after the line
unset($data['secure']);

This was replace to the original (or updated) version when I did the 
"composer update".

What I was really hoping for was perhaps a method of setting a /config 
option on the user side.

Regards

Lorne

On Thursday, January 8, 2015 at 11:28:48 PM UTC-5, Lorne Dudley wrote:
>
> I have finally found the method to turn off browser validation so that 
> cakePHP can take control of the validation instead.  
>   
> This works for me.  
>   
> Form->button(__('Submit'), array('formnovalidate' => true)) 
> ?>  
>   
> Rather than do this for every Form, is there any way to set this option 
> for Forms globally on the user side ?  
>   
> Regards
>

-- 
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: cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-09 Thread José Lorenzo
In cake 3 you can override the ButtonWidget and make that a default 
property of your 
buttons: 
http://book.cakephp.org/3.0/en/views/helpers/form.html#adding-custom-widgets

You can just extend the one in the core (Cake\View\Widget\ButtonWidget) and 
append your custom options.

On Friday, January 9, 2015 at 5:28:48 AM UTC+1, Lorne Dudley wrote:
>
> I have finally found the method to turn off browser validation so that 
> cakePHP can take control of the validation instead.  
>   
> This works for me.  
>   
> Form->button(__('Submit'), array('formnovalidate' => true)) 
> ?>  
>   
> Rather than do this for every Form, is there any way to set this option 
> for Forms globally on the user side ?  
>   
> Regards
>

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


cakePHP 3.0-RC1, turning off HTML5 browser validation globally on user side ???

2015-01-08 Thread Lorne Dudley
I have finally found the method to turn off browser validation so that 
cakePHP can take control of the validation instead.  
  
This works for me.  
  
Form->button(__('Submit'), array('formnovalidate' => true)) 
?>  
  
Rather than do this for every Form, is there any way to set this option for 
Forms globally on the user side ?  
  
Regards

-- 
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: Validation error on "baked" date field , CakePHP 3

2015-01-08 Thread euromark
Answer is here: https://github.com/cakephp/cakephp/issues/5611


Am Donnerstag, 8. Januar 2015 21:54:34 UTC+1 schrieb Lorne Dudley:
>
> I have a "baked" cakePHP-3.0.0 page which has a field defined as 
> 'date_of_birth date DEFAULT NULL' in TABLE users.  
> When I click the Submit for the "add" function I get  
>   
> Warning (2): preg_match() expects parameter 2 to be string, array given 
> [CORE\src\Validation\Validation.php, line 763]  
> Code Context
>
> protected static function _check($check, $regex)  
> { 
> 
> if (is_string($regex) && preg_match($regex, $check)) { 
> 
> $check = [  
> 'year' => '2014',  
> 'month' => '01',  
> 'day' => '01'  
> ]  
> $regex = 
> '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))([-
>  
> /.])(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})([- 
> /.])(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]$%'
>   
>
>   
> Any suggestion on how to fix ?  
> Regards
>   
> The stack trace is  
> 
> preg_match - [internal], line ??
> Cake\Validation\Validation::_check() - 
> CORE\src\Validation\Validation.php, line 763  
> Cake\Validation\Validation::date() - 
> CORE\src\Validation\Validation.php, line 346  
> Cake\Validation\RulesProvider::__call() - 
> CORE\src\Validation\RulesProvider.php, line 53  
> Cake\Validation\RulesProvider::date() - 
> CORE\src\Validation\ValidationRule.php, line 138  
> Cake\Validation\ValidationRule::process() - 
> CORE\src\Validation\ValidationRule.php, line 138  
> Cake\Validation\Validator::_processRules() - 
> CORE\src\Validation\Validator.php, line 554  
> Cake\Validation\Validator::errors() - 
> CORE\src\Validation\Validator.php, line 128  
> Cake\ORM\Marshaller::_validate() - CORE\src\ORM\Marshaller.php, line 
> 185  
> Cake\ORM\Marshaller::merge() - CORE\src\ORM\Marshaller.php, line 341  
> Cake\ORM\Table::patchEntity() - CORE\src\ORM\Table.php, line 1899  
> App\Controller\UsersController::add() - 
> APP/Controller\UsersController.php, line 48  
> Cake\Controller\Controller::invokeAction() - 
> CORE\src\Controller\Controller.php, line 406  
> Cake\Routing\Dispatcher::_invoke() - CORE\src\Routing\Dispatcher.php, 
> line 114  
> Cake\Routing\Dispatcher::dispatch() - CORE\src\Routing\Dispatcher.php, 
> line 87  
>
>

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


Validation error on "baked" date field , CakePHP 3

2015-01-08 Thread Lorne Dudley
I have a "baked" cakePHP-3.0.0 page which has a field defined as 
'date_of_birth date DEFAULT NULL' in TABLE users.  
When I click the Submit for the "add" function I get  
  
Warning (2): preg_match() expects parameter 2 to be string, array given 
[CORE\src\Validation\Validation.php, line 763]  
Code Context

protected static function _check($check, $regex)  
{ 

if (is_string($regex) && preg_match($regex, $check)) { 

$check = [  
'year' => '2014',  
'month' => '01',  
'day' => '01'  
]  
$regex = 
'%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))([-
 
/.])(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})([- 
/.])(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]$%'
  

  
Any suggestion on how to fix ?  
Regards
  
The stack trace is  

preg_match - [internal], line ??
Cake\Validation\Validation::_check() - 
CORE\src\Validation\Validation.php, line 763  
Cake\Validation\Validation::date() - 
CORE\src\Validation\Validation.php, line 346  
Cake\Validation\RulesProvider::__call() - 
CORE\src\Validation\RulesProvider.php, line 53  
Cake\Validation\RulesProvider::date() - 
CORE\src\Validation\ValidationRule.php, line 138  
    Cake\Validation\ValidationRule::process() - 
CORE\src\Validation\ValidationRule.php, line 138  
Cake\Validation\Validator::_processRules() - 
CORE\src\Validation\Validator.php, line 554  
Cake\Validation\Validator::errors() - 
CORE\src\Validation\Validator.php, line 128  
Cake\ORM\Marshaller::_validate() - CORE\src\ORM\Marshaller.php, line 
185  
Cake\ORM\Marshaller::merge() - CORE\src\ORM\Marshaller.php, line 341  
Cake\ORM\Table::patchEntity() - CORE\src\ORM\Table.php, line 1899  
App\Controller\UsersController::add() - 
APP/Controller\UsersController.php, line 48  
Cake\Controller\Controller::invokeAction() - 
CORE\src\Controller\Controller.php, line 406  
Cake\Routing\Dispatcher::_invoke() - CORE\src\Routing\Dispatcher.php, 
line 114  
Cake\Routing\Dispatcher::dispatch() - CORE\src\Routing\Dispatcher.php, 
line 87  

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


Validation error on date field , CakePHP 3

2015-01-03 Thread Paulo Homem

/**
 * Actions Model
 */
class ActionsTable extends Table {

public function validationDefault(Validator $validator) {
$validator->add('close_date', 'valid', ['rule' => 'date']);
}
..

data passed on save for close_date field :
[ 'year' => '2015', 'month' => '01','day' => '02']


error :

Warning (2): preg_match() expects parameter 2 to be string, array given 
[CORE/src/Validation/Validation.php, line 763]
 protected static function _check($check, $regex) {
 if (is_string($regex) && preg_match($regex, $check)) {
...
parameter values ...

$regex = 
'%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))([-
 
/.])(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})([- 
/.])(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]$%'

$check = [ 'year' => '2015', 'month' => '01', 'day' => '02' ] -> expecting 
String for $check parameter ?

Working two days ago, but after todays update this error apeared ..
is this a recent bug or something is missing ?


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


Custom Validation (CakePHP 3.0)

2014-12-20 Thread Alberto Domínguez
Hi all,

I'm trying to enforce password definition through Model Validation rule. I 
would like to include a RegExp validation. Is there any simple way to do 
it? Should I create a validation function? Checking the sources look like 
there is no need, however I haven't been able to perform a validation.

Any help will be appreciated.

-- 
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: How to create a provider of validation

2014-12-01 Thread Dakota
Firstly, your Validation Provider is better situated in your src/ directory 
(I personally use src/Model/Validation/Provider), so the filename will be 
src/Model/Validation/Provider/Validation.php and the FQN will be 
App\Model\Validation\Provider\Validation.php

Then in your ProjectValidation file, you would add:

$this->validator->provider('myProvider', 
'App\Model\Validation\Provider\Validation');

into your constructor.

Your '' would then simply be 'myProvider'

As for your actual validation rule, please try not to directly use SQL. 
Your query is better written as:

$count = TableRegistry::get('Catalogue')
   ->find()
   ->where(['t_identifiant' => $check])
   ->count();


On Monday, 1 December 2014 17:02:46 UTC+2, Ernaelsten Gérard wrote:
>
> Hello, 
> I try to create my own validation, But I have an error of provider because 
> I do not know what to put.
>
> //vendor/maitrepylos/Validation.php
>
> 
> namespace Maitrepylos;
>
>
> use Cake\Datasource\ConnectionManager;
>
> class Validation extends \Cake\Validation\Validation {
>
>
> public static function uniqueIdentifiant($check){
>
> $pdo = ConnectionManager::get('default');
> $sql =  'SELECT count(*) as compteur FROM catalogue WHERE 
> t_identifiant = ?';
> $r = $pdo->prepare($sql);
> $r->execute([$check]);
> $d = $r->fetch(\PDO::FETCH_OBJ);
>
> if($d->compteur > 0){
> return false;
> }
>
> return true;
>
>
>
> }
>
> }
>
>
>
> //App/Model/Validation/ProjectValidation.php
>
>  namespace App\Model\Validation;
>
>
> use Cake\Datasource\ConnectionManager;
> use Cake\Validation\Validator;
>
> class ProjectValidation
> {
> public $validator = null;
> public function __construct()
> {
> $this->validator = new Validator();
>
>
> }
>
> public function newFiche(){
>
> $this->validator->requirePresence('t_titre', true)
> ->notEmpty('t_titre', 'Le nom de la fiche ne peut être absente')
> ->notEmpty('d_date_creation','La date ne peut être vide')
> ->add('d_date_creation',[
> 'checkDate'=>[
> 'rule'=>['date','dmy'],
> 'message' => 'La date doit-être au format d/m/Y'
> ]
> ])
> ->notEmpty('t_identifiant', 'L\'identifiant ne peut être vide')
> ->add('t_identifiant',[
> 'single' =>
> [
> 'rule' => ['uniqueIdentifiant'],
> 'provider'=>'??', //I don't 
> know 
>'message' => 'test unique'
> ]
>
> ]);
>
> return $this->validator;
>
> }
>
>
> }
>
> Thank you for your help
>
>

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

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


How to create a provider of validation

2014-12-01 Thread Anthony GRASSIOT
well, i would say that at least you need to include your class by replacing
use Cake\Validation\Validate 
by
use Maitrepylos\Validation.
then maybe you need to bind a provider as explained in the doc 

http://book.cakephp.org/3.0/en/core-libraries/validation.html#adding-validation-providers
but I didn't use it yet.

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


How to create a provider of validation

2014-12-01 Thread Ernaelsten Gérard
Hello, 
I try to create my own validation, But I have an error of provider because 
I do not know what to put.

//vendor/maitrepylos/Validation.php

prepare($sql);
$r->execute([$check]);
$d = $r->fetch(\PDO::FETCH_OBJ);

if($d->compteur > 0){
return false;
}

return true;



}

}



//App/Model/Validation/ProjectValidation.php

validator = new Validator();


}

public function newFiche(){

$this->validator->requirePresence('t_titre', true)
->notEmpty('t_titre', 'Le nom de la fiche ne peut être absente')
->notEmpty('d_date_creation','La date ne peut être vide')
->add('d_date_creation',[
'checkDate'=>[
'rule'=>['date','dmy'],
'message' => 'La date doit-être au format d/m/Y'
]
])
->notEmpty('t_identifiant', 'L\'identifiant ne peut être vide')
->add('t_identifiant',[
'single' =>
[
'rule' => ['uniqueIdentifiant'],
'provider'=>'??', //I don't 
know 
   'message' => 'test unique'
]

]);

return $this->validator;

}


}

Thank you for your help

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

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


Re: cake3 validation in controller

2014-11-14 Thread cesar calvo
How do link the schema with Table Object?
You can provide an example?

I have an action "contact" in PagesController which processes the contact 
form:

//model
namespace App\Model\Table;
use Cake\Database\Schema;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class PagesTable extends Table {
public function initialize(array $config) {
$t = new Schema\Table('pages');
$t->addColumn('email', 'string')
  ->addColumn('name', 'string')
  ->addColumn('subject', 'string')
  ->addColumn('content', 'string');
}
}

regards --cesar

El viernes, 14 de noviembre de 2014 09:32:15 UTC-2, Florian Krämer escribió:
>
> Create a table / model object with a schema but no table and use it as 
> usual. The controller should be tiny and models fat.
>
> <http://i.stack.imgur.com/UrtaH.png>
>
>
> On Thursday, November 13, 2014 1:58:42 PM UTC+1, cesar calvo wrote:
>>
>> It is possible show in a form the error messages with no model 
>> associated? Obviously using the Form helper. 
>> I see validating-data 
>> <http://book.cakephp.org/3.0/en/core-libraries/validation.html#validating-data>,
>>  
>> but I need some guidance about the feasibility automatically display errors 
>> like when work with a model
>>
>> //view
>> > $this->Form->create(),
>> $this->Form->input('name', ['label' => __('Name')]),
>> $this->Form->input('email', ['label' => __('Email')]),
>> $this->Form->input('subject', ['label' => __('Subject')]),
>> $this->Form->input('message', ['label' => __('Message'), 'type' => 
>> 'textarea', 'rows' => '3']),
>> $this->Form->button(__('Submit')),
>> $this->Form->end()
>> ?>
>>
>> //controller
>> public function contact() {
>> if ($this->request->is('post')) {
>> $validator = new Validator();
>> $validator
>> ->validatePresence('email')
>> ->notEmpty('email', __('This field is required.'))
>> ->add('email', 'valid', ['rule' => 'email', 'message' => 
>> __('This field requires a valid email address.')])
>> ->validatePresence('name')
>> ->notEmpty('name', __('This field is required.'))
>> ->validatePresence('subject')
>> ->notEmpty('subject', __('This field is required.'))
>> ->validatePresence('message')
>> ->notEmpty('message', __('This field is required.'))
>> ;
>> $errors = $validator->errors($this->request->data);
>> if (empty($errors)) {
>> $this->Flash->success(__('Your data has been sent 
>> succesfully.'));
>> } else {
>> $this->Flash->error(__('Unable to sent your data.'));
>> }
>> }
>> }
>>
>> best regards
>>
>

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

2014-11-14 Thread Florian Krämer
Create a table / model object with a schema but no table and use it as 
usual. The controller should be tiny and models fat.




On Thursday, November 13, 2014 1:58:42 PM UTC+1, cesar calvo wrote:
>
> It is possible show in a form the error messages with no model associated? 
> Obviously using the Form helper. 
> I see validating-data 
> ,
>  
> but I need some guidance about the feasibility automatically display errors 
> like when work with a model
>
> //view
>  $this->Form->create(),
> $this->Form->input('name', ['label' => __('Name')]),
> $this->Form->input('email', ['label' => __('Email')]),
> $this->Form->input('subject', ['label' => __('Subject')]),
> $this->Form->input('message', ['label' => __('Message'), 'type' => 
> 'textarea', 'rows' => '3']),
> $this->Form->button(__('Submit')),
> $this->Form->end()
> ?>
>
> //controller
> public function contact() {
> if ($this->request->is('post')) {
> $validator = new Validator();
> $validator
> ->validatePresence('email')
> ->notEmpty('email', __('This field is required.'))
> ->add('email', 'valid', ['rule' => 'email', 'message' => 
> __('This field requires a valid email address.')])
> ->validatePresence('name')
> ->notEmpty('name', __('This field is required.'))
> ->validatePresence('subject')
> ->notEmpty('subject', __('This field is required.'))
> ->validatePresence('message')
> ->notEmpty('message', __('This field is required.'))
> ;
> $errors = $validator->errors($this->request->data);
> if (empty($errors)) {
> $this->Flash->success(__('Your data has been sent 
> succesfully.'));
> } else {
> $this->Flash->error(__('Unable to sent your data.'));
> }
> }
> }
>
> best regards
>

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


cake3 validation in controller

2014-11-13 Thread cesar calvo
It is possible show in a form the error messages with no model associated? 
Obviously using the Form helper. 
I see validating-data 
,
 
but I need some guidance about the feasibility automatically display errors 
like when work with a model

//view
Form->create(),
$this->Form->input('name', ['label' => __('Name')]),
$this->Form->input('email', ['label' => __('Email')]),
$this->Form->input('subject', ['label' => __('Subject')]),
$this->Form->input('message', ['label' => __('Message'), 'type' => 
'textarea', 'rows' => '3']),
$this->Form->button(__('Submit')),
$this->Form->end()
?>

//controller
public function contact() {
if ($this->request->is('post')) {
$validator = new Validator();
$validator
->validatePresence('email')
->notEmpty('email', __('This field is required.'))
->add('email', 'valid', ['rule' => 'email', 'message' => 
__('This field requires a valid email address.')])
->validatePresence('name')
->notEmpty('name', __('This field is required.'))
->validatePresence('subject')
->notEmpty('subject', __('This field is required.'))
->validatePresence('message')
->notEmpty('message', __('This field is required.'))
;
$errors = $validator->errors($this->request->data);
if (empty($errors)) {
$this->Flash->success(__('Your data has been sent 
succesfully.'));
} else {
$this->Flash->error(__('Unable to sent your data.'));
}
}
}

best regards

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

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&#x

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()
>>> ?>
>>>
>>>

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

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'

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


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.


Re: validation criteria at least 3 fileds are not empty

2014-10-28 Thread José Lorenzo
You are correct. With custom validation methods or with the validation 
callbacks you can extend the validation process to to more than what it is 
designed to do.

On Tuesday, October 28, 2014 8:06:19 AM UTC+1, Radharadhya Dasa wrote:
>
> As I understand validation handles only one filed. Am I wrong?
>
> rrd
>
> 2014. október 26., vasárnap 19:33:14 UTC+1 időpontban John Andersen a 
> következőt írta:
>>
>> Good to see that you are trying to solve this :)
>>
>> I would still have gone with rolling my own validation, just by extending 
>> the validator, so it can validate a record also, not only fields.
>>
>> Anyway, I am not moving to CakePHP 3.x, so will not be able to give 
>> further ideas on that, but I do hope you find a solution in the end.
>>
>> Enjoy, John
>>
>> On Thursday, 23 October 2014 12:12:11 UTC+3, Radharadhya Dasa wrote:
>>>
>>> I checked to cookbook and find out that validation handles singe fields. 
>>> So I used beforeSave for this.
>>>
>>> public function beforeSave(Event $event, Entity $entity, ArrayObject 
>>> $options){
>>> if((!empty($entity->name) + !empty($entity->contactname) + !empty(
>>> $entity->zip_id)
>>>   + !empty($entity->address) + !empty($entity->phone) + !empty(
>>> $entity->email)
>>>   + !empty($entity->birth->time)) >= 3){
>>> return true;
>>> }
>>> else{
>>> //Error: __('At least 3 info should be filled');
>>> return false;
>>> }
>>> }
>>>
>>> But I have a problem and a question.
>>>
>>> The above gives me this error message:
>>>
>>> *Warning* (4096): Argument 1 passed to 
>>> App\Model\Table\ContactsTable::beforeSave() must be an instance of 
>>> App\Model\Table\Event, instance of Cake\Event\Event given, called in 
>>> /home/rrd/public_html/sanga/vendor/cakephp/cakephp/src/Event/EventManager.php
>>>  on line 266 and defined [*APP/Model/Table/ContactsTable.php*, line *85*]
>>>
>>> What is the proper way to do it?
>>>
>>> The question is how to define an error message what will be flashed to the 
>>> user?
>>>
>>>
>>>
>>>
>>>
>>> 2014. október 18., szombat 15:41:28 UTC+2 időpontban John Andersen a 
>>> következőt írta:
>>>>
>>>> Assuming you are still using CakePHP 3.0
>>>>
>>>> I have not seen any built-in rules for this kind of validation, so my 
>>>> best guess is to roll your own.
>>>> See section "Custom Validation Rules" under "Validation" in the CakePHP 
>>>> 3.0 book. That should help you on the way.
>>>>
>>>> Enjoy, John
>>>>
>>>> On Saturday, 18 October 2014 16:21:57 UTC+3, Radharadhya Dasa wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Is there a way to check if at least 3 fileds are not empty? I have 8 
>>>>> fileds and any of those could be empty, but at least 3 of them should be 
>>>>> not empty. Is there any build in validation rule, or how to do it? Should 
>>>>> I 
>>>>> do it on beforeSave?
>>>>>
>>>>> rrd
>>>>>
>>>>

-- 
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: validation criteria at least 3 fileds are not empty

2014-10-28 Thread Radharadhya Dasa
As I understand validation handles only one filed. Am I wrong?

rrd

2014. október 26., vasárnap 19:33:14 UTC+1 időpontban John Andersen a 
következőt írta:
>
> Good to see that you are trying to solve this :)
>
> I would still have gone with rolling my own validation, just by extending 
> the validator, so it can validate a record also, not only fields.
>
> Anyway, I am not moving to CakePHP 3.x, so will not be able to give 
> further ideas on that, but I do hope you find a solution in the end.
>
> Enjoy, John
>
> On Thursday, 23 October 2014 12:12:11 UTC+3, Radharadhya Dasa wrote:
>>
>> I checked to cookbook and find out that validation handles singe fields. 
>> So I used beforeSave for this.
>>
>> public function beforeSave(Event $event, Entity $entity, ArrayObject 
>> $options){
>> if((!empty($entity->name) + !empty($entity->contactname) + !empty(
>> $entity->zip_id)
>>   + !empty($entity->address) + !empty($entity->phone) + !empty(
>> $entity->email)
>>   + !empty($entity->birth->time)) >= 3){
>> return true;
>> }
>> else{
>> //Error: __('At least 3 info should be filled');
>> return false;
>> }
>> }
>>
>> But I have a problem and a question.
>>
>> The above gives me this error message:
>>
>> *Warning* (4096): Argument 1 passed to 
>> App\Model\Table\ContactsTable::beforeSave() must be an instance of 
>> App\Model\Table\Event, instance of Cake\Event\Event given, called in 
>> /home/rrd/public_html/sanga/vendor/cakephp/cakephp/src/Event/EventManager.php
>>  on line 266 and defined [*APP/Model/Table/ContactsTable.php*, line *85*]
>>
>> What is the proper way to do it?
>>
>> The question is how to define an error message what will be flashed to the 
>> user?
>>
>>
>>
>>
>>
>> 2014. október 18., szombat 15:41:28 UTC+2 időpontban John Andersen a 
>> következőt írta:
>>>
>>> Assuming you are still using CakePHP 3.0
>>>
>>> I have not seen any built-in rules for this kind of validation, so my 
>>> best guess is to roll your own.
>>> See section "Custom Validation Rules" under "Validation" in the CakePHP 
>>> 3.0 book. That should help you on the way.
>>>
>>> Enjoy, John
>>>
>>> On Saturday, 18 October 2014 16:21:57 UTC+3, Radharadhya Dasa wrote:
>>>>
>>>> Hi,
>>>>
>>>> Is there a way to check if at least 3 fileds are not empty? I have 8 
>>>> fileds and any of those could be empty, but at least 3 of them should be 
>>>> not empty. Is there any build in validation rule, or how to do it? Should 
>>>> I 
>>>> do it on beforeSave?
>>>>
>>>> rrd
>>>>
>>>

-- 
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: validation criteria at least 3 fileds are not empty

2014-10-26 Thread John Andersen
Good to see that you are trying to solve this :)

I would still have gone with rolling my own validation, just by extending 
the validator, so it can validate a record also, not only fields.

Anyway, I am not moving to CakePHP 3.x, so will not be able to give further 
ideas on that, but I do hope you find a solution in the end.

Enjoy, John

On Thursday, 23 October 2014 12:12:11 UTC+3, Radharadhya Dasa wrote:
>
> I checked to cookbook and find out that validation handles singe fields. 
> So I used beforeSave for this.
>
> public function beforeSave(Event $event, Entity $entity, ArrayObject 
> $options){
> if((!empty($entity->name) + !empty($entity->contactname) + !empty(
> $entity->zip_id)
>   + !empty($entity->address) + !empty($entity->phone) + !empty(
> $entity->email)
>   + !empty($entity->birth->time)) >= 3){
> return true;
> }
> else{
> //Error: __('At least 3 info should be filled');
> return false;
> }
> }
>
> But I have a problem and a question.
>
> The above gives me this error message:
>
> *Warning* (4096): Argument 1 passed to 
> App\Model\Table\ContactsTable::beforeSave() must be an instance of 
> App\Model\Table\Event, instance of Cake\Event\Event given, called in 
> /home/rrd/public_html/sanga/vendor/cakephp/cakephp/src/Event/EventManager.php 
> on line 266 and defined [*APP/Model/Table/ContactsTable.php*, line *85*]
>
> What is the proper way to do it?
>
> The question is how to define an error message what will be flashed to the 
> user?
>
>
>
>
>
> 2014. október 18., szombat 15:41:28 UTC+2 időpontban John Andersen a 
> következőt írta:
>>
>> Assuming you are still using CakePHP 3.0
>>
>> I have not seen any built-in rules for this kind of validation, so my 
>> best guess is to roll your own.
>> See section "Custom Validation Rules" under "Validation" in the CakePHP 
>> 3.0 book. That should help you on the way.
>>
>> Enjoy, John
>>
>> On Saturday, 18 October 2014 16:21:57 UTC+3, Radharadhya Dasa wrote:
>>>
>>> Hi,
>>>
>>> Is there a way to check if at least 3 fileds are not empty? I have 8 
>>> fileds and any of those could be empty, but at least 3 of them should be 
>>> not empty. Is there any build in validation rule, or how to do it? Should I 
>>> do it on beforeSave?
>>>
>>> rrd
>>>
>>

-- 
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: validation criteria at least 3 fileds are not empty

2014-10-24 Thread Radharadhya Dasa
I went forward.

So in the model we need
use ArrayObject;
use Cake\Event\Event;


Adding error message in beforeSave

$entity->errors('name', __('At least 2 info should be filled'));


In the controller you will find it in
$contact = $this->Contacts->newEntity($this->request->data);
debug($contact->errors());

But this is not what cake makes its automagic rules... So further digging 
needed.


2014. október 23., csütörtök 11:12:11 UTC+2 időpontban Radharadhya Dasa a 
következőt írta:
>
> I checked to cookbook and find out that validation handles singe fields. 
> So I used beforeSave for this.
>
> public function beforeSave(Event $event, Entity $entity, ArrayObject 
> $options){
> if((!empty($entity->name) + !empty($entity->contactname) + !empty(
> $entity->zip_id)
>   + !empty($entity->address) + !empty($entity->phone) + !empty(
> $entity->email)
>   + !empty($entity->birth->time)) >= 3){
> return true;
> }
> else{
> //Error: __('At least 3 info should be filled');
> return false;
> }
> }
>
> But I have a problem and a question.
>
> The above gives me this error message:
>
> *Warning* (4096): Argument 1 passed to 
> App\Model\Table\ContactsTable::beforeSave() must be an instance of 
> App\Model\Table\Event, instance of Cake\Event\Event given, called in 
> /home/rrd/public_html/sanga/vendor/cakephp/cakephp/src/Event/EventManager.php 
> on line 266 and defined [*APP/Model/Table/ContactsTable.php*, line *85*]
>
> What is the proper way to do it?
>
> The question is how to define an error message what will be flashed to the 
> user?
>
>
>
>
>
> 2014. október 18., szombat 15:41:28 UTC+2 időpontban John Andersen a 
> következőt írta:
>>
>> Assuming you are still using CakePHP 3.0
>>
>> I have not seen any built-in rules for this kind of validation, so my 
>> best guess is to roll your own.
>> See section "Custom Validation Rules" under "Validation" in the CakePHP 
>> 3.0 book. That should help you on the way.
>>
>> Enjoy, John
>>
>> On Saturday, 18 October 2014 16:21:57 UTC+3, Radharadhya Dasa wrote:
>>>
>>> Hi,
>>>
>>> Is there a way to check if at least 3 fileds are not empty? I have 8 
>>> fileds and any of those could be empty, but at least 3 of them should be 
>>> not empty. Is there any build in validation rule, or how to do it? Should I 
>>> do it on beforeSave?
>>>
>>> rrd
>>>
>>

-- 
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: validation criteria at least 3 fileds are not empty

2014-10-23 Thread Radharadhya Dasa
I checked to cookbook and find out that validation handles singe fields. So 
I used beforeSave for this.

public function beforeSave(Event $event, Entity $entity, ArrayObject 
$options){
if((!empty($entity->name) + !empty($entity->contactname) + !empty(
$entity->zip_id)
  + !empty($entity->address) + !empty($entity->phone) + !empty(
$entity->email)
  + !empty($entity->birth->time)) >= 3){
return true;
}
else{
//Error: __('At least 3 info should be filled');
return false;
}
}

But I have a problem and a question.

The above gives me this error message:

*Warning* (4096): Argument 1 passed to 
App\Model\Table\ContactsTable::beforeSave() must be an instance of 
App\Model\Table\Event, instance of Cake\Event\Event given, called in 
/home/rrd/public_html/sanga/vendor/cakephp/cakephp/src/Event/EventManager.php 
on line 266 and defined [*APP/Model/Table/ContactsTable.php*, line *85*]

What is the proper way to do it?

The question is how to define an error message what will be flashed to the user?





2014. október 18., szombat 15:41:28 UTC+2 időpontban John Andersen a 
következőt írta:
>
> Assuming you are still using CakePHP 3.0
>
> I have not seen any built-in rules for this kind of validation, so my best 
> guess is to roll your own.
> See section "Custom Validation Rules" under "Validation" in the CakePHP 
> 3.0 book. That should help you on the way.
>
> Enjoy, John
>
> On Saturday, 18 October 2014 16:21:57 UTC+3, Radharadhya Dasa wrote:
>>
>> Hi,
>>
>> Is there a way to check if at least 3 fileds are not empty? I have 8 
>> fileds and any of those could be empty, but at least 3 of them should be 
>> not empty. Is there any build in validation rule, or how to do it? Should I 
>> do it on beforeSave?
>>
>> rrd
>>
>

-- 
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: validation criteria at least 3 fileds are not empty

2014-10-18 Thread John Andersen
Assuming you are still using CakePHP 3.0

I have not seen any built-in rules for this kind of validation, so my best 
guess is to roll your own.
See section "Custom Validation Rules" under "Validation" in the CakePHP 3.0 
book. That should help you on the way.

Enjoy, John

On Saturday, 18 October 2014 16:21:57 UTC+3, Radharadhya Dasa wrote:
>
> Hi,
>
> Is there a way to check if at least 3 fileds are not empty? I have 8 
> fileds and any of those could be empty, but at least 3 of them should be 
> not empty. Is there any build in validation rule, or how to do it? Should I 
> do it on beforeSave?
>
> rrd
>

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


validation criteria at least 3 fileds are not empty

2014-10-18 Thread Radharadhya Dasa
Hi,

Is there a way to check if at least 3 fileds are not empty? I have 8 fileds 
and any of those could be empty, but at least 3 of them should be not 
empty. Is there any build in validation rule, or how to do it? Should I do 
it on beforeSave?

rrd

-- 
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: Model Validation

2014-07-31 Thread Stephen S
Are you submitting the entire form or individual fields via ajax?

If you're submitting the entire form and returning HTML, make sure to set
your $invalidFields variable which you have and check
if(isset($invalidFields)) in your returned html to highlight the fields. If
you're still not sure please post your ajax code as well as all the
relevant controller code so we can see exactly what you are doing wrong.
Thanks


On 31 July 2014 09:37, Sudhir Pandey  wrote:

> Thanks for your response , but I submitting the form by ajax & then
> validate. I have encode the error & get it on success method of ajax. The
> problem arising  How can I show these error message .
>
> I want model validation using ajax
>
>
> On Wednesday, 30 July 2014 14:59:03 UTC+5:30, Dr. Tarique Sani wrote:
>
>> Start here http://bit.ly/UKovlN
>>
>> If you get stuck with a method you choose ask further questions.
>>
>> Tarique
>>
>>
>> On Wed, Jul 30, 2014 at 2:40 PM, Sudhir Pandey  wrote:
>>
>>> How can I perform cakephp Model validation using ajax & shows error
>>> message.
>>>
>>> I have already set the error message in controller but not shown in view.
>>>
>>> $this->Candidateprofile->set($this->data);
>>> if($this->Candidateprofile->validates())
>>> {
>>> $this->Candidateprofile->create();
>>> if($this->Candidateprofile->saveAll($this->data)) {
>>>  }else{
>>> $invalidFields=$this->Candidateprofile->invalidFields();
>>>  $this->set('invalidFields',$invalidFields);
>>> }
>>> }else{
>>> $invalidFields=$this->Candidateprofile->invalidFields();
>>>  $this->set('invalidFields',$invalidFields);
>>> }
>>>
>>> --
>>> 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+u...@googlegroups.com.
>>> To post to this group, send email to cake...@googlegroups.com.
>>>
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> =
>> The Conference Schedule Creator : http://shdlr.com
>>
>> PHP for E-Biz : http://sanisoft.com
>> =
>>
>  --
> 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.
>



-- 
Kind Regards
 Stephen Speakman

-- 
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: Model Validation

2014-07-31 Thread Sudhir Pandey
Thanks for your response , but I submitting the form by ajax & then 
validate. I have encode the error & get it on success method of ajax. The 
problem arising  How can I show these error message .

I want model validation using ajax 

On Wednesday, 30 July 2014 14:59:03 UTC+5:30, Dr. Tarique Sani wrote:
>
> Start here http://bit.ly/UKovlN
>
> If you get stuck with a method you choose ask further questions.
>
> Tarique
>
>
> On Wed, Jul 30, 2014 at 2:40 PM, Sudhir Pandey  > wrote:
>
>> How can I perform cakephp Model validation using ajax & shows error 
>> message.
>>
>> I have already set the error message in controller but not shown in view.
>>
>> $this->Candidateprofile->set($this->data);
>> if($this->Candidateprofile->validates())
>> {
>> $this->Candidateprofile->create();
>> if($this->Candidateprofile->saveAll($this->data)) {
>>  }else{
>> $invalidFields=$this->Candidateprofile->invalidFields();
>>  $this->set('invalidFields',$invalidFields);
>> }
>> }else{
>> $invalidFields=$this->Candidateprofile->invalidFields();
>>  $this->set('invalidFields',$invalidFields);
>> }
>>
>> -- 
>> 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+u...@googlegroups.com .
>> To post to this group, send email to cake...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> =
> The Conference Schedule Creator : http://shdlr.com
>
> PHP for E-Biz : http://sanisoft.com
> = 
>

-- 
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: Display Form Validation Errors CakePHP 3

2014-07-30 Thread José Lorenzo
Glad it worked :)

On Wednesday, July 30, 2014 3:35:21 PM UTC+2, Jipson Thomas wrote:
>
> Hi Jose Lorenzo,
> Thank you very much. Now it is working perfectly.
> Regards,
> Jipson
>
> On Wednesday, 30 July 2014 14:31:30 UTC+1, José Lorenzo wrote:
>>
>> Ok, you problem is that you are calling create() without the entity, You 
>> should get that fixed by doing:
>>
>> Form->create($package) ?>
>>
>> On Wednesday, July 30, 2014 3:29:33 PM UTC+2, Jipson Thomas wrote:
>>>
>>> Hi Jose Lorenzo,
>>> Thank you for the reply. Please find the below code 
>>>
>>> *CTP*
>>> ==
>>> 
>>> Flash->render('auth') ?>
>>> Form->create() ?>
>>> 
>>> >> ?>
>>>Form->input('name', ['label' => 'Package 
>>> Name']); ?>
>>>Form->input('annual_price', ['label' => 'Price 
>>> / Year','type' => 'decimal']); ?>
>>>Form->input('monthly_price', ['label' => 'Price 
>>> / Month','type' => 'decimal']); ?>
>>>Form->input('duration', ['label' => 'Minimum 
>>> Months of Contract','type' => 'integer']);?>
>>>Form->input('no_partners', ['label' => 'Maximum 
>>> No of Partners','type' => 'integer']);?>
>>>Form->input('no_emails', ['label' => 'Maximum 
>>> No of Emails/Month','type' => 'integer']);?>
>>>Form->input('storage', ['label' => 'Maximum 
>>> Allowed Storage Space (GB)','type' => 'integer']);?>
>>>Form->input('resource_library', ['label' => 
>>> 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => 
>>> 'N']);?> 
>>>Form->input('portal_cms', ['label' => 'Portal 
>>> CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?>
>>>Form->input('MDF', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>>Form->input('deal_registration', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>>>Form->input('partner_recruit', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>>>Form->input('training', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>>Form->input('Socialmedia', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>>>Form->input('multilingual', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>>Form->input('partner_incentive', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>>Form->input('partner_app', ['type' => 
>>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>>
>>> 
>>> Form->button(__('Save')); ?>
>>> Form->end() ?>
>>> 
>>>
>>> *Controller Action*
>>> ==
>>> public function add(){
>>> $package = $this->Package->newEntity($this->request->data);
>>> if ($this->request->is('post')) {
>>> if ($this->Package->save($package)) {
>>> $this->Flash->success(__('The package has been saved.'));
>>> return $this->redirect(['action' => 'inde

Re: Display Form Validation Errors CakePHP 3

2014-07-30 Thread Jipson Thomas
Hi Jose Lorenzo,
Thank you very much. Now it is working perfectly.
Regards,
Jipson

On Wednesday, 30 July 2014 14:31:30 UTC+1, José Lorenzo wrote:
>
> Ok, you problem is that you are calling create() without the entity, You 
> should get that fixed by doing:
>
> Form->create($package) ?>
>
> On Wednesday, July 30, 2014 3:29:33 PM UTC+2, Jipson Thomas wrote:
>>
>> Hi Jose Lorenzo,
>> Thank you for the reply. Please find the below code 
>>
>> *CTP*
>> ==
>> 
>> Flash->render('auth') ?>
>> Form->create() ?>
>> 
>> > ?>
>>Form->input('name', ['label' => 'Package 
>> Name']); ?>
>>Form->input('annual_price', ['label' => 'Price / 
>> Year','type' => 'decimal']); ?>
>>Form->input('monthly_price', ['label' => 'Price 
>> / Month','type' => 'decimal']); ?>
>>Form->input('duration', ['label' => 'Minimum 
>> Months of Contract','type' => 'integer']);?>
>>Form->input('no_partners', ['label' => 'Maximum 
>> No of Partners','type' => 'integer']);?>
>>Form->input('no_emails', ['label' => 'Maximum No 
>> of Emails/Month','type' => 'integer']);?>
>>Form->input('storage', ['label' => 'Maximum 
>> Allowed Storage Space (GB)','type' => 'integer']);?>
>>Form->input('resource_library', ['label' => 
>> 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => 
>> 'N']);?> 
>>Form->input('portal_cms', ['label' => 'Portal 
>> CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?>
>>Form->input('MDF', ['type' => 'checkbox','value' 
>> => 'Y','hiddenField' => 'N']);?>
>>Form->input('deal_registration', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>>Form->input('partner_recruit', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>>Form->input('training', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>Form->input('Socialmedia', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>>Form->input('multilingual', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>Form->input('partner_incentive', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>Form->input('partner_app', ['type' => 
>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>>
>> 
>> Form->button(__('Save')); ?>
>> Form->end() ?>
>> 
>>
>> *Controller Action*
>> ==
>> public function add(){
>> $package = $this->Package->newEntity($this->request->data);
>> if ($this->request->is('post')) {
>> if ($this->Package->save($package)) {
>> $this->Flash->success(__('The package has been saved.'));
>> return $this->redirect(['action' => 'index']);
>> }
>> else{
>>   //  $errors = $this->Package->errors();
>> 
>> $error_string=  implode('\n',$package->errors());
>> //print_r($package);
>> }
>> $this->Flash->error(__('Unable to add the packa

Re: Display Form Validation Errors CakePHP 3

2014-07-30 Thread José Lorenzo
Ok, you problem is that you are calling create() without the entity, You 
should get that fixed by doing:

Form->create($package) ?>

On Wednesday, July 30, 2014 3:29:33 PM UTC+2, Jipson Thomas wrote:
>
> Hi Jose Lorenzo,
> Thank you for the reply. Please find the below code 
>
> *CTP*
> ==
> 
> Flash->render('auth') ?>
> Form->create() ?>
> 
>  ?>
>Form->input('name', ['label' => 'Package Name']); 
> ?>
>Form->input('annual_price', ['label' => 'Price / 
> Year','type' => 'decimal']); ?>
>Form->input('monthly_price', ['label' => 'Price / 
> Month','type' => 'decimal']); ?>
>Form->input('duration', ['label' => 'Minimum 
> Months of Contract','type' => 'integer']);?>
>Form->input('no_partners', ['label' => 'Maximum 
> No of Partners','type' => 'integer']);?>
>Form->input('no_emails', ['label' => 'Maximum No 
> of Emails/Month','type' => 'integer']);?>
>Form->input('storage', ['label' => 'Maximum 
> Allowed Storage Space (GB)','type' => 'integer']);?>
>Form->input('resource_library', ['label' => 
> 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => 
> 'N']);?> 
>Form->input('portal_cms', ['label' => 'Portal 
> CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?>
>Form->input('MDF', ['type' => 'checkbox','value' 
> => 'Y','hiddenField' => 'N']);?>
>Form->input('deal_registration', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>Form->input('partner_recruit', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>Form->input('training', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>Form->input('Socialmedia', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
>Form->input('multilingual', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>Form->input('partner_incentive', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>Form->input('partner_app', ['type' => 
> 'checkbox','value' => 'Y','hiddenField' => 'N']);?>
>
> 
> Form->button(__('Save')); ?>
> Form->end() ?>
> 
>
> *Controller Action*
> ==
> public function add(){
> $package = $this->Package->newEntity($this->request->data);
> if ($this->request->is('post')) {
> if ($this->Package->save($package)) {
> $this->Flash->success(__('The package has been saved.'));
>     return $this->redirect(['action' => 'index']);
> }
> else{
>   //  $errors = $this->Package->errors();
> 
> $error_string=  implode('\n',$package->errors());
> //print_r($package);
> }
> $this->Flash->error(__('Unable to add the package.'));
> }
> $this->set('package', $package);
> }
>
> *Model - Table Class*
> =
> class PackagesTable extends Table {
> public function initialize(array $config) {
> $this->addBehavior('Timestamp', [
> 'events' => [
> 'Model.beforeSave' => [
> 'created_on'

Re: Display Form Validation Errors CakePHP 3

2014-07-30 Thread Jipson Thomas
Hi Jose Lorenzo,
Thank you for the reply. Please find the below code 

*CTP*
==

Flash->render('auth') ?>
Form->create() ?>


   Form->input('name', ['label' => 'Package Name']); 
?>
   Form->input('annual_price', ['label' => 'Price / 
Year','type' => 'decimal']); ?>
   Form->input('monthly_price', ['label' => 'Price / 
Month','type' => 'decimal']); ?>
   Form->input('duration', ['label' => 'Minimum 
Months of Contract','type' => 'integer']);?>
   Form->input('no_partners', ['label' => 'Maximum No 
of Partners','type' => 'integer']);?>
   Form->input('no_emails', ['label' => 'Maximum No 
of Emails/Month','type' => 'integer']);?>
   Form->input('storage', ['label' => 'Maximum 
Allowed Storage Space (GB)','type' => 'integer']);?>
   Form->input('resource_library', ['label' => 
'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => 
'N']);?> 
   Form->input('portal_cms', ['label' => 'Portal 
CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?>
   Form->input('MDF', ['type' => 'checkbox','value' 
=> 'Y','hiddenField' => 'N']);?>
   Form->input('deal_registration', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
   Form->input('partner_recruit', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
   Form->input('training', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?>
   Form->input('Socialmedia', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?> 
   Form->input('multilingual', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?>
   Form->input('partner_incentive', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?>
   Form->input('partner_app', ['type' => 
'checkbox','value' => 'Y','hiddenField' => 'N']);?>
   

Form->button(__('Save')); ?>
Form->end() ?>


*Controller Action*
==
public function add(){
$package = $this->Package->newEntity($this->request->data);
if ($this->request->is('post')) {
if ($this->Package->save($package)) {
$this->Flash->success(__('The package has been saved.'));
return $this->redirect(['action' => 'index']);
}
    else{
      //  $errors = $this->Package->errors();
    
$error_string=  implode('\n',$package->errors());
//print_r($package);
}
$this->Flash->error(__('Unable to add the package.'));
}
$this->set('package', $package);
}

*Model - Table Class*
=
class PackagesTable extends Table {
public function initialize(array $config) {
$this->addBehavior('Timestamp', [
'events' => [
'Model.beforeSave' => [
'created_on' => 'new',
'modified_on' => 'always',
]

]
]);
}
public function validationDefault(Validator $validator) {
$validator
->notEmpty('name','A valid package name is required')
->notEmpty('annual_price','A valid annual price is required')
->notEmpty('monthly_price','A valid monthly price is required')
->notEmpty('duration','Minimum duration of contract is 
requi

Re: Display Form Validation Errors CakePHP 3

2014-07-30 Thread José Lorenzo
There does not seem to be any Form->create() call in that code you pasted. 
Can you share the full code?

On Wednesday, July 30, 2014 3:20:54 PM UTC+2, Jipson Thomas wrote:
>
> Hi ,
> On my package creation form I am using cakephp validation. The validation 
> is working perfectly. Unfortunately the validation error messages are not 
> displaying on my form. Would you please help me on this?
>
> The code I am using is as follows. Please advise me what I am missing here.
>
> *My Table Class*
> ==
> public function validationDefault(Validator $validator) {
> $validator
> ->notEmpty('name','A valid package name is required')
> ->notEmpty('annual_price','A valid annual price is required')
> ->notEmpty('monthly_price','A valid monthly price is required')
> ->notEmpty('duration','Minimum duration of contract is 
> required')
> ->notEmpty('no_partners','Maximum no of partners is required')
> ->notEmpty('no_emails','Maximum no of emails per month is 
> required');
>
> return $validator;
> }
>
> *On my controller*
> 
> I am using the following codes to get the validation result.
> $package = $this->Package->newEntity($this->request->data);
> if ($this->SubscriptionPackage->save($package)) {
> $this->Flash->success(__('The package has been saved.'));
> return $this->redirect(['action' => 'index']);
> }
> else{
> //print_r($package->errors()); It will display an array with field names 
> and message.
> }
>
> *On my ctp file I am using the following code.*
> 
>  Form->input('name', ['label' => 'Package Name']); ?>
>Form->input('annual_price', ['label' => 'Price / 
> Year','type' => 'decimal']); ?>
>Form->input('monthly_price', ['label' => 'Price / 
> Month','type' => 'decimal']); ?>
>Form->input('duration', ['label' => 'Minimum 
> Months of Contract','type' => 'integer']);?>
>Form->input('no_partners', ['label' => 'Maximum 
> No of Partners','type' => 'integer']);?>
>Form->input('no_emails', ['label' => 'Maximum No 
> of Emails/Month','type' => 'integer']);?>
>Form->input('storage', ['label' => 'Maximum 
> Allowed Storage Space (GB)','type' =>?>
>

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


Display Form Validation Errors CakePHP 3

2014-07-30 Thread Jipson Thomas
Hi ,
On my package creation form I am using cakephp validation. The validation 
is working perfectly. Unfortunately the validation error messages are not 
displaying on my form. Would you please help me on this?

The code I am using is as follows. Please advise me what I am missing here.

*My Table Class*
==
public function validationDefault(Validator $validator) {
$validator
->notEmpty('name','A valid package name is required')
->notEmpty('annual_price','A valid annual price is required')
->notEmpty('monthly_price','A valid monthly price is required')
->notEmpty('duration','Minimum duration of contract is 
required')
->notEmpty('no_partners','Maximum no of partners is required')
->notEmpty('no_emails','Maximum no of emails per month is 
required');

return $validator;
}

*On my controller*

I am using the following codes to get the validation result.
$package = $this->Package->newEntity($this->request->data);
if ($this->SubscriptionPackage->save($package)) {
$this->Flash->success(__('The package has been saved.'));
return $this->redirect(['action' => 'index']);
}
else{
//print_r($package->errors()); It will display an array with field names 
and message.
}

*On my ctp file I am using the following code.*

 Form->input('name', ['label' => 'Package Name']); ?>
   Form->input('annual_price', ['label' => 'Price / 
Year','type' => 'decimal']); ?>
   Form->input('monthly_price', ['label' => 'Price / 
Month','type' => 'decimal']); ?>
   Form->input('duration', ['label' => 'Minimum 
Months of Contract','type' => 'integer']);?>
   Form->input('no_partners', ['label' => 'Maximum No 
of Partners','type' => 'integer']);?>
   Form->input('no_emails', ['label' => 'Maximum No 
of Emails/Month','type' => 'integer']);?>
   Form->input('storage', ['label' => 'Maximum 
Allowed Storage Space (GB)','type' =>?>

-- 
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: Model Validation

2014-07-30 Thread Dr. Tarique Sani
Start here http://bit.ly/UKovlN

If you get stuck with a method you choose ask further questions.

Tarique


On Wed, Jul 30, 2014 at 2:40 PM, Sudhir Pandey  wrote:

> How can I perform cakephp Model validation using ajax & shows error
> message.
>
> I have already set the error message in controller but not shown in view.
>
> $this->Candidateprofile->set($this->data);
> if($this->Candidateprofile->validates())
> {
> $this->Candidateprofile->create();
> if($this->Candidateprofile->saveAll($this->data)) {
>  }else{
> $invalidFields=$this->Candidateprofile->invalidFields();
> $this->set('invalidFields',$invalidFields);
> }
> }else{
> $invalidFields=$this->Candidateprofile->invalidFields();
> $this->set('invalidFields',$invalidFields);
> }
>
> --
> 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.
>



-- 
=
The Conference Schedule Creator : http://shdlr.com

PHP for E-Biz : http://sanisoft.com
=

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

2014-07-30 Thread Sudhir Pandey
How can I perform cakephp Model validation using ajax & shows error message.

I have already set the error message in controller but not shown in view.

$this->Candidateprofile->set($this->data);
if($this->Candidateprofile->validates())
{
$this->Candidateprofile->create();
if($this->Candidateprofile->saveAll($this->data)) {
 }else{
$invalidFields=$this->Candidateprofile->invalidFields();
$this->set('invalidFields',$invalidFields);
}
}else{
$invalidFields=$this->Candidateprofile->invalidFields();
$this->set('invalidFields',$invalidFields);
}

-- 
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: CakePHP 3.0 Validation ?

2014-07-28 Thread José Lorenzo
You can also use $this->loadModel('Devoirs'); in the controller

Glad you found the problem

On Monday, July 28, 2014 11:10:09 PM UTC+2, Mikaël Capelle wrote:
>
> I'm not in DevoirsController. 
>
> Thanks to your questions, I found my mistake, I named the file 
> DevoirsTable.ctp instead of DevoirsTable.php... Stupid copy/paste mistake, 
> thanks you for pointing me to this!
>
> On Monday, July 28, 2014 10:54:33 PM UTC+2, José Lorenzo wrote:
>>
>> A few questions:
>>
>> - Where did you put DevoirsTable ?
>> - How did you name the DevoirsTable file?
>> - What namespace did you use in that file?
>> - Can you verify that file is being included?
>>
>> And a small correction, This is not needed in a DevoirsController:
>>
>> $this->Devoirs = TableRegistry::get('Devoirs');
>>
>>
>> On Monday, July 28, 2014 10:20:06 PM UTC+2, Mikaël Capelle wrote:
>>>
>>> Hi everyone,
>>>
>>> I'm trying to build a new CakePHP 3 application but I didn't manage to 
>>> get the data validation working... I followed the CakePHP 3.0 book, and 
>>> particulary this page 
>>> http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html 
>>> but it didn't help.
>>>
>>> Currently, my Table is as follow:
>>>
>>> class DevoirsTable extends Table {
>>>  
>>> public function initialize(array $config) {
>>>  
>>> }
>>> 
>>> public function validationDefault (Validator $validator) {
>>> debug('TEST HERE') ;
>>> $validator->notEmpty('pseudo', 'Oh my god!');
>>> return $validator;
>>> } 
>>>  }
>>>
>>>
>>> And my controller:
>>>
>>> $this->Devoirs = TableRegistry::get('Devoirs') ;
>>> $devoir = $this->Devoirs->find()->first() ;
>>> if ($this->request->is(['post', 'put'])) {
>>> $this->Devoirs->patchEntity($devoir, $this->request->data) ;
>>> $this->set('saved', $this->Devoirs->save($devoir, ['validate' => 
>>> true])) ;
>>> }
>>>
>>>
>>> This is only a test action, the row is correctly updated in my database 
>>> but the 'TEST HERE' string never showed up... I don't understand how the 
>>> new validation system works, maybe someone can help me?
>>>
>>> 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: CakePHP 3.0 Validation ?

2014-07-28 Thread Mikaël Capelle
I'm not in DevoirsController. 

Thanks to your questions, I found my mistake, I named the file 
DevoirsTable.ctp instead of DevoirsTable.php... Stupid copy/paste mistake, 
thanks you for pointing me to this!

On Monday, July 28, 2014 10:54:33 PM UTC+2, José Lorenzo wrote:
>
> A few questions:
>
> - Where did you put DevoirsTable ?
> - How did you name the DevoirsTable file?
> - What namespace did you use in that file?
> - Can you verify that file is being included?
>
> And a small correction, This is not needed in a DevoirsController:
>
> $this->Devoirs = TableRegistry::get('Devoirs');
>
>
> On Monday, July 28, 2014 10:20:06 PM UTC+2, Mikaël Capelle wrote:
>>
>> Hi everyone,
>>
>> I'm trying to build a new CakePHP 3 application but I didn't manage to 
>> get the data validation working... I followed the CakePHP 3.0 book, and 
>> particulary this page 
>> http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html 
>> but it didn't help.
>>
>> Currently, my Table is as follow:
>>
>> class DevoirsTable extends Table {
>>  
>> public function initialize(array $config) {
>>  
>> }
>> 
>> public function validationDefault (Validator $validator) {
>> debug('TEST HERE') ;
>> $validator->notEmpty('pseudo', 'Oh my god!');
>> return $validator;
>> } 
>>  }
>>
>>
>> And my controller:
>>
>> $this->Devoirs = TableRegistry::get('Devoirs') ;
>> $devoir = $this->Devoirs->find()->first() ;
>> if ($this->request->is(['post', 'put'])) {
>>     $this->Devoirs->patchEntity($devoir, $this->request->data) ;
>> $this->set('saved', $this->Devoirs->save($devoir, ['validate' => 
>> true])) ;
>> }
>>
>>
>> This is only a test action, the row is correctly updated in my database 
>> but the 'TEST HERE' string never showed up... I don't understand how the 
>> new validation system works, maybe someone can help me?
>>
>> 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: CakePHP 3.0 Validation ?

2014-07-28 Thread José Lorenzo
A few questions:

- Where did you put DevoirsTable ?
- How did you name the DevoirsTable file?
- What namespace did you use in that file?
- Can you verify that file is being included?

And a small correction, This is not needed in a DevoirsController:

$this->Devoirs = TableRegistry::get('Devoirs');


On Monday, July 28, 2014 10:20:06 PM UTC+2, Mikaël Capelle wrote:
>
> Hi everyone,
>
> I'm trying to build a new CakePHP 3 application but I didn't manage to get 
> the data validation working... I followed the CakePHP 3.0 book, and 
> particulary this page 
> http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html 
> but it didn't help.
>
> Currently, my Table is as follow:
>
> class DevoirsTable extends Table {
>  
> public function initialize(array $config) {
>  
> }
> 
> public function validationDefault (Validator $validator) {
> debug('TEST HERE') ;
> $validator->notEmpty('pseudo', 'Oh my god!');
> return $validator;
> } 
>  }
>
>
> And my controller:
>
> $this->Devoirs = TableRegistry::get('Devoirs') ;
> $devoir = $this->Devoirs->find()->first() ;
> if ($this->request->is(['post', 'put'])) {
> $this->Devoirs->patchEntity($devoir, $this->request->data) ;
> $this->set('saved', $this->Devoirs->save($devoir, ['validate' => 
> true])) ;
> }
>
>
> This is only a test action, the row is correctly updated in my database 
> but the 'TEST HERE' string never showed up... I don't understand how the 
> new validation system works, maybe someone can help me?
>
> 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.


CakePHP 3.0 Validation ?

2014-07-28 Thread Mikaël Capelle
Hi everyone,

I'm trying to build a new CakePHP 3 application but I didn't manage to get 
the data validation working... I followed the CakePHP 3.0 book, and 
particulary this 
page http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html 
but it didn't help.

Currently, my Table is as follow:

class DevoirsTable extends Table {
 
public function initialize(array $config) {
 
}

public function validationDefault (Validator $validator) {
debug('TEST HERE') ;
$validator->notEmpty('pseudo', 'Oh my god!');
return $validator;
} 
 }


And my controller:

$this->Devoirs = TableRegistry::get('Devoirs') ;
$devoir = $this->Devoirs->find()->first() ;
if ($this->request->is(['post', 'put'])) {
$this->Devoirs->patchEntity($devoir, $this->request->data) ;
$this->set('saved', $this->Devoirs->save($devoir, ['validate' => 
true])) ;
}


This is only a test action, the row is correctly updated in my database but 
the 'TEST HERE' string never showed up... I don't understand how the new 
validation system works, maybe someone can help me?

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: Data Validation: Checking if at least one field is populated and multiple rules not validating

2014-07-17 Thread seba
Thanks very much Stephen. I kept at it and found the solution lay in 
removing the 'required' and 'allowEmpty' from the 'needOne' ruleset, and 
adding a 'required' => false in the view. 

Here's the working solution for any one else with this problem:

The model:

public $validate = array(
'last_name'=> array(
'needOne' => array (
'rule' => 'checkOne',
'message' => 'You must enter at least a contact name or email address.'
),
'alphaNumeric' => array(
'rule'   => 'alphaNumeric',
'message'  => 'Alphabets and numbers only',
'allowEmpty' => TRUE
),
'between' => array(
'rule'  => array('between', 2, 45),
'message' => 'Between 2 to 45 characters',
'allowEmpty' => TRUE
)
),
'email' => array(
'needOne' => array (
'rule' => 'checkOne',
'message' => 'You must enter at least a contact name or email address.'
),
'emailAddress' => array (
'rule' => 'email',
'message'  => 'A valid Email address is required',
'allowEmpty' => TRUE
)
)
);

// Ensure at least the last name or email field value is provided
public function checkOne($data) {
if(!empty($this->data[$this->alias]['last_name']) 
|| !empty($this->data[$this->alias]['email'])) {
return TRUE;
} else {
return FALSE;
}
} 


The view/fields (I'm using Bootstrap):

echo $this->Form->input('last_name', array(
'required' => false,
'fieldset' => false,
'label' => false,
'before' => 'Last Name *',
'class' => 'form-control',
'placeholder' => 'Last Name',
'div' => 'form-group col-sm-12',
'error' => array(
'attributes' => array(
'wrap' => 'div', 
'class' => 'alert alert-danger'
)
)
)
);

echo $this->Form->input('email', array(
'required' => false,
'fieldset' => false,
'label' => false,
'before' => 'Email *',
'after' => '',
'class' => 'form-control',
'div' => 'form-group col-sm-12 col-xs-12',
'error' => array(
'attributes' => array(
'wrap' => 'div', 
'class' => 'alert alert-danger'
)
)
)
);

Thanks.

On Wednesday, 16 July 2014 00:44:50 UTC+10, seba wrote:
>
> Folks,
>
> I'm trying to ensure at least one of two fields (last_name or email) is 
> being populated. Each field also has multiple rules. I'm using CakePHP 
> version 2.4.2. 
>
> The problem I have at the moment, after multiple permutations of updating 
> and/or moving around the use 'last', 'allowEmpty', 'required', etc, is that 
> the fields just aren't validating at all, or aren't executing all the rules 
> when a field is populated.
>
> Any advice on how to modify the code below to achieve the following 
> behaviour is much appreciated:
> 1. One of the two fields must be populated;
> 2. The other rules attached to each field must validate as well (i.e. if a 
> last name is passed, then it must be between 2 and 45 chars and 
> alphanumeric only)
>
> Here's the model code:
>
> public $validate = array(
> 'last_name'=> array(
> 'needOne' => array (
> 'required' => FALSE,
> 'allowEmpty' => TRUE,
> 'last' => TRUE,
> 'rule' => array('checkOne','last_name'),
> 'message' => 'You must enter at least a contact name or email address.'
>  ),
> 'alphaNumeric' => array(
> 'rule' => 'alphaNumeric',
> 'message'  => 'Alphabets and numbers only'
> ),
> 'between' => array(
> 'rule' => array('between', 2, 45),
> 'message' => 'Between 2 to 45 characters'
> )
> ),
> 'email' => array(
> 'needOne' => array (
> 'required' => FALSE,
> 'allowEmpty' => TRUE,
> 'last' => TRUE,
> 'rule' => array('checkOne','email'),
> 'message' => 'You must enter at least a contact name or email address.'
>  ),
> 'emailAddress' => array (
> 'last' => TRUE,
> 'rule' => array('email', FALSE),
> 'message'  => 'A valid Email address is required'
>  )
> )
> );
>  // Ensure at least the last name or email field value is provided
> function checkOne() {
> if(!empty($this->data[$this->User]['last_name']) || 
> !empty($this->data[$this->User]['email'])){
> return true;
> } else {
> return false;
> }
> }
>
> 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 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: Data Validation: Checking if at least one field is populated and multiple rules not validating

2014-07-15 Thread Stephen S
You can try dynamically adding or removing validation rules in your custom
'checkOne' method.

http://book.cakephp.org/2.0/en/models/data-validation.html#removing-rules-from-the-set


On 15 July 2014 15:44, seba  wrote:

> Folks,
>
> I'm trying to ensure at least one of two fields (last_name or email) is
> being populated. Each field also has multiple rules. I'm using CakePHP
> version 2.4.2.
>
> The problem I have at the moment, after multiple permutations of updating
> and/or moving around the use 'last', 'allowEmpty', 'required', etc, is that
> the fields just aren't validating at all, or aren't executing all the rules
> when a field is populated.
>
> Any advice on how to modify the code below to achieve the following
> behaviour is much appreciated:
> 1. One of the two fields must be populated;
> 2. The other rules attached to each field must validate as well (i.e. if a
> last name is passed, then it must be between 2 and 45 chars and
> alphanumeric only)
>
> Here's the model code:
>
> public $validate = array(
> 'last_name'=> array(
> 'needOne' => array (
> 'required' => FALSE,
> 'allowEmpty' => TRUE,
> 'last' => TRUE,
> 'rule' => array('checkOne','last_name'),
> 'message' => 'You must enter at least a contact name or email address.'
>  ),
> 'alphaNumeric' => array(
> 'rule' => 'alphaNumeric',
> 'message'  => 'Alphabets and numbers only'
> ),
> 'between' => array(
> 'rule' => array('between', 2, 45),
> 'message' => 'Between 2 to 45 characters'
> )
> ),
> 'email' => array(
> 'needOne' => array (
> 'required' => FALSE,
> 'allowEmpty' => TRUE,
> 'last' => TRUE,
> 'rule' => array('checkOne','email'),
> 'message' => 'You must enter at least a contact name or email address.'
>  ),
> 'emailAddress' => array (
> 'last' => TRUE,
> 'rule' => array('email', FALSE),
> 'message'  => 'A valid Email address is required'
>  )
> )
> );
>  // Ensure at least the last name or email field value is provided
> function checkOne() {
> if(!empty($this->data[$this->User]['last_name']) ||
> !empty($this->data[$this->User]['email'])){
> return true;
> } else {
> return false;
> }
> }
>
> 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 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.
>



-- 
Kind Regards
 Stephen Speakman

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


Data Validation: Checking if at least one field is populated and multiple rules not validating

2014-07-15 Thread seba
Folks,

I'm trying to ensure at least one of two fields (last_name or email) is 
being populated. Each field also has multiple rules. I'm using CakePHP 
version 2.4.2. 

The problem I have at the moment, after multiple permutations of updating 
and/or moving around the use 'last', 'allowEmpty', 'required', etc, is that 
the fields just aren't validating at all, or aren't executing all the rules 
when a field is populated.

Any advice on how to modify the code below to achieve the following 
behaviour is much appreciated:
1. One of the two fields must be populated;
2. The other rules attached to each field must validate as well (i.e. if a 
last name is passed, then it must be between 2 and 45 chars and 
alphanumeric only)

Here's the model code:

public $validate = array(
'last_name'=> array(
'needOne' => array (
'required' => FALSE,
'allowEmpty' => TRUE,
'last' => TRUE,
'rule' => array('checkOne','last_name'),
'message' => 'You must enter at least a contact name or email address.'
 ),
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'message'  => 'Alphabets and numbers only'
),
'between' => array(
'rule' => array('between', 2, 45),
'message' => 'Between 2 to 45 characters'
)
),
'email' => array(
'needOne' => array (
'required' => FALSE,
'allowEmpty' => TRUE,
'last' => TRUE,
'rule' => array('checkOne','email'),
'message' => 'You must enter at least a contact name or email address.'
 ),
'emailAddress' => array (
'last' => TRUE,
'rule' => array('email', FALSE),
'message'  => 'A valid Email address is required'
 )
)
);
 // Ensure at least the last name or email field value is provided
function checkOne() {
if(!empty($this->data[$this->User]['last_name']) || 
!empty($this->data[$this->User]['email'])){
return true;
} else {
return false;
}
}

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 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: callback succession / why afterValidate() if validation fails

2014-05-26 Thread Charles Bueche
Thx José for the explanation.

But how do I test if the validation has failed ?
Something like this is not really nice...

function afterValidate($options) {
if (!empty($this->validationErrors)) {
return false;
}
}

any better idea ?
TIA,
Charles

On 26.05.14 10:16, José Lorenzo wrote:
> It is just the way it works. There are equal amount of reasons for
> wanting the callback to be run after the validation has failed, can
> you not change the logic to check if there are any validation errors
> and not run the rest of the method?
>
> On Monday, May 26, 2014 10:06:50 AM UTC+2, cbueche wrote:
>
> Dear Bakers,
>
> I have an app under CakePHP 2.5.1. I'm not sure to understand how
> the callback succession is supposed to work, eg if the validation
> fails, there is IMHO no reason to run afterValidate() ? But it
> does run indeed.
>
> What I'm trying to do:
>
> my form has 7 entry fields. The ones I have issues with are
> start_time, end_time and duration. The user might enter a
> combination of them, eg
>
> - start & end
> - start & duration
> - duration & end
> - only duration
>
> (at the end, I only care about durations)
>
> My strategy for saving the data is
>
> - have a validation for the fields, eg to get the right time
> format (HH:MM) or duration, but with 'required' => false and
> 'allowEmpty' => true
> - in afterValidate(), I verify that the new entered start and end
> do not overlap with existing records
> - in beforeSave(), I verify the combination entered by the user,
> the goal being to calculate a duration
>
> My problem is that even if the user enters a wrong format for a
> field, Cake still run afterValidate(), causing problems in my
> queries, before I can return "false" to abort the save.
>
> Now I'm not really sure why cake runs afterValidate() if
> validation fails. Is there something I missed ?
>
> TIA for your assistance,
> Charles
>

-- 
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: callback succession / why afterValidate() if validation fails

2014-05-26 Thread José Lorenzo
It is just the way it works. There are equal amount of reasons for wanting 
the callback to be run after the validation has failed, can you not change 
the logic to check if there are any validation errors and not run the rest 
of the method?

On Monday, May 26, 2014 10:06:50 AM UTC+2, cbueche wrote:
>
>  Dear Bakers,
>
> I have an app under CakePHP 2.5.1. I'm not sure to understand how the 
> callback succession is supposed to work, eg if the validation fails, there 
> is IMHO no reason to run afterValidate() ? But it does run indeed.
>
> What I'm trying to do:
>
> my form has 7 entry fields. The ones I have issues with are start_time, 
> end_time and duration. The user might enter a combination of them, eg
>
> - start & end
> - start & duration
> - duration & end
> - only duration
>
> (at the end, I only care about durations)
>
> My strategy for saving the data is 
>
> - have a validation for the fields, eg to get the right time format 
> (HH:MM) or duration, but with 'required' => false and 'allowEmpty' => true
> - in afterValidate(), I verify that the new entered start and end do not 
> overlap with existing records
> - in beforeSave(), I verify the combination entered by the user, the goal 
> being to calculate a duration
>
> My problem is that even if the user enters a wrong format for a field, 
> Cake still run afterValidate(), causing problems in my queries, before I 
> can return "false" to abort the save.
>
> Now I'm not really sure why cake runs afterValidate() if validation fails. 
> Is there something I missed ?
>
> TIA for your assistance,
> Charles
>  

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


callback succession / why afterValidate() if validation fails

2014-05-26 Thread Charles Bueche
Dear Bakers,

I have an app under CakePHP 2.5.1. I'm not sure to understand how the
callback succession is supposed to work, eg if the validation fails,
there is IMHO no reason to run afterValidate() ? But it does run indeed.

What I'm trying to do:

my form has 7 entry fields. The ones I have issues with are start_time,
end_time and duration. The user might enter a combination of them, eg

- start & end
- start & duration
- duration & end
- only duration

(at the end, I only care about durations)

My strategy for saving the data is

- have a validation for the fields, eg to get the right time format
(HH:MM) or duration, but with 'required' => false and 'allowEmpty' => true
- in afterValidate(), I verify that the new entered start and end do not
overlap with existing records
- in beforeSave(), I verify the combination entered by the user, the
goal being to calculate a duration

My problem is that even if the user enters a wrong format for a field,
Cake still run afterValidate(), causing problems in my queries, before I
can return "false" to abort the save.

Now I'm not really sure why cake runs afterValidate() if validation
fails. Is there something I missed ?

TIA for your assistance,
Charles

-- 
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: V3.0 Custom validation messages

2014-03-18 Thread Dr. Tarique Sani
Cool - that works. Now trying out for other rules

Also instead having to write echo $this->Form->input('title',['required' =>
false] ); keep the required to false by default OR have a javascript helper
automatically output and attach custom error messages to fields. The second
option will be really cool to have.

Thanks for your efforts

Regards
Tarique



On Tue, Mar 18, 2014 at 7:10 PM, José Lorenzo  wrote:

> Tarique, I recently pushed some changes to the validation. You can now do:
>
> $validator->allowEmpty('my_field', false, 'My Custom message');
>
> This deprecates the use of the 'notEmpty' rule.
>
>
> On Friday, March 14, 2014 12:55:58 PM UTC+1, Dr. Tarique Sani wrote:
>
>> Thanks a lot José, would be interesting to compare what you do with what
>> I was going to do :)
>>
>> Cheers
>> Tarique
>>
>>
>> On Fri, Mar 14, 2014 at 3:07 PM, José Lorenzo  wrote:
>>
>>> Tarique, I can confirm the problem. It is actually an overlook on how
>>> the validation system works now I will implementing a solution and
>>> providing documentation for it soon.
>>>
>>>
>>> On Friday, March 14, 2014 10:10:18 AM UTC+1, José Lorenzo wrote:
>>>>
>>>> Sure, I think github is a better place to track this problem
>>>>
>>>> On Friday, March 14, 2014 7:56:40 AM UTC+1, Dr. Tarique Sani wrote:
>>>>>
>>>>> Another strange thing. If I use an Entity class written in a file then
>>>>> at least the validation works but if I try the following in the controller
>>>>>
>>>>> $article = new Cake\ORM\Entity;
>>>>> $article->accessible('*', true);
>>>>> $article = $this->Articles->patchEntity($article,
>>>>> $this->request->data);
>>>>>
>>>>> Validation is completely skipped. I traced it till the
>>>>> _addValidatorProps in  http://api.cakephp.org/3.0/so
>>>>> urce-class-Cake.Validation.ValidationRule.html#171-190 and then ran
>>>>> out of time...
>>>>>
>>>>> Should I file this on github?
>>>>>
>>>>> Cheers
>>>>>
>>>>> Tarique
>>>>>
>>>>>
>>>>>
>>>>> On Fri, Mar 14, 2014 at 8:46 AM, Dr. Tarique Sani 
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Wonder if you had the time to look into why custom error messages
>>>>>> don't get populated?
>>>>>>
>>>>>> http://bin.cakephp.org/saved/120670 has my complete Table class
>>>>>>
>>>>>> The controller is more or less like you suggested in
>>>>>> http://bin.cakephp.org/saved/120567
>>>>>>
>>>>>> Cheers
>>>>>>  Tarique
>>>>>>
>>>>>>
>>>>>> On Thu, Mar 13, 2014 at 1:56 PM, José Lorenzo wrote:
>>>>>>
>>>>>>> It could be a bug. I'm going to check that out in a bit. To avoid
>>>>>>> the strict warning you need:
>>>>>>>
>>>>>>> use Cake\Validation\Validator;
>>>>>>>
>>>>>>> class ArticlesTable extends Table {
>>>>>>>
>>>>>>> public function validationDefault(Validator $validator) {
>>>>>>> ...
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, March 13, 2014 6:07:47 AM UTC+1, Dr. Tarique Sani wrote:
>>>>>>>>
>>>>>>>> My AtriclesTable has
>>>>>>>>
>>>>>>>>
>>>>>>>> public function validationDefault($validator) {
>>>>>>>> $validator
>>>>>>>> ->add('title', 'not-Empty', [
>>>>>>>> 'rule' => 'notEmpty',
>>>>>>>> 'message' => 'You need to provide a title',
>>>>>>>> ])
>>>>>>>> ->add('body', 'not-Empty', [
>>>>>>>> 'rule' => 'notEmpty',
>>>>>>>> 'message' => 'A body is required'
>>>>>>>&g

Re: V3.0 Custom validation messages

2014-03-18 Thread José Lorenzo
Tarique, I recently pushed some changes to the validation. You can now do:

$validator->allowEmpty('my_field', false, 'My Custom message');

This deprecates the use of the 'notEmpty' rule.

On Friday, March 14, 2014 12:55:58 PM UTC+1, Dr. Tarique Sani wrote:
>
> Thanks a lot José, would be interesting to compare what you do with what I 
> was going to do :)
>
> Cheers
> Tarique
>
>
> On Fri, Mar 14, 2014 at 3:07 PM, José Lorenzo 
> > wrote:
>
>> Tarique, I can confirm the problem. It is actually an overlook on how the 
>> validation system works now I will implementing a solution and providing 
>> documentation for it soon.
>>
>>
>> On Friday, March 14, 2014 10:10:18 AM UTC+1, José Lorenzo wrote:
>>>
>>> Sure, I think github is a better place to track this problem
>>>
>>> On Friday, March 14, 2014 7:56:40 AM UTC+1, Dr. Tarique Sani wrote:
>>>>
>>>> Another strange thing. If I use an Entity class written in a file then 
>>>> at least the validation works but if I try the following in the controller
>>>>
>>>> $article = new Cake\ORM\Entity;
>>>> $article->accessible('*', true);
>>>> $article = $this->Articles->patchEntity($article, 
>>>> $this->request->data);
>>>>
>>>> Validation is completely skipped. I traced it till the 
>>>> _addValidatorProps in  http://api.cakephp.org/3.0/
>>>> source-class-Cake.Validation.ValidationRule.html#171-190 and then ran 
>>>> out of time...
>>>>
>>>> Should I file this on github?
>>>>
>>>> Cheers
>>>>
>>>> Tarique
>>>>
>>>>
>>>>
>>>> On Fri, Mar 14, 2014 at 8:46 AM, Dr. Tarique Sani 
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Wonder if you had the time to look into why custom error messages 
>>>>> don't get populated? 
>>>>>
>>>>> http://bin.cakephp.org/saved/120670 has my complete Table class 
>>>>>
>>>>> The controller is more or less like you suggested in 
>>>>> http://bin.cakephp.org/saved/120567 
>>>>>
>>>>> Cheers
>>>>>  Tarique
>>>>>
>>>>>
>>>>> On Thu, Mar 13, 2014 at 1:56 PM, José Lorenzo wrote:
>>>>>
>>>>>> It could be a bug. I'm going to check that out in a bit. To avoid the 
>>>>>> strict warning you need:
>>>>>>
>>>>>> use Cake\Validation\Validator;
>>>>>>
>>>>>> class ArticlesTable extends Table {
>>>>>>
>>>>>> public function validationDefault(Validator $validator) {
>>>>>> ...
>>>>>>
>>>>>>
>>>>>> On Thursday, March 13, 2014 6:07:47 AM UTC+1, Dr. Tarique Sani wrote:
>>>>>>>
>>>>>>> My AtriclesTable has 
>>>>>>>
>>>>>>>
>>>>>>> public function validationDefault($validator) {
>>>>>>> $validator
>>>>>>> ->add('title', 'not-Empty', [
>>>>>>> 'rule' => 'notEmpty',
>>>>>>> 'message' => 'You need to provide a title',
>>>>>>> ])
>>>>>>> ->add('body', 'not-Empty', [
>>>>>>> 'rule' => 'notEmpty',
>>>>>>> 'message' => 'A body is required'
>>>>>>> ]);
>>>>>>> return $validator;
>>>>>>> }
>>>>>>>
>>>>>>> When I try to save an article entity the validation runs fine but I 
>>>>>>> am only getting the default in the ArticleEntity 
>>>>>>>
>>>>>>> 'errors' => [
>>>>>>> 'title' => [
>>>>>>>  (int) 0 => 'This field cannot be left empty'
>>>>>>> ],
>>>>>>> 'body' => [
>>>>>>>  (int) 0 => 'This field cannot be left empty'
>>>>>>> ]
>>>>>>> ]
>>>>>

Re: Custom MM:SS Time Validation with Regex

2014-03-14 Thread Justin Atack
Hmmm thanks for that code you've given me something to think about.

Would I implement that in my model and the call it before my save in the 
controller?

On Tuesday, 11 March 2014 19:44:14 UTC+11, AD7six wrote:
>
> If regular expressions aren't your thing - don't use regular expressions =)
>
> e.g. write a validation function like so:
>
> function validateTime($check) {
> $string = current($check);
> list($mins, $seconds) = expode(':', $string);
>
> $validMins = is_numeric($mins);
> $validSeconds = is_numeric($seconds) && ($seconds < 60);
>
> return $validMins && $validSeconds;
> }
>
> Alternatively since a regex is not cakephp specific - ask in an 
> appropriate place (stack overflow) with appropriate context i.e. "how can I 
> check that a string matches the format xx:yy where ?" Or - check 
> for existing questions asking exactly that, like this one: 
> http://stackoverflow.com/questions/3964972/validate-this-format-hhmm and 
> modify to your needs
>
> AD
>
>
> On Tuesday, 11 March 2014 05:03:28 UTC+1, Justin Atack wrote:
>>
>> Anybody?
>>
>> On Friday, 7 March 2014 22:14:03 UTC+11, Justin Atack wrote:
>>>
>>> Hi All,
>>>
>>> I need to validate a field that will store a time instance MM:SS e.g. 
>>> 04:32 would represent 4 minutes and 32 seconds.
>>>
>>> I have created the code in my model to validate the time field but I 
>>> really don't know much about regex. Here are a few that work ok...
>>>
>>> /([0-9]\d|60):([0-9]\d|60)/
>>>
>>> ^([0-5]?[0-9]):([0-5]?[0-9])^
>>>
>>> but neither causes an error if the time is 99:99. This is ok for the MM 
>>> part as 99 minutes is valid but the SS part should only ever have a max of 
>>> 59 (seconds).
>>>
>>> I hope that makes sense!
>>>
>>> This is the code in my model this far
>>>
>>> 'time' => array(
>>> 'custom' => array(
>>> 'rule' => array('custom', '/([0-9]\d|60):([0-9]\d|60)/'), //MM:SS
>>> //'rule' => array('custom', '^([0-5]?[0-9]):([0-5]?[0-9])^'), //MM:SS
>>> 'message' => 'Time must be entered as MM:SS. e.g. 04:32 representing 4 
>>> minutes and 32 seconds.',
>>> 'allowEmpty' => true,
>>> //'required' => false,
>>> //'last' => false, // Stop validation after this rule
>>> //'on' => 'create', // Limit validation to 'create' or 'update' 
>>> operations
>>> ),
>>> 'maxLength' => array(
>>> 'rule' => array('maxLength', '5'),
>>> 'message' => 'Maximum length of time input is five characters. e.g. 
>>> MM:SS',
>>> //'allowEmpty' => true,
>>> //'required' => false,
>>> //'last' => false, // Stop validation after this rule
>>> //'on' => 'create', // Limit validation to 'create' or 'update' 
>>> operations
>>> ), 
>>> ),
>>> );
>>>
>>

-- 
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: V3.0 Custom validation messages

2014-03-14 Thread Dr. Tarique Sani
Thanks a lot José, would be interesting to compare what you do with what I
was going to do :)

Cheers
Tarique


On Fri, Mar 14, 2014 at 3:07 PM, José Lorenzo  wrote:

> Tarique, I can confirm the problem. It is actually an overlook on how the
> validation system works now I will implementing a solution and providing
> documentation for it soon.
>
>
> On Friday, March 14, 2014 10:10:18 AM UTC+1, José Lorenzo wrote:
>>
>> Sure, I think github is a better place to track this problem
>>
>> On Friday, March 14, 2014 7:56:40 AM UTC+1, Dr. Tarique Sani wrote:
>>>
>>> Another strange thing. If I use an Entity class written in a file then
>>> at least the validation works but if I try the following in the controller
>>>
>>> $article = new Cake\ORM\Entity;
>>> $article->accessible('*', true);
>>> $article = $this->Articles->patchEntity($article, $this->request->data);
>>>
>>> Validation is completely skipped. I traced it till the
>>> _addValidatorProps in  http://api.cakephp.org/3.0/
>>> source-class-Cake.Validation.ValidationRule.html#171-190 and then ran
>>> out of time...
>>>
>>> Should I file this on github?
>>>
>>> Cheers
>>>
>>> Tarique
>>>
>>>
>>>
>>> On Fri, Mar 14, 2014 at 8:46 AM, Dr. Tarique Sani wrote:
>>>
>>>> Hi,
>>>>
>>>> Wonder if you had the time to look into why custom error messages don't
>>>> get populated?
>>>>
>>>> http://bin.cakephp.org/saved/120670 has my complete Table class
>>>>
>>>> The controller is more or less like you suggested in
>>>> http://bin.cakephp.org/saved/120567
>>>>
>>>> Cheers
>>>> Tarique
>>>>
>>>>
>>>> On Thu, Mar 13, 2014 at 1:56 PM, José Lorenzo wrote:
>>>>
>>>>> It could be a bug. I'm going to check that out in a bit. To avoid the
>>>>> strict warning you need:
>>>>>
>>>>> use Cake\Validation\Validator;
>>>>>
>>>>> class ArticlesTable extends Table {
>>>>>
>>>>> public function validationDefault(Validator $validator) {
>>>>> ...
>>>>>
>>>>>
>>>>> On Thursday, March 13, 2014 6:07:47 AM UTC+1, Dr. Tarique Sani wrote:
>>>>>>
>>>>>> My AtriclesTable has
>>>>>>
>>>>>>
>>>>>> public function validationDefault($validator) {
>>>>>> $validator
>>>>>> ->add('title', 'not-Empty', [
>>>>>> 'rule' => 'notEmpty',
>>>>>>     'message' => 'You need to provide a title',
>>>>>> ])
>>>>>> ->add('body', 'not-Empty', [
>>>>>> 'rule' => 'notEmpty',
>>>>>> 'message' => 'A body is required'
>>>>>> ]);
>>>>>> return $validator;
>>>>>> }
>>>>>>
>>>>>> When I try to save an article entity the validation runs fine but I
>>>>>> am only getting the default in the ArticleEntity
>>>>>>
>>>>>> 'errors' => [
>>>>>> 'title' => [
>>>>>>  (int) 0 => 'This field cannot be left empty'
>>>>>> ],
>>>>>> 'body' => [
>>>>>>  (int) 0 => 'This field cannot be left empty'
>>>>>> ]
>>>>>> ]
>>>>>>
>>>>>> Additionally there is a warning
>>>>>>
>>>>>> Strict (2048): Declaration of 
>>>>>> App\Model\Table\ArticlesTable::validationDefault()
>>>>>> should be compatible with 
>>>>>> Cake\ORM\Table::validationDefault(Cake\Validation\Validator
>>>>>> $validator) [APP/Model/Table/ArticlesTable.php, line 7]
>>>>>>
>>>>>> What additional steps are needed to fix this?
>>>>>>
>>>>>> Cheers
>>>>>> Tarique
>>>>>>
>>>>>> --
>>>>>> 

  1   2   3   4   5   6   7   8   9   10   >