Hi,
I’m uploading an image for an article, and in the model, i set some validation rules for this image.
//View
$this->Form->input('Post.image');
//Model Post
public $validate = array(
'image' => array(
'extension' => array(
'rule' => array('extension', array('jpeg', 'jpg', 'png', 'gif', 'bmp')),
'message' => "L'extension de l'image envoyée n'est pas valide"
),
'uploadError' => array(
'rule' => array('uploadError', true),
'message' => "Une erreur est survenue lors de l'upload de l'image"
),
'mimeType' => array(
'rule' => array('mimeType', array('image/png', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp')),
'message' => "Type de l'image invalide"
),
'fileSize' => array(
'rule' => array('fileSize', '<=', '2MB'),
'message' => "La taille de l'image ne doit pas dépasser 2MB"
)
)
);
The image is not required
, but the input generated in html view contains the required
attribute, i fix that by adding allowEmpty => true
on every rule. But still, the validation doesnt pass!
How can i fix this ?
Thank you