亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

cakephp 驗證不適用于 save()

cakephp 驗證不適用于 save()

PHP
白豬掌柜的 2023-03-26 16:03:23
我只是在 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 &nbsp;<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&nbsp;<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&nbsp;<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'        )    ),
查看完整描述

1 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

如果您分配自己的名稱,CakePHP 無法將輸入字段與模型列匹配。例如:


<input type="text" class="form-control" id="inputName" name="name" placeholder="Name" required value="">

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^^^^

... 應該


name="data[User][name]"?

如果您將 CakePHP 用于模型和控制器,那么將它也用于視圖會更容易:


<?php

echo $this->Form->create('User');

echo $this->Form->input('name');


查看完整回答
反對 回復 2023-03-26
  • 1 回答
  • 0 關注
  • 107 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號