我只是在 cakephp(2.x) 中应用验证规则。当我保存数据时,它会在不验证表单的情况下保存到数据库中。我无法找到我缺少的地方。我是 cakephp 的初学者。请建议我如何验证我的表格。我的表单结构如下所示。
<form class="form-horizontal" method="POST" action="saveUser">
<fieldset>
<legend>Register</legend>
<span class = "error">* Required field</span>
<div class="form-group">
<label for="inputName" class="col-lg-2 control-label">Name <span class="error">*</span></label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputName" name="name" placeholder="Name" required value="">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email <span class="error">*</span></label>
<div class="col-lg-10">
<input type="email" class="form-control" id="inputEmail" name="email" placeholder="Email" required value="">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Password <span class="error">*</span></label>
<div class="col-lg-10">
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password" required value="">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
和模型这样验证数组
public $validate = array(
'name' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Only Allows Letter and Numbers'
),
'between' => array(
'rule' => array('lengthBetween', 5, 15),
'message' => 'length upto 5 to 15 character'
)
),
临摹微笑