Wednesday, December 18, 2013

Re: Yet Another Validation Question

Have you confirmed that the validation function is actually getting called, via CakeLog::debug() or error_log(print_r($data, true));

If your validation function only returns false, and it never gets called, mostly likely, validation is not getting called at all.

If the data is data['Community']['start']['year'], then you're probably using the FormHelper date functions, which tend to split a date into it's components, and return the results as an array.  However, you may wish to confirm with  error_log(print_r($data, true)); or similar, the structure of the field at validation time.  You may want to check for $value $this->data[$this->alias][$field]['year']; when determining the value of the year.

Regards
Reuben Helms

On Wednesday, 18 December 2013 16:22:45 UTC+10, advantage+ wrote:

I cannot validate my year select.

 

When posted it appears as :

data[Comunity][start][year]...

2009

 

Validation rule:

'start' => array(

       'required' => true,

       'allowEmpty' => false,

       'rule' => array('checkYearValues', 'start'),

       'message' => 'Please enter a year between 1950 and 2013 when you started.',

       'last' => true),

 

checkYearVales:

       /************************************************************

       * FORM VALIDATION SELECT YEAR VALUES

       * ***********************************************************

       * @access public

       * @return bool

       *

       *

       *

       ************************************************************/

       public function checkYearValues($data, $field){

 

                     $value = $this->data[$this->alias][$field];

                    

                     $baseYear = date('Y') - 2013 + 10;

                     $years =  array_combine(range( date('Y'), date('Y') - $baseYear), range( date('Y'), date('Y') - $baseYear));

                    

                     //return in_array($value, $years);

                     return false

                    

       }

 

But it always passes validation

 

Any ideas why start[year] gets added to the input?

 

Thanks all

 

Dave Maharaj

Freelance Designer | Developer
Description: header_logo

www.movepixels.com  |  dave@movepixels.com  |  709.800.0852

 

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: