codeigniter form_validation 不起作用并且 $this->form_validation->run() 不返回任何内容
Posted
技术标签:
【中文标题】codeigniter form_validation 不起作用并且 $this->form_validation->run() 不返回任何内容【英文标题】:codeigniter form_validation not working and $this->form_validation->run() don't return anything 【发布时间】:2021-01-19 07:09:10 【问题描述】:这是我的查看页面代码
我在 codeigniter 中检查了 codeigniter 表单验证,它复制并粘贴了我的控制器,但同样的错误
<form action="<?php echo base_url(); ?>admin/user_setup/store" method="post" class="ml-4 mr-4 mt-2" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="firstname" id="firstname" placeholder="নাম" class="form-control form__field" required>
<label for="firstname" class="form__label">নাম </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="username" id="username" placeholder="ইউজার নাম" class="form-control form__field" required>
<label for="username" class="form__label">ইউজার নাম </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="email" id="email" placeholder="ই-মেইল" class="form-control form__field" required>
<label for="email" class="form__label">ই-মেইল </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<select name="activated" id="activated" class="form-control form__field" >
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
<label for="activated" class="form__label">অ্যাক্টিভেটেড</label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="password" name="password" id="password" placeholder="পাসওয়ার্ড" class="form-control form__field" required>
<label for="password" class="form__label">পাসওয়ার্ড</label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="password" name="confirm_password" id="confirm_password" placeholder="কন্ফার্ম পাসওয়ার্ড" class="form-control form__field" required>
<label for="confirm_password" class="form__label">কন্ফার্ম পাসওয়ার্ড</label>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group form__group">
<label for="logo" class="form__label">ছবি </label>
<input type="file" name="logo" id="logo" placeholder="ছবি" class="form-control form__field" rows="2" cols="2" style="height: 38px;"></input>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group form__group">
<select name="type" id="type" class="form-control form__field" >
<option value="2">এডিটর</option>
<option value="3">লাইসেন্স অফিসার</option>
</select>
<label for="type" class="form__label">ইউজার টাইপ</label>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group">
<input type="submit" value="তৈরি করুন" class="form-control btn btn-sm btn-primary mt-fl">
</div>
</div>
</div>
</form>
这是我的控制器代码
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|minlength[6]|max_length[50]|alpha_dash');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]');
$data['errors'] = array();
echo $this->form_validation->set_value('username');
echo $this->input->post('username');
if ($this->form_validation->run())
$data['username'] = $this->form_validation->set_value('username');
$data['firstname'] = $this->form_validation->set_value('firstname');
$data['email'] = $this->form_validation->set_value('email');
$data['password'] = $this->form_validation->set_value('password');
$data['created'] = date('Y-m-d H:i:s');
$data['activated'] = $this->input->post('activated');
$data['type'] = $this->input->post('type');
$insert_id = $this->web_model->insert('users', $data);
var_dump("asduasiduiasdijasidij");
else
$errors = $this->tank_auth->get_error_message();
foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
// $this->render_page('admin/setup/user_setup/create', $data);
echo $this->form_validation->run();
var_dump($data['errors']);
表单验证不返回任何内容,$this->form_validation->set_value('any');
始终为空
我在控制器 __construct 中加载 form_validation 并检查内部加载函数,但错误是绝对的
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
【问题讨论】:
您应该使用$this->input->post('fieldname')
将字段值分配给变量。 set_value
方法用于填充表单字段以防验证失败。 run()
方法不返回任何内容(可见)这一事实非常准确,因为它只会根据验证通过或失败返回布尔值(真/假)
【参考方案1】:
检查你的 PHPMyAdmin,我上个月也遇到了同样的问题,在 PHP 5.6 中找到 xampp,在此处链接 https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/5.6.40/,删除或重命名你的旧 Windows(c:)/xammp/ 并替换为 PHP 5.6
【讨论】:
这对表单验证有什么帮助?以上是关于codeigniter form_validation 不起作用并且 $this->form_validation->run() 不返回任何内容的主要内容,如果未能解决你的问题,请参考以下文章
调用未定义函数 codeigniter\locale_set_default() 时出现 codeigniter 错误
codeigniter 中是不是有子查询库?或者我如何在codeigniter 3中进行子查询?
php优秀框架codeigniter学习系列——CodeIgniter.php概览
Codeigniter- Ajax Codeigniter Ajax - 通过ajax返回不止一行
CodeIgniter 4 项目中未定义的常量“CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT”