我有一个表格,要求填写所有字段。
提交后,它应该在做任何其他事情之前进行验证。但是,即使有一些字段没有填写,它也会提交。
我在这里搜索过,但似乎找不到任何对我有用的东西。
这是我在InductionPpe
控制器中的方法:
public function request() {
if ($this->request->is('post')) {
$this->InductionPpe->set($this->request->data);
if($this->InductionPpe->validates()) {
// carry on
} else {
$this->validateErrors($this->InductionPpe);
$this->render();
}
}
}
我的模型设置了字段的所有规则,并且可以很好地完成其余的过程。但它不验证。
我从哪里开始寻找问题?我该如何解决?
更新
InductionPpe 模型中的验证规则:
class InductionPpe extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'hr_employee_id' => array(
'numeric' => array(
'rule' => array('numeric')
),
),
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter your name.'
),
),
'shoes' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the shoe size required.'
),
),
'reflective_jacket' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the size reflective jacket required.'
),
),
'metaguards' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the size of metaguards required.'
),
),
'glasses' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the number of glasses required.'
),
),
'earplugs' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the amount of earplugs reguired.'
),
),
'hardhats' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the amount of hardhats required.'
),
),
'gloves' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the amount of gloves required.'
),
),
'kit_bags' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the amount of kit bags required.'
),
),
'dust_mask' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the amount of dust masks required.'
),
),
'ppe_size' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the size of the PPE items.'
),
),
'activities' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please specify which activities the PPE items are required for.'
),
),
'site' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the site that you will be visiting.'
),
),
'project_number' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the project number applicable.'
),
),
'date_required' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter the date that the PPE equipment is required.'
),
)
);
}
更新 2
这是我得到的验证调试(如果我运行debug($this->InductionPpe->validationErrors);
)。
array(
'name' => array(
(int) 0 => 'Please enter your name.'
),
'shoes' => array(
(int) 0 => 'Please enter the shoe size required.'
),
'reflective_jacket' => array(
(int) 0 => 'Please enter the size reflective jacket required.'
),
'metaguards' => array(
(int) 0 => 'Please enter the size of metaguards required.'
),
'glasses' => array(
(int) 0 => 'Please enter the number of glasses required.'
),
'earplugs' => array(
(int) 0 => 'Please enter the amount of earplugs reguired.'
),
'hardhats' => array(
(int) 0 => 'Please enter the amount of hardhats required.'
),
'gloves' => array(
(int) 0 => 'Please enter the amount of gloves required.'
),
'kit_bags' => array(
(int) 0 => 'Please enter the amount of kit bags required.'
),
'dust_mask' => array(
(int) 0 => 'Please enter the amount of dust masks required.'
),
'ppe_size' => array(
(int) 0 => 'Please enter the size of the PPE items.'
),
'activities' => array(
(int) 0 => 'Please specify which activities the PPE items are required for.'
),
'site' => array(
(int) 0 => 'Please enter the site that you will be visiting.'
),
'project_number' => array(
(int) 0 => 'Please enter the project number applicable.'
),
'date_required' => array(
(int) 0 => 'Please enter the date that the PPE equipment is required.'
)
)
还有我输入这些的表格:
<div class="inductionPpes form">
<?php
echo $this->Form->create('PpeRequest',array('type' => 'file')); ?>
<fieldset>
<legend><?php echo __(' PPE Request'); ?></legend>
<?php
echo $this->Form->input('name',array('value'=>$loggedInUsersName));
echo $this->Form->input('shoes');
echo $this->Form->input('reflective_jacket');
echo $this->Form->input('metaguards');
echo $this->Form->input('glasses');
echo $this->Form->input('earplugs');
echo $this->Form->input('hardhats');
echo $this->Form->input('gloves');
echo $this->Form->input('kit_bag');
echo $this->Form->input('dust_masks');
echo $this->Form->input('ppe_size');
echo $this->Form->input('activities',array('label'=>'Type of activities that will be undertaken'));
echo $this->Form->input('additional',array('label'=>'Additional PPE Requirements'));
echo $this->Form->input('site',array('label'=>'Type of Site'));
echo $this->Form->input('project_number');
echo $this->Form->input('date_required');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>