我試圖從Codegniter的文檔複製,但我無法使表單驗證回調工作。Codeigniter - 我的表單驗證回調不起作用
我添加了助手窗體,URL和庫form_validation。它不工作,總是返回 「假」
控制器
public function addtest()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'callback_username_check');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ($this->form_validation->run() == TRUE)
{
die('true');
}
else
{
die('false');
}
}
$this->template
->build('myform',array());
}
public function username_check($str)
{
if ($str == 'test')
{
return TRUE;
}
else
{
return FALSE;
}
}
查看
<form method="post" action="" class="form-horizontal form-label-left">
<div class="col-xs-12 col-md-9">
<div class="x_panel">
<div class="form-group col-xs-12">
<div class="col-xs-3">
<label class="control-label">Folder name</label>
</div>
<div class="col-xs-9">
<input type="text" name="username" value="" class="form-control " id="" placeholder="">
</div>
</div>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
嘗試添加'$ this'在'$這個 - > form_validation->運行($這個);' – Gaurav
我已經添加了$ this,但是它再次返回false –
您可以嘗試通過刪除請求方法檢查...? –