gpt4 book ai didi

php - CodeIgniter form_validation 没有显示错误

转载 作者:行者123 更新时间:2023-12-05 07:49:19 25 4
gpt4 key购买 nike

我是 CodeIgniter 的新手,我对 form_validation 有疑问:

  • 我创建了一个 Controller 来进行身份验证,这是我的 Controller

============================================= ===========================

public function auth()
{
$this->load->helper(array('from','url'));

$this->load->library('form_validation');

$rules = array(
array(
'field' => 'username',
'label' => 'username',
'rules' => 'required'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required'
)
);
$this->form_validation->set_rules($rules);

if ($this->form_validation->run() == false) {
$this->load->view('login');
} else {
echo ';) like a boss';
}
}
}

============================================= =================

  • 我还创建了登录 View 。这是查看代码

============================================= =================

<section class="container">
<div class="login">
<h1>Login to Web App</h1>
<?php
$this->load->helper('form');
echo validation_errors();
echo form_open('login/auth');
$username = form_input(array('name' => 'username', 'placeholder' => 'Username or Email'));
$password = form_password(array('name' => 'password', 'placeholder' => 'Password'));
$checkbox = form_checkbox('remember', '1');
$submit = form_submit('submit', 'Login');
?>
<p><?= $username ?></p>
<p><?= $password ?></p>
<p class="remember_me">
<label>
<?= $checkbox ?>
Remember me on this computer
</label>
</p>
<p class="submit"><?= $submit ?></p>
<?php echo form_close(); ?>
</div>
</section>

最佳答案

你的代码中多了一个尖括号

public function auth()
{
$this->load->helper(array('from','url'));

$this->load->library('form_validation');

$rules = array(
array(
'field' => 'username',
'label' => 'username',
'rules' => 'required'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required'
)
);
$this->form_validation->set_rules($rules);

if ($this->form_validation->run() == false) {
$this->load->view('login');
} else {
echo ';) like a boss';
}`enter code here`
}

关于php - CodeIgniter form_validation 没有显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37422884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com