something like
public function beforeValidate($options = array()) {
if(empty($this->data['Photo']['0']['image']['tmp_name'])) { //zero is added in array structure (Photo.0.image....
unset($this->data['Photo']);
}
return true;
}
I hope it helps
and if you have more fields than 2, you can make for loop and inside for just change this "zero" to 1, 2, 3, 4, 5... how many fields you have.
Have fun!
--
Lep pozdrav, Tilen Majerle
2013/2/28 kicaj <kicaj@kdev.pl>
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.
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:
Post a Comment