当我使用Cakephp的Form Helper时,它可以在Model中验证,其中包含许多规则:(例如)
$this->validate = array(
"name" => array(
"rule" => "notBlank",
"message" => "Name not empty !",
),
"email" => array(
"rule" => "notBlank",
"message" => "Email not empty !",
),
);
Bootstrap Form:
<form>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Enter name">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
。但是当我使用在Bootstrap中创建的Form时,验证不会发生。
如何修复????
答案 0 :(得分:2)
如果您使用表单助手,则输入字段名称应为name="data[Modelname][fieldname]"
基于它,您的代码应该是(如果您的模型是Users
)
<form>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" name="data[User][name]" class="form-control" id="name" placeholder="Enter name">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" name="data[User][email]" class="form-control" id="email" placeholder="Enter email">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
详情为Here