【发布时间】:2013-03-20 23:35:07
【问题描述】:
我设置了一个为个人资料图片上传文件的表单,我正在验证文件上传,如下所示:
'picture' => array(
'kosher' => array(
'rule' => 'validateImage',
'message' => 'Only images are allowed to be uploaded'
),
'size' => array(
'rule' => array('fileSize', '<=', '2MB'),
'message' => 'Picture must be less than 2 MB'
)
)
验证运行正常,但是当我提交不正确的数据时,表单上没有显示验证错误。我正在构建整个表单:
<?php echo $this->Form->create('Profile', array('type' => 'file')); ?>
<?php echo $this->Form->hidden('id'); ?>
<?php echo $this->Form->label('Profile.picture', 'Profile picture'); ?>
<?php echo $this->Form->file('picture'); ?>
<?php echo $this->Form->input('firstname'); ?>
<?php echo $this->Form->input('lastname'); ?>
<?php echo $this->Form->input('email', array('between' => 'This is the email other users will use to contact you')); ?>
<?php echo $this->Form->input('Skill', array('type' => 'text', 'value' => $skills, 'label' => 'Your skills (seperate each skill by space)')); ?>
<?php echo $this->Form->input('course'); ?>
<?php echo $this->Form->input('bio'); ?>
<?php echo $this->Form->end('Save changes'); ?>
其他字段错误消息显示正确,只是文件上传不正确。如何使验证错误显示在文件输入周围?
【问题讨论】:
-
'picture'被定义为<?php echo $this->Form->file('picture'); ?>的数组,但不是size。据我所知。 -
我听不懂你在说什么?
-
与
'picture'、'firstname'等相比,您的'size'没有在任何地方回显。文件上传的错误消息不是'message' => 'Picture must be less than 2 MB'? -
也许你需要在某处添加
<?php echo $this->Form->file('size'); ?>。再说一次,我可能错了。 -
显示“validateImage”的验证操作
标签: php validation cakephp file-upload