php - 提交 CI 表单时没有任何反应
问题描述
我有一个表格,旨在收集医生信息并将其存储在 MySQL 表中以作为医生目录。我在网站上有其他表格可以做其他事情。我对 Codeignitor 和 OOP 很陌生,但我似乎在这里很困惑,因为每次我提交表单时,它只是重新加载表单,而我填写的数据已经消失了。验证表单中没有错误消息。我做了测试,似乎在我的控制器中,if($this->form_validation->run())
条件没有触发,因为print_r($this->input->post());
该部分中的运行没有触发。
下面是我的代码/
控制器表单验证:
public function add_doctor_val()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="alert alert-primary" role="alert">', '</div>');
$this->form_validation->set_rules('sname', 'Surname of Doctor', 'required|alpha');
$this->form_validation->set_rules('dr_field', 'Type of Doctor', 'required');
$this->form_validation->set_rules('country', 'Country', 'required');
$this->form_validation->set_rules('town', 'City / Town / Village', 'required|alpha');
$this->form_validation->set_rules('postal_code', 'Postal / Zip Code', 'required');
$this->form_validation->set_rules('tel ', 'Telephone Number', 'required');
$this->form_validation->set_rules('web', 'website', 'valid_url');
if ($this->form_validation->run()) {
$user_id = $this->ion_auth->get_user_id();
$dr_info = array(
'user' => $user_id,
'sname' => $this->input->post('sname'),
'dr_field' => $this->input->post('dr_field'),
'country' => $this->input->post('country'),
'town' => $this->input->post('town'),
'postal_code' => $this->input->post('postal_code'),
'tel' => $this->input->post('tel'),
'web' => $this->input->post('web'),
'review' => $this->input->post('review')
);
$this->db->insert('dr_dir', $dr_info);
$this->success_pin();
} else {
$this->add_doctor();
}
}
表格:
<div class="col-lg-6 col-lg-offset-0 ">
<?php
if (!$this->ion_auth->logged_in()) {
redirect('auth/login');
} elseif ($this->ion_auth->logged_in()) {
?>
<h1>Add Doctor to Directory</h1>
<div id="map"></div>
<form method="post" action="<?= base_url('index.php/forms/add_doctor_val'); ?>">
<br />
<p>Having a list of knowledgebal doctors is a vital tool for any AlphaGal sufferer. If you have a doctor who has taken the time to learn about AlphaGal and it's treatment, please fill in the form below</p>
<div class="form-group row" style="margin-top: 20px">
<div class="col-xs-6">
<?php
echo form_label('Surname of Doctor', 'sname');
echo form_error('sname');
echo form_input('sname', '', 'class="form-control"');
?>
</div>
<div class="col-xs-6">
<?php
echo form_label('Type of Doctor', 'dr_field');
echo form_error('dr_field');
echo "<br />";
?>
<select class="form-control" name="dr_field">
<?php
foreach ($doctors as $row) {
echo '<option value="' . $row->id . '">' . $row->field . '</option>' . "\n";
}
?>
</select>
</div>
</div>
<div class="form-group row" style="margin-top: 20px">
<div class="col-xs-6">
<?php
echo form_label('Country', 'country');
echo form_error('country');
echo "<br />";
?>
<select class="form-control" name="country">
<?php
foreach ($countries as $row) {
echo '<option value="' . $row->country_iso_code . '">' . $row->country_name . '</option>' . "\n";
}
?>
</select>
</div>
<div class="col-xs-6">
<?php
echo form_label('City / Town / Village', 'town');
echo form_error('town');
echo form_input('town', '', 'class="form-control"');
?>
</div>
</div>
<div class="form-group row" style="margin-top: 20px">
<div class="col-xs-6">
<?php
echo form_label('Postal / Zip Code', 'postal_code');
echo form_error('postal_code');
echo form_input('postal_code', '', 'class="form-control"');
?>
</div>
<div class="col-xs-6">
<?php
echo form_label('Telephone Number', 'tel');
echo form_error('tel');
echo form_input('tel', '', 'class="form-control"');
?>
</div>
</div>
<div class="form-group row" style="margin-top: 20px">
<div class="col-xs-6">
<?php
echo form_label('Email', 'email');
echo form_error('email');
echo form_input('email', '', 'class="form-control"');
?>
</div>
<div class="col-xs-6">
<?php
echo form_label('Website', 'web');
echo form_error('web');
echo form_input('web', '', 'class="form-control"');
?>
</div>
</div>
<div class="form-group row" style="margin-top: 20px">
<div class="col-xs-12">
<?php
echo form_label('Leave a review', 'review');
echo form_error('review');
echo form_textarea('review', '', 'class="form-control"')
?>
</div>
</div>
<?php echo form_submit('submit', 'Submit', 'class="btn btn-primary btn-sm-15 btn-block"'); ?>
</div>
</form>
<?php } ?>
</div>
解决方案
我发现了问题,即使我现在知道原因:
这里的这一行是抛出整个脚本没有错误:
$this->form_validation->set_error_delimiters('<div class="alert alert-primary" role="alert">', '</div>');
我唯一能想到的是它被引用了两次
推荐阅读
- c - 在c中打印文件的最后10行
- dialogflow-es - 缓慢的 Google 操作控制台
- angular - 同时寻找 ngFor 和带参数的函数示例,即 Stackblitz
- c# - 无法调试 xUnit Theory 案例
- angular - 如果加载选项需要时间,则绑定选择的正确方法
- html - 如何使用 CSS 在两个图像之间创建剪辑路径
- html - 如何在 Angular 11 中使用 Jquery ligtslider
- reactjs - 通过 id React + Flask 获取数据
- javascript - setInterval vs setTimeout vs requestAnimationFrame
- sql - JPQL 中的嵌套查询