Thursday, February 28, 2013

Re: beforeValidate can't modify my data

This isn't helpful:(

I think is not complicated?

W dniu czwartek, 28 lutego 2013 22:03:59 UTC+1 użytkownik André Luis napisał:
Try:

public function beforeValidate($options = array()) {
        $data=&$this->data['Photo'];
        foreach($data as $k=>$v){
            if(empty($v['name'])) unset($data[$k]);
        }
        return true;
    }

Em quarta-feira, 27 de fevereiro de 2013 20h58min12s UTC-3, kicaj escreveu:
I create form with many fields and fields for upload files (Photo.0.image, Photo.1.image).

How do I choose from my computer two files to upload and send form, then works perfectly. But sometimes I would like upload only one file (Photo.0.image) and the secend input file (Photo.1.image) leave empty. I prepare Photo::beforeValidate for this:

public function beforeValidate($options = array()) {
if(empty($this->data['Photo']['image']['tmp_name'])) {
unset($this->data['Photo']);
}
return true;
}

But my SaveAll() return false and results for pr($this->News->validationErrors) is:

Array (
[Photo] => Array (
[1] => Array ()
)
)

What going on?
Any idea?

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

No comments: