#6399: Message errors translations doesn't work for date validation
--------------------------+-------------------------------------------------
    Reporter:  jbarbede   |          Type:  Bug    
      Status:  new        |      Priority:  Medium 
   Milestone:  1.2.x.x    |     Component:  General
     Version:  1.2 Final  |      Severity:  Normal 
    Keywords:             |   Php_version:  n/a    
Cake_version:             |  
--------------------------+-------------------------------------------------
 = What I did =

 I made the following:

   - a model "Member" with the following validation rules (I use the
 Multivalidatable behavior) :

 {{{
 public $validationSets = array(
   'signUp' => array(
     'gender' => array(
       'notEmpty' => array(
         'rule' => 'notEmpty',
         'required' => true
       )
     ),
     'first_name' => array(
       'notEmpty' => array(
         'rule' => 'notEmpty',
         'required' => true
       )
     ),
     'last_name' => array(
       'notEmpty' => array(
         'rule' => 'notEmpty',
         'required' => true
       )
     ),
     'birth_date' => array(
       'date' => array(
         'rule' => 'date'
       ),
       'notEmpty' => array(
         'rule' => 'notEmpty',
         'required' => true
       )
     ),
   )
 )
 }}}

   - My input generated with the following code:


 {{{
 //Member's birth date
 e($form->input('birth_date', array(
       'label' => __('label_birth_date', true),
       'div' => array('class' => 'form-line clearfix'),
       'before' => '<div class="clearfix">',
       'between' => '<div class="form-field">',
       'after' => '</div></div>',
       'error' => array(
         'date' => __('error_invalid_date', true),
         'notEmpty' => __('error_birth_date_required', true)
       ),
       'minYear'=> date('Y') - 100,
       'maxYear' => date('Y') - 18,
       'dateFormat' => 'DMY',
       'empty' => true
     )
   )
 );
 }}}

   - in my controller:

 {{{
 //Define validation rules for each model.
 $this->Member->setValidation('signUp');

 //Data posted.
 if (!empty($this->data)) {
   //Sanitize data.
   Sanitize::clean($this->data);
   //Populate member and email models.
   $this->Member->set($this->data);
   ...
 }
 }}}

 = What I expected to happen =

 I expect to obtain translated error message for date translation
 (English/Spanish).

 = Why it didn't meet my expectations =

 Error messages are not translated. The displayed message is always the
 default cakePHP error message: ''This field cannot be left blank''.

 I debug this during a moment and I found something strange: if I dump
 ''$this->data'' before ''$this->Member->set($this->data)'' call, I have
 that:

 {{{
 array(
 ['Member'] => array(
   ....,
   ['birth_date'] =>
     array(
       ['day'] => ''
       ['month'] => ''
       ['year'] => ''
     )
   )
 )
 }}}

 Now If I dump ''$this->data'' to the end of the ''set'' method in
 ''model.php'', I have that:

 {{{
 array(
 ['Member'] => array(
   ....,
   ['birth_date'] => null
 )
 }}}

 The ''set'' method of the ''model.php'' modified the ''$this->data''
 array. The value for ''birth_date'' is modified by the ''deconstruct''
 method of ''model.php'' which seems to be the origin of the problem of
 translation for error messages.

 = Posible fix =
 Change the condition or the returned value in ''deconstruct'' method in
 ''model.php'' on line ''843''.

 {{{
 if (in_array($type, array('datetime', 'timestamp', 'date')) &&
 !isset($data[$val]) || isset($data[$val]) && (empty($data[$val]) ||
 $data[$val][0] === '-')) {
   return null;
 } elseif (isset($data[$val]) && !empty($data[$val])) {
   $date[$key] = $data[$val];
 }
 }}}

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6399>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

  • [CakePHP : The Rapid Dev... CakePHP : The Rapid Development Framework for PHP

Reply via email to