[英]Nothing happens when CI form submitted
I have a form that is meant to collect Doctors information and store it in a MySQL table for a directory of doctors. 我有一个表单,用于收集Doctors信息并将其存储在MySQL表中作为Doctors的目录。 I have other forms on the site that do other things. 我在网站上还有其他表格可以做其他事情。 I am very new to Codeignitor and to OOP, but I seem stumped here as everytime I submit the form, it just reloads the form, and the data I filled in is gone. 我对Codeignitor和OOP还是陌生的,但是每次提交表单时,我似乎都感到很困惑,因为它只是重新加载了表单,而我填写的数据也消失了。 There are no error message in the form from validation. 验证中的表单中没有错误消息。 I did test, and it seems like in my controller, the if ($this->form_validation->run())
condition is not triggering as a print_r($this->input->post());
我做了测试,似乎在我的控制器中,if ($this->form_validation->run())
条件没有作为print_r($this->input->post());
触发print_r($this->input->post());
run in that section does not trigger. 在该部分运行不会触发。
Below is my code / 下面是我的代码/
CONTROLLER Form Validation: 控制器表格验证:
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();
}
}
THE FORM: 表格:
<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>
I found the problem, even though I do now know why: 我发现了问题,尽管我现在知道为什么:
This line here is throwing the whole script without error: 这行代码将整个脚本正确地抛出:
$this->form_validation->set_error_delimiters('<div class="alert alert-primary" role="alert">', '</div>');
The only thing that I can think of is that it was referenced twice 我唯一能想到的是它被两次引用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.